Skip to main content

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

Protocol reliability (0.2.0)

Inference opening retries now honor max_retries for streamed and aggregated calls. Stream failures expose partial results through StreamError; EOF without a terminal event is an error. Chat tool calls use id/type/function format and include argument deltas and accurate finish reasons. Optional preserve_context retains opaque Codex context for same-model replay. See streaming, Chat migration, and native replay. Validation uses offline MockTransport fixtures, not live OAuth/Codex calls.

Metadata

Release files for gpt-codex-client 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt-codex-client 0.2.0
File Size Uploaded
gpt_codex_client-0.2.0.tar.gz 129.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gpt-codex-client 0.2.0
File Interpreter ABI Platform
gpt_codex_client-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 163.7 kB

Release files / gpt_codex_client-0.2.0.tar.gz

Download URL gpt_codex_client-0.2.0.tar.gz
Size 129.7 kB
Tags Source
SHA-256 checksum
How to use checksums
53a6972e821e8462470ece529654049d1b777e54be15c05a9210bf143c9bab0f
BLAKE2b-256 checksum
How to use checksums
c0756439408789575d61b08ec41a3d29a0ee427cbbea4c03e37d6359686f71ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release files / gpt_codex_client-0.2.0-py3-none-any.whl

Download URL gpt_codex_client-0.2.0-py3-none-any.whl
Size 34.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
12e31b697102261c054275e7bf514e1b6f4fa341371ca72a4dbfbb2746c22bea
BLAKE2b-256 checksum
How to use checksums
d39160133b38da81b91a716b742be891d23fa5adb1ba515b3dadf51874c730c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 12, 2026.

Transparency log

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.2.0 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page