oauth-codex
OAuth PKCE-based Python SDK for the Codex backend.
Highlights
- Resource-style clients:
ClientandAsyncClient - OAuth PKCE only, with interactive login and automatic token refresh
- OpenAI-style
chat.completions.create(...) - Lower-level
responses.create(...),responses.parse(...), andresponses.stream(...) - Callable tool loop helpers via
client.beta.chat.completions.run_tools(...)
Installation
pip install oauth-codex
Requires Python 3.11 or newer.
Quick Start
Synchronous Client
from oauth_codex import Client
client = Client()
client.authenticate()
completion = client.chat.completions.create(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "Hello from oauth-codex"}],
)
print(completion.choices[0].message.content)
Asynchronous Client
import asyncio
from oauth_codex import AsyncClient
async def main():
client = AsyncClient()
await client.authenticate()
completion = await client.chat.completions.create(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "Hello async"}],
)
print(completion.choices[0].message.content)
asyncio.run(main())
Authentication
This SDK uses OAuth PKCE only. API keys are not supported.
client = Client()
client.authenticate()
On first authentication, the SDK prints an authorization URL, waits for the browser sign-in flow, and asks you to paste the localhost callback URL back into the terminal. Tokens are stored locally and refreshed automatically on later requests.
By default, oauth-codex stores tokens in the OS keyring when available. If keyring storage fails, it falls back to a per-user file in the platform-native config directory, such as %LOCALAPPDATA%\\oauth-codex\\auth.json on Windows, ~/Library/Application Support/oauth-codex/auth.json on macOS, or ~/.config/oauth-codex/auth.json on Linux. Legacy ~/.oauth_codex/auth.json files are migrated automatically when read.
For deterministic deployments on clean machines, you can control the storage backend explicitly:
CODEX_OAUTH_TOKEN_STORE=autouses keyring first, then file fallback.CODEX_OAUTH_TOKEN_STORE=keyringrequires OS keyring storage and fails if keyring is unavailable.CODEX_OAUTH_TOKEN_STORE=filealways uses the file backend.CODEX_OAUTH_TOKEN_PATH=/absolute/path/to/auth.jsonoverrides the file location when using file storage or auto fallback.
For headless servers, use CODEX_OAUTH_TOKEN_STORE=file and set CODEX_OAUTH_TOKEN_PATH to a deployment-managed per-user secret path if you do not want keyring-dependent behavior.
Main API Surface
Chat Completions
response = client.chat.completions.create(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "Write a sorting function"}],
)
print(response.choices[0].message.content)
Responses Resource
response = client.responses.create(
model="gpt-5.3-codex",
input=[{"role": "user", "content": "Analyze this code snippet."}],
)
print(response.output_text)
Streaming
for event in client.responses.stream(
model="gpt-5.3-codex",
input=[{"role": "user", "content": "Say hello in three words"}],
):
if event.type == "text_delta" and event.delta:
print(event.delta, end="", flush=True)
Structured Output
from pydantic import BaseModel
class Summary(BaseModel):
title: str
score: int
response = client.responses.parse(
model="gpt-5.3-codex",
input=[{"role": "user", "content": "Return JSON with title and score"}],
response_format=Summary,
)
print(response.parsed)
Tool Execution
def add(a: int, b: int) -> int:
return a + b
completion = client.beta.chat.completions.run_tools(
model="gpt-5.3-codex",
messages=[{"role": "user", "content": "What is 2 + 3?"}],
tools=[add],
)
print(completion.choices[0].message.content)
Available Namespaces
client.chat.completionsclient.responsesclient.filesclient.vector_storesclient.vector_stores.filesclient.vector_stores.file_batchesclient.modelsclient.beta.chat.completions
AsyncClient exposes the same namespaces with async methods.
Removed In 4.0
authenticate_on_initgenerate,agenerate,stream,astream- legacy
OAuthCodexClientandAsyncOAuthCodexClient - module-level proxy usage such as
oauth_codex.responses.create(...)
Error Handling
The package exports OpenAI-style exception classes such as AuthenticationError, RateLimitError, APIConnectionError, and APIStatusError.
Documentation
- English:
docs/en/index.md - Korean:
docs/ko/index.md
Development
pip install -e .[dev]
pytest -q
python -m build
Changelog
Release files for flowalto-oauth 4.0.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 | |
|---|---|---|---|
| flowalto_oauth-4.0.2.tar.gz | 39.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flowalto_oauth-4.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 90.5 kB
Release files / flowalto_oauth-4.0.2.tar.gz
| Download URL | flowalto_oauth-4.0.2.tar.gz |
|---|---|
| Size | 39.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
84180d9ad37889c0cc833c1693d3399e8d76c8cd18061f70cb5db1af8d77cfe3
|
|
BLAKE2b-256 checksum How to use checksums |
ca6d43bb179c9a2644da223412fc50e4f2d1117aa78b952735787e37621f89ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 1, 2026.
Transparency logRelease files / flowalto_oauth-4.0.2-py3-none-any.whl
| Download URL | flowalto_oauth-4.0.2-py3-none-any.whl |
|---|---|
| Size | 50.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
51adb541417ff00bed26006dd13409e82d66cf3019d85cc8d1bf986d26781195
|
|
BLAKE2b-256 checksum How to use checksums |
219fb16e34ea87bfc200b498e4f93d8a4a328e8de29ffee26e078c9e8a057a3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 1, 2026.
Transparency log