codex-client
A thin Python library that lets your programs call OpenAI models using your existing Codex/openclaw subscription — no API key, no proxy process, no Docker.
Zero dependencies beyond the Python standard library.
Prerequisites
You must have either openclaw or the Codex CLI installed and logged in on the machine. Either one writes the credentials this library reads.
If you only have the Codex CLI:
npx @openai/codex login
That's the only authentication step you'll ever need. The library refreshes tokens automatically when they expire (~10 day access token TTL, refresh token lasts months).
Installation
pip install codex-sub
Usage
Fact extraction (primary use case)
from codex_sub import CodexClient
client = CodexClient()
pdf_text = """
Apple Inc. reported Q1 2026 earnings with EPS of $2.41, revenue of $124.3B,
and EBITDA of $38.7B. Operating margin came in at 31.2%.
"""
facts = client.extract(
text=pdf_text,
instruction=(
"Extract financial metrics as JSON. "
"Keys: eps, revenue_b, ebitda_b, operating_margin_pct. "
"Use null for missing values."
),
)
print(facts)
# {'eps': 2.41, 'revenue_b': 124.3, 'ebitda_b': 38.7, 'operating_margin_pct': 31.2}
extract() always returns a parsed dict. It handles JSON mode internally.
General chat
response = client.complete(
messages=[
{"role": "system", "content": "You are a concise analyst."},
{"role": "user", "content": "Summarise this text: ..."},
]
)
print(response) # plain string
JSON mode with complete()
response = client.complete(
messages=[
{"role": "system", "content": "Extract data as JSON."},
{"role": "user", "content": "Revenue was $5B, margin 20%."},
],
json_mode=True,
)
import json
data = json.loads(response)
Available models
| Model | Speed | Notes |
|---|---|---|
gpt-5.4-mini |
Fastest | Default — good for structured extraction |
gpt-5.4 |
Balanced | Better reasoning |
gpt-5.5 |
Slower | Highest quality |
gpt-5.5-pro |
Slowest | Maximum context (1M tokens) |
Set a default model at construction time, or override per call:
client = CodexClient(model="gpt-5.4")
# override for a single call
result = client.extract(text, instruction, model="gpt-5.5")
Token refresh
Credentials are read from ~/.codex/auth.json on every call. If the access token is expired, the library refreshes it silently using the stored refresh token and writes the new token back to the file — so openclaw and the Codex CLI also benefit from the refresh.
No action needed on your part. If the refresh token itself expires (after months of no use), re-run npx @openai/codex login.
Endpoint constraints
These are handled automatically by the library, documented here for reference:
stream=Trueandstore=Falseare required by the endpoint and always set- System messages are translated to the top-level
instructionsfield max_output_tokensis not supported by this endpoint- JSON mode requires the word "json" to appear in the user message — the library appends
\n\nRespond in JSON.if it's absent - Only Codex-tier models are accepted (
gpt-5.4-mini,gpt-5.4,gpt-5.5,gpt-5.5-pro)
Metadata
Release files for codex-sub 0.1.0
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_sub-0.1.0.tar.gz | 5.4 kB | With provenance | Details for codex_sub-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| codex_sub-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for codex_sub-0.1.0-py3-none-any.whl |
Total release size: 11.6 kB
Release files / codex_sub-0.1.0.tar.gz
| Download URL | codex_sub-0.1.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7886cbd04c55a2703630a6ead052090c7e11811c574886ddf7d9c36d3d83bc45
|
|
BLAKE2b-256 checksum How to use checksums |
59866fbab312cbbb209559cd8f4dd61f450776cb3cb35e63508b37bf27e6d0a2
|
| 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 May 10, 2026.
Transparency logRelease files / codex_sub-0.1.0-py3-none-any.whl
| Download URL | codex_sub-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db5d9f66be4bcf77498c2a88ccad38412bff5222d104e9cdc236b170eff95ab2
|
|
BLAKE2b-256 checksum How to use checksums |
b7cd8867c91b0022414ad6b7d65e267ade3e1101e467de43ba1c12ef91948fd2
|
| 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 May 10, 2026.
Transparency logSecurity for codex-sub 0.1.0
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_sub-0.1.0.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 May 10, 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.