Skip to main content

OpenAI SDK-style Python client for ChatGPT/Codex OAuth-backed Responses workflows.

Project description

gpt-codex-client

English | 简体中文

gpt-codex-client is an OpenAI SDK-style Python client for ChatGPT/Codex OAuth-backed workflows. It is intentionally not an API-key client for api.openai.com; it uses a local token cache compatible with ~/.codex/auth.json and requires an account that can access the relevant ChatGPT/Codex backend.

uv add gpt-codex-client
from gpt_codex_client import CodexClient

with CodexClient(no_browser=True) as client:
    response = client.responses.create(
        model="gpt-5.5",
        input="Write a short Python function that reverses a string.",
    )
    print(response.output_text)

List Models

client.models.list() reads the public OpenAI Codex model registry from the openai/codex GitHub repository instead of the ChatGPT/Codex backend /models endpoint.

from gpt_codex_client import CodexClient

with CodexClient() as client:
    models = client.models.list()
    for model in models:
        print(model.id)

The registry source is:

https://raw.githubusercontent.com/openai/codex/main/codex-rs/models-manager/models.json

Set GPT_CODEX_CLIENT_MODELS_MANIFEST_URL or pass models_manifest_url= to use another compatible registry.

Authentication

The client lazily authenticates on the first request. By default it reads and writes ~/.codex/auth.json with 0600 permissions.

from gpt_codex_client import login

login(no_browser=True)

The default OAuth client id follows the ChatGPT/Codex sign-in flow used by the official Codex clients. If OpenAI issues a different client id for your app, set GPT_CODEX_CLIENT_OAUTH_CLIENT_ID or pass auth_client_id= to CodexClient.

For automation, pass a login_handler that receives the authorization URL and returns the final redirect URL:

from gpt_codex_client import login

token = login(login_handler=lambda url: input(f"Open {url}\nRedirect URL: "))

Responses

with CodexClient() as client:
    response = client.responses.create(
        model="gpt-5.5",
        input="Summarize this repository.",
        reasoning={"effort": "medium"},
        text={"verbosity": "low"},
    )

Streaming returns a context manager and iterator:

with CodexClient() as client:
    with client.responses.create(model="gpt-5.5", input="Say hi", stream=True) as stream:
        for event in stream:
            if event.type == "response.output_text.delta":
                print(event.data.get("delta"), end="")

Structured Output

Install the optional extra when using Pydantic models:

uv add "gpt-codex-client[pydantic]"
from pydantic import BaseModel
from gpt_codex_client import CodexClient

class Result(BaseModel):
    title: str

parsed = CodexClient().responses.parse(
    model="gpt-5.5",
    input="Return JSON with a title.",
    text_format=Result,
)
print(parsed.parsed.title)

Chat Compatibility

The chat compatibility layer converts Chat Completions-style messages and function tools into Responses requests:

completion = CodexClient().chat.completions.create(
    model="gpt-5.5",
    messages=[{"role": "user", "content": "Hello"}],
)
print(completion.choices[0].message.content)

Development

uv sync --all-extras --dev
uv run pytest -q

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpt_codex_client-0.1.0.tar.gz (101.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpt_codex_client-0.1.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file gpt_codex_client-0.1.0.tar.gz.

File metadata

  • Download URL: gpt_codex_client-0.1.0.tar.gz
  • Upload date:
  • Size: 101.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpt_codex_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa9ce81cfb2d2c8a8801e9987dfb40478a705bce91fbee4f1ccc154028c3d00e
MD5 ad82e0438b651bda1f16789b46897221
BLAKE2b-256 0b33958511fd4efaa61c67f87fc4c8c211e3e0837b2520b90c00f387da6f53f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpt_codex_client-0.1.0.tar.gz:

Publisher: release.yml on HC-Zhou/gpt-codex-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gpt_codex_client-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gpt_codex_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b3d1bb0f267be928f1a8283dfcb6de4088e16cb856921673df737fbc2a616e5
MD5 7f638285722829b82866c51d8f304106
BLAKE2b-256 3a31636b138b5450db8e18222f8f6cee2dbcd6536d7ae01a7aee4a89db8570de

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpt_codex_client-0.1.0-py3-none-any.whl:

Publisher: release.yml on HC-Zhou/gpt-codex-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page