Use your OpenAI Codex subscription as an API — no API key required
Project description
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)
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 codex_sub-0.1.0.tar.gz.
File metadata
- Download URL: codex_sub-0.1.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7886cbd04c55a2703630a6ead052090c7e11811c574886ddf7d9c36d3d83bc45
|
|
| MD5 |
684bc1471c87d426bb61210c45262de1
|
|
| BLAKE2b-256 |
59866fbab312cbbb209559cd8f4dd61f450776cb3cb35e63508b37bf27e6d0a2
|
Provenance
The following attestation bundles were made for codex_sub-0.1.0.tar.gz:
Publisher:
publish.yml on Asing1001/codex-sub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_sub-0.1.0.tar.gz -
Subject digest:
7886cbd04c55a2703630a6ead052090c7e11811c574886ddf7d9c36d3d83bc45 - Sigstore transparency entry: 1497909705
- Sigstore integration time:
-
Permalink:
Asing1001/codex-sub@6597565e3f20c451e3d68df0b12bef156ba07b41 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Asing1001
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6597565e3f20c451e3d68df0b12bef156ba07b41 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_sub-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codex_sub-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.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 |
db5d9f66be4bcf77498c2a88ccad38412bff5222d104e9cdc236b170eff95ab2
|
|
| MD5 |
a6cc760870282ab88718c52df1742c23
|
|
| BLAKE2b-256 |
b7cd8867c91b0022414ad6b7d65e267ade3e1101e467de43ba1c12ef91948fd2
|
Provenance
The following attestation bundles were made for codex_sub-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Asing1001/codex-sub
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_sub-0.1.0-py3-none-any.whl -
Subject digest:
db5d9f66be4bcf77498c2a88ccad38412bff5222d104e9cdc236b170eff95ab2 - Sigstore transparency entry: 1497909936
- Sigstore integration time:
-
Permalink:
Asing1001/codex-sub@6597565e3f20c451e3d68df0b12bef156ba07b41 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Asing1001
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6597565e3f20c451e3d68df0b12bef156ba07b41 -
Trigger Event:
push
-
Statement type: