OpenAI SDK-style Python client for ChatGPT/Codex OAuth-backed Responses workflows.
Project description
gpt-codex-client
OpenAI SDK-style Python client for ChatGPT/Codex OAuth-backed workflows.
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.jsontoken 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cd83d869c650ee279f5ecb5865a1030c74479f9b3c011d6f5b49f819e8d0655
|
|
| MD5 |
7ae1b53e08b69cedf45d928e682def98
|
|
| BLAKE2b-256 |
a262f0304b45117e64d4283407e042de5aa916fc90af137d3daea6e9b6da39ee
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gpt_codex_client-0.1.1.tar.gz -
Subject digest:
3cd83d869c650ee279f5ecb5865a1030c74479f9b3c011d6f5b49f819e8d0655 - Sigstore transparency entry: 1856168872
- Sigstore integration time:
-
Permalink:
HC-Zhou/gpt-codex-client@cd00dab439478633bd3306deb1263ff87281b61e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/HC-Zhou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cd00dab439478633bd3306deb1263ff87281b61e -
Trigger Event:
push
-
Statement type:
File details
Details for the file gpt_codex_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: gpt_codex_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c93e108ffe1eb061bc6b1edc150d9bb3fcb2acaa3b98f03113a3f4b5cc4f6f20
|
|
| MD5 |
0fc43f4370578d83227dc2bb70850364
|
|
| BLAKE2b-256 |
2c77f8e12421e62e9c7f5218e00981552762d87498821e3422faf46637ffbf38
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gpt_codex_client-0.1.1-py3-none-any.whl -
Subject digest:
c93e108ffe1eb061bc6b1edc150d9bb3fcb2acaa3b98f03113a3f4b5cc4f6f20 - Sigstore transparency entry: 1856168885
- Sigstore integration time:
-
Permalink:
HC-Zhou/gpt-codex-client@cd00dab439478633bd3306deb1263ff87281b61e -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/HC-Zhou
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cd00dab439478633bd3306deb1263ff87281b61e -
Trigger Event:
push
-
Statement type: