Skip to main content

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

Project description

gpt-codex-client icon

gpt-codex-client

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

English · 简体中文 · PyPI · Docs

PyPI Python versions License CI

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.

Install

uv add gpt-codex-client

Quick Start

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)

Highlights

  • Responses-style sync and async clients with streaming support.
  • Chat Completions compatibility for existing message/tool-call workflows.
  • OAuth PKCE login, refresh tokens, and ~/.codex/auth.json token cache support.
  • Model discovery from the public OpenAI Codex model registry.
  • Optional Pydantic parsing for structured output.

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.1.tar.gz (103.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.1-py3-none-any.whl (28.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gpt_codex_client-0.1.1.tar.gz
  • Upload date:
  • Size: 103.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.1.tar.gz
Algorithm Hash digest
SHA256 3cd83d869c650ee279f5ecb5865a1030c74479f9b3c011d6f5b49f819e8d0655
MD5 7ae1b53e08b69cedf45d928e682def98
BLAKE2b-256 a262f0304b45117e64d4283407e042de5aa916fc90af137d3daea6e9b6da39ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpt_codex_client-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gpt_codex_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c93e108ffe1eb061bc6b1edc150d9bb3fcb2acaa3b98f03113a3f4b5cc4f6f20
MD5 0fc43f4370578d83227dc2bb70850364
BLAKE2b-256 2c77f8e12421e62e9c7f5218e00981552762d87498821e3422faf46637ffbf38

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpt_codex_client-0.1.1-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