Metadata-Version: 2.4
Name: openai-codex-auth
Version: 0.1.0
Summary: Use the Codex CLI's ChatGPT login (~/.codex/auth.json) as a bearer credential for the Codex backend
Keywords: codex,chatgpt,oauth,openai
Author: hrbatra
Author-email: hrbatra <hrbatra@utexas.edu>
License-Expression: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: requests>=2.32.0
Requires-Python: >=3.12
Project-URL: Homepage, https://github.com/hrbatra/openai-codex-auth
Project-URL: Issues, https://github.com/hrbatra/openai-codex-auth/issues
Project-URL: Repository, https://github.com/hrbatra/openai-codex-auth
Description-Content-Type: text/markdown

# 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

```bash
uv add openai-codex-auth
codex login   # once, choosing "Sign in with ChatGPT"
```

## Usage

```python
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

```bash
uv sync --dev
uv run pytest
uv run ruff check .
uv build --no-sources
```

## Release

See [RELEASING.md](RELEASING.md).
