openai-codex-auth
Use the Codex CLI's ChatGPT login as a bearer credential, so OpenAI model calls bill to a ChatGPT (Codex) subscription instead of an API key.
codex login stores tokens in ~/.codex/auth.json. This package reads them,
refreshes the access token when it has expired, and writes the result back in
the CLI's format so the two stay in sync. One runtime dependency: requests.
Install
uv add openai-codex-auth
codex login # once, choosing "Sign in with ChatGPT"
Usage
import openai_codex_auth
auth = openai_codex_auth.CodexAuth() # or CodexAuth("/path/to/auth.json")
token = auth.token() # refreshed if expired
headers = openai_codex_auth.codex_headers(token, account_id=auth.account_id(), originator="my_app")
base_url = openai_codex_auth.DEFAULT_CODEX_API_BASE
Send Responses API requests to base_url with Authorization: Bearer <token>
plus headers. The backend requires stream: true, rejects system role
input items (use instructions or developer), and rejects
max_output_tokens.
openai_codex_auth.getauthtoken() is the one-call form of the above.
Refreshes take an exclusive lock on the file, so parallel processes sharing
one login do not race each other. A missing file, or a CLI signed in with an
API key rather than ChatGPT, raises CodexAuthError naming codex login.
Development
uv sync --dev
uv run pytest
uv run ruff check .
uv build --no-sources
Release
See RELEASING.md.
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 openai_codex_auth-0.1.0.tar.gz.
File metadata
- Download URL: openai_codex_auth-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ac25a2203fe9d5f0baccb29170da4b4008b756f9c8b858cbb5c610f6edb2abb
|
|
| MD5 |
49d37cd6e04c3fedb00539c32ad86066
|
|
| BLAKE2b-256 |
1f0898ce522dd7156b5a15b3b63657cba8b24d5f6e1ff16b09f438b49c4aa3cf
|
File details
Details for the file openai_codex_auth-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai_codex_auth-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b344b0557d7b6b1dc57f47edc2d622611e7bee696c39f095a96b8289a66d1d86
|
|
| MD5 |
c6f29ea5e6cc371fa26e4c59dda360ce
|
|
| BLAKE2b-256 |
9459def548432867da955bf53fe93f681dc664c463ab69a8c4078e28d2f20995
|