codex-open-client
Python client for OpenAI Codex — use your ChatGPT Plus/Pro subscription for API access.
Installation
pip install codex-open-client
Quick Start
import codex_open_client
client = codex_open_client.CodexClient()
response = client.responses.create(
model="gpt-5.1-codex-mini",
instructions="Be brief.",
input="What is 2 + 2?",
)
print(response.output_text)
On first run, your browser opens for OAuth login. Tokens are cached at ~/.codex/auth.json (shared with the official Codex CLI) and refreshed automatically after that.
Authentication
Multiple ways to authenticate, depending on your environment:
# Default — opens browser, local server catches the callback
client = codex_open_client.CodexClient()
# Headless — prints URL, you paste the redirect URL back (servers, Docker, CI)
client = codex_open_client.CodexClient(headless=True)
# Custom handler — full control over the auth UX (GUI apps, bots, web apps)
def my_handler(url: str) -> str:
send_url_to_user(url)
return get_callback_url_from_user()
client = codex_open_client.CodexClient(login_handler=my_handler)
For async or multi-step flows, use the two-step API:
auth = codex_open_client.start_login()
# present auth.url to the user, collect callback URL however you want
tokens = codex_open_client.finish_login(auth, callback_url="http://localhost:1455/...")
Streaming
with client.responses.create(
model="gpt-5.1-codex-mini",
instructions="Be helpful.",
input="Write a haiku about Python.",
stream=True,
) as stream:
for event in stream:
if isinstance(event, codex_open_client.ResponseOutputTextDeltaEvent):
print(event.delta, end="", flush=True)
print()
Tool Calls
import json
tool = codex_open_client.FunctionTool(
name="get_weather",
description="Get weather for a city.",
parameters={
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": False,
},
)
response = client.responses.create(
model="gpt-5.1-codex-mini",
instructions="Use tools when helpful.",
input="What's the weather in Tokyo?",
tools=[tool],
)
for call in response.tool_calls:
print(f"{call.name}({call.arguments})")
Structured Output
Get typed responses using Pydantic models:
pip install codex-open-client[pydantic]
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
city: str
parsed = client.responses.parse(
model="gpt-5.1-codex-mini",
instructions="Extract the person info.",
input="John Smith is 30 years old and lives in New York.",
text_format=Person,
)
print(parsed.output_parsed.name) # "John Smith"
print(parsed.output_parsed.age) # 30
Also works with manual JSON schema via TextConfig and ResponseFormatJsonSchema — see the docs.
Features
- Automatic auth — OAuth PKCE with token caching and refresh
- Typed API — dataclass-based types for all objects, full mypy strict support
- Structured output —
parse()with Pydantic models or manual JSON schemas - Streaming — iterate SSE events with context manager support
- Tool calls — function calling with roundtrip helpers
- Retries — built-in exponential backoff for 429/5xx
- Models — list available models with cached metadata
- Headless mode — works on remote servers, Docker, CI
- Custom login — bring your own auth UX with
login_handler - CLI interop — shares token storage with the official Codex CLI
Requirements
- Python 3.10+
- ChatGPT Plus or Pro subscription
License
MIT
Metadata
Release files for codex-open-client 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| codex_open_client-0.2.2.tar.gz | 109.2 kB | With provenance | Details for codex_open_client-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codex_open_client-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for codex_open_client-0.2.2-py3-none-any.whl |
Total release size: 133.5 kB
Release files / codex_open_client-0.2.2.tar.gz
| Download URL | codex_open_client-0.2.2.tar.gz |
|---|---|
| Size | 109.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e2159cd96833fff198d804275adfe0f0a9e25efd5326271c4293e0192ecd7b6
|
|
BLAKE2b-256 checksum How to use checksums |
25f775a1b55d4d90c00bae37a34132fd16f6bbb86e5a4ce86fb1e61c1a9280bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 9, 2026.
Transparency logRelease files / codex_open_client-0.2.2-py3-none-any.whl
| Download URL | codex_open_client-0.2.2-py3-none-any.whl |
|---|---|
| Size | 24.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6aa9ee456fce5e50c4e2b777f973f57b4118636e6362327293f1a2225498c7a
|
|
BLAKE2b-256 checksum How to use checksums |
99ebb5b372eb5c25e751707eddccafb46f605c363f797f411d81165803731fab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Mar 9, 2026.
Transparency logSecurity for codex-open-client 0.2.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for codex_open_client-0.2.2.tar.gz
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 Mar 9, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.