codex-as-api 0.9.6__tar.gz → 0.10.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/PKG-INFO +114 -25
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/README.md +112 -24
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/RELEASES.md +25 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/THIRD_PARTY_NOTICES.md +26 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/pyproject.toml +2 -1
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/requirements.txt +1 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/rust/THIRD_PARTY_NOTICES.md +26 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/__init__.py +1 -1
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/auth.py +122 -72
- codex_as_api-0.10.0/src/codex_as_api/browser_login.py +265 -0
- codex_as_api-0.10.0/src/codex_as_api/device_login.py +286 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/server.py +192 -28
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_auth.py +98 -18
- codex_as_api-0.10.0/tests/test_browser_login.py +259 -0
- codex_as_api-0.10.0/tests/test_device_login.py +304 -0
- codex_as_api-0.10.0/tests/test_login_commit_races.py +138 -0
- codex_as_api-0.10.0/tests/test_login_generation.py +89 -0
- codex_as_api-0.10.0/tests/test_login_http_real_store.py +176 -0
- codex_as_api-0.10.0/tests/test_management_body.py +91 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_provider.py +8 -5
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_server.py +7 -3
- codex_as_api-0.10.0/tests/test_standalone_login_api.py +178 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/.gitignore +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/LICENSE +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/config/codex-upstream-contract.json +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/config/o200k_base.tiktoken +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/config/verified-hidden-models.json +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/scripts/check_no_static_model_catalog.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/scripts/check_package_versions.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/scripts/check_registry_release.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/scripts/check_release_artifacts.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/scripts/generate_rust_third_party_notices.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/scripts/package_rust_release.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/anthropic_adapter.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/codex_config.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/codex_version.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/messages.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/model_capabilities.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/o200k_tokenizer.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/protocol.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/provider.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/reasoning_signature.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/src/codex_as_api/strict_json.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/__init__.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/conftest.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/fixtures/o200k_base_encode_ordinary.json +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_anthropic_adapter.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_codex_config.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_codex_version.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_messages.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_model_capabilities.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_no_static_model_catalog.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_o200k_tokenizer.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_package_versions.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_protocol.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_registry_release.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_release_artifacts.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_rust_third_party_notices.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_strict_json.py +0 -0
- {codex_as_api-0.9.6 → codex_as_api-0.10.0}/tests/test_ultrafast.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: codex-as-api
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: Use ChatGPT/Codex OAuth as a local OpenAI-compatible API server.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Eunho-J/codex-as-api
|
|
6
6
|
Project-URL: Repository, https://github.com/Eunho-J/codex-as-api
|
|
@@ -19,6 +19,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
19
19
|
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
20
|
Requires-Python: >=3.10
|
|
21
21
|
Requires-Dist: fastapi>=0.100
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
22
23
|
Requires-Dist: pydantic>=2.0
|
|
23
24
|
Requires-Dist: regex
|
|
24
25
|
Requires-Dist: tomli>=2; python_version < '3.11'
|
|
@@ -52,35 +53,31 @@ Use ChatGPT / Codex OAuth as a local OpenAI-compatible API server.
|
|
|
52
53
|
- **Codex features** — live authenticated model discovery, session-aware `prompt_cache_key`, account-scoped Chat continuation, subagent headers, and remote compaction
|
|
53
54
|
- **Codex config aware** — reads `CODEX_HOME` / `~/.codex/config.toml` for model, reasoning-effort, and context-window settings
|
|
54
55
|
- **Token estimate & compaction helpers** — Anthropic-compatible `/v1/messages/count_tokens` and `/v1/messages/compact`
|
|
55
|
-
- **
|
|
56
|
+
- **Standalone ChatGPT login** — ordinary browser OAuth by default, optional device-code login for remote servers, a private application-owned credential store, and managed refresh; no installed Codex CLI or existing Codex login required
|
|
56
57
|
- **3 implementations** — Python, TypeScript (npm), and Rust — identical behavior
|
|
57
58
|
|
|
58
59
|
## What it does
|
|
59
60
|
|
|
60
|
-
Runs a lightweight HTTP server on `localhost` that translates standard OpenAI API calls into authenticated requests against the ChatGPT / Codex backend
|
|
61
|
+
Runs a lightweight HTTP server on `localhost` that translates standard OpenAI API calls into authenticated requests against the ChatGPT / Codex backend. Sign in explicitly through this server's browser OAuth API; it stores and refreshes its own OAuth credentials without reading or changing your Codex login.
|
|
61
62
|
|
|
62
63
|
Python, Rust, and TypeScript (npm) implementations are provided — identical functionality, same endpoints, same behavior.
|
|
63
64
|
|
|
64
65
|
## Prerequisites
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
A ChatGPT account eligible for the Codex backend and a runtime for your chosen
|
|
68
|
+
implementation are required. The official Codex CLI is **not** required.
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
codex
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
managed ChatGPT OAuth tokens automatically. `auth_mode` may be omitted, `null`,
|
|
75
|
-
or `"chatgpt"`.
|
|
70
|
+
After starting the server, use [Standalone login](#standalone-login) to open
|
|
71
|
+
OpenAI's ordinary sign-in page in your browser and authorize this server. Credentials are saved privately to
|
|
72
|
+
`~/.codex-as-api/auth.json` by default, and the server handles refresh itself.
|
|
73
|
+
It does not discover, import or fall back to `~/.codex/auth.json`, `CODEX_HOME`
|
|
74
|
+
credentials or a Codex keychain entry. Upgrading from older versions therefore
|
|
75
|
+
requires a fresh login for codex-as-api; your existing Codex login is left alone.
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
host refresh callback. `personal_access_token`-, `agent_identity`-, and
|
|
82
|
-
Bedrock-only auth files are not ChatGPT OAuth credentials; run `codex login` to
|
|
83
|
-
create the supported managed-token file.
|
|
77
|
+
Use one server process per credential store. To run independent instances,
|
|
78
|
+
assign each its own `CODEX_AS_API_HOME` or `CODEX_AS_API_AUTH_PATH`.
|
|
79
|
+
Model settings may still be read from `~/.codex/config.toml`; that separate
|
|
80
|
+
configuration behavior is unchanged and does not require installing Codex.
|
|
84
81
|
|
|
85
82
|
## Install & Run
|
|
86
83
|
|
|
@@ -163,6 +160,87 @@ app.listen(18080);
|
|
|
163
160
|
|
|
164
161
|
All versions bind to `127.0.0.1:18080` (localhost only) by default.
|
|
165
162
|
|
|
163
|
+
## Standalone login
|
|
164
|
+
|
|
165
|
+
Login is an API operation; the `codex-as-api` command starts the server, not the
|
|
166
|
+
Codex CLI. Before starting, set `CODEX_AS_API_ADMIN_KEY` to a private random
|
|
167
|
+
administrator key. Supply that same key as a bearer credential on `/auth/*`.
|
|
168
|
+
This key is independent of both the OpenAI OAuth credentials and any inference
|
|
169
|
+
client authentication; never use your access or refresh token as the admin key.
|
|
170
|
+
|
|
171
|
+
1. Start the server with the key configured, then initiate login from a trusted
|
|
172
|
+
local terminal or authenticated management client:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
curl -sS -X POST http://127.0.0.1:18080/auth/login \
|
|
176
|
+
-H "Authorization: Bearer $CODEX_AS_API_ADMIN_KEY" \
|
|
177
|
+
-H 'Content-Type: application/json' -d '{}'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
2. The `202` response contains `id`, `method: "browser"`, `status: "pending"`,
|
|
181
|
+
`auth_url` and `expires_at`. Your app opens `auth_url` in the system browser;
|
|
182
|
+
sign in normally on OpenAI's page. No one-time device code or Codex CLI is
|
|
183
|
+
needed. On approval, the browser returns to a separate loopback callback
|
|
184
|
+
listener on the **same machine as the server**, and credentials are saved
|
|
185
|
+
privately. The server tries registered callback port 1455, then 1457; if both
|
|
186
|
+
are occupied it reports `409 callback_port_unavailable` instead of interfering
|
|
187
|
+
with another app. The API itself never launches a browser on a remote server.
|
|
188
|
+
The authorization URL contains temporary sensitive state; do not log or share
|
|
189
|
+
it. Only start login on a server you control.
|
|
190
|
+
|
|
191
|
+
3. Poll the login ID returned by step 1 (the placeholder below is not a real ID):
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
curl -sS http://127.0.0.1:18080/auth/login/LOGIN_ID \
|
|
195
|
+
-H "Authorization: Bearer $CODEX_AS_API_ADMIN_KEY"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Status becomes `succeeded` only after valid credentials are durably saved.
|
|
199
|
+
Other terminal states are `failed`, `cancelled` and `expired`. Routine status
|
|
200
|
+
responses include the method but never repeat the authorization URL or user
|
|
201
|
+
code, or return OAuth tokens, authorization codes, verifiers, device IDs or
|
|
202
|
+
storage paths.
|
|
203
|
+
|
|
204
|
+
4. To stop an outstanding attempt, send `DELETE /auth/login/LOGIN_ID` with the same
|
|
205
|
+
administrator bearer. Repeating cancellation is safe. A login already saved
|
|
206
|
+
remains `succeeded`; cancellation is not logout or provider-side revocation.
|
|
207
|
+
|
|
208
|
+
`GET /auth/status` with the administrator bearer returns only
|
|
209
|
+
`{"status":"authenticated"}`, `unauthenticated` or `reauthentication_required`.
|
|
210
|
+
This checks the local application-owned credential state, not provider-side
|
|
211
|
+
revocation or remote account validity; refresh is handled privately when needed.
|
|
212
|
+
Validation, cancellation and failures before credential replacement preserve a
|
|
213
|
+
prior valid login. If replacement succeeds but the final directory sync fails,
|
|
214
|
+
`login_persistence_uncertain` reports that durability could not be confirmed; a
|
|
215
|
+
new local credential may already exist. Cancellation is not a rollback.
|
|
216
|
+
|
|
217
|
+
### Explicit device login for remote/headless use
|
|
218
|
+
|
|
219
|
+
When the browser and API server are on different machines, a loopback browser
|
|
220
|
+
callback would reach the wrong machine. Explicitly send `{"method":"device"}`
|
|
221
|
+
to `POST /auth/login` instead. It returns `method: "device"`, `verification_url`,
|
|
222
|
+
`user_code`, `interval` and the common session fields. Open
|
|
223
|
+
`https://auth.openai.com/codex/device` in your own browser and enter the code.
|
|
224
|
+
Only approve a code from a login you initiated on a trusted server; never post
|
|
225
|
+
it in public channels or logs. Device-code login may need enabling in your
|
|
226
|
+
OpenAI account. No method silently falls back to another.
|
|
227
|
+
|
|
228
|
+
All management responses use `Cache-Control: no-store`. An unset admin key returns
|
|
229
|
+
`503 management_disabled`; a missing/wrong bearer returns `401 invalid_admin_key`.
|
|
230
|
+
An empty request body, `{}` or `{"method":"browser"}` selects browser login;
|
|
231
|
+
`{"method":"device"}` selects device login. No other body fields are accepted.
|
|
232
|
+
The API does not accept credentials to import, token export switches,
|
|
233
|
+
authentication endpoints or credential paths from a request. One active attempt per store is allowed; another
|
|
234
|
+
start returns `409 login_in_progress`. Unknown/retired IDs return `404`.
|
|
235
|
+
|
|
236
|
+
Keep the default loopback binding unless you deliberately deploy authenticated
|
|
237
|
+
HTTPS administration behind a trusted reverse proxy. A browser `Origin` must
|
|
238
|
+
match the request's own scheme and Host; the API does not blindly trust forwarded
|
|
239
|
+
headers. Configure proxy origins consistently. Origin checking supplements the
|
|
240
|
+
admin bearer and is not a replacement for authentication or network controls.
|
|
241
|
+
Each credential store must be owned by one server process, not shared between
|
|
242
|
+
independent workers. Choose separate store paths for separate instances.
|
|
243
|
+
|
|
166
244
|
## Configuration
|
|
167
245
|
|
|
168
246
|
Environment variables (Python, Rust, and TypeScript):
|
|
@@ -172,10 +250,12 @@ Environment variables (Python, Rust, and TypeScript):
|
|
|
172
250
|
| `CODEX_AS_API_HOST` | `127.0.0.1` | Bind address |
|
|
173
251
|
| `CODEX_AS_API_PORT` | `18080` | Listen port |
|
|
174
252
|
| `CODEX_AS_API_MODEL` | `~/.codex/config.toml` `model`, else live default | Model identifier passed to Codex backend |
|
|
175
|
-
| `CODEX_AS_API_AUTH_PATH` | `~/.codex/auth.json` |
|
|
253
|
+
| `CODEX_AS_API_AUTH_PATH` | `CODEX_AS_API_HOME/auth.json`, else `~/.codex-as-api/auth.json` | Explicit application-owned OAuth store path; not an import command |
|
|
254
|
+
| `CODEX_AS_API_HOME` | `~/.codex-as-api` | Application-owned credential directory |
|
|
255
|
+
| `CODEX_AS_API_ADMIN_KEY` | unset (management disabled) | Independent bearer key for `/auth/*`; never use an OAuth token as this key |
|
|
176
256
|
| `CODEX_AS_API_RESPONSES_LITE` | `auto` | Responses Lite mode: `auto`, `on`, or `off` |
|
|
177
257
|
| `CODEX_AS_API_CODEX_METADATA` | `off` | Add Codex-style per-turn `client_metadata` and related backend headers |
|
|
178
|
-
| `CODEX_HOME` | `~/.codex` | Codex
|
|
258
|
+
| `CODEX_HOME` | `~/.codex` | Optional Codex model/config discovery only; never used to find credentials |
|
|
179
259
|
|
|
180
260
|
The server also reads root-level Codex CLI settings from `~/.codex/config.toml`:
|
|
181
261
|
|
|
@@ -865,7 +945,7 @@ HTTP Server (FastAPI / Axum / Express)
|
|
|
865
945
|
|
|
|
866
946
|
+---> ChatGPTOAuthProvider
|
|
867
947
|
|
|
|
868
|
-
+---> ~/.codex/auth.json (
|
|
948
|
+
+---> ~/.codex-as-api/auth.json (own OAuth credentials, auto-refresh)
|
|
869
949
|
+---> https://chatgpt.com/backend-api/codex/models
|
|
870
950
|
+---> https://chatgpt.com/backend-api/codex/responses
|
|
871
951
|
```
|
|
@@ -912,9 +992,9 @@ registry setup is still required:
|
|
|
912
992
|
After bumping every version and passing the local gate, push the matching tag:
|
|
913
993
|
|
|
914
994
|
```bash
|
|
915
|
-
python scripts/check_package_versions.py --tag v0.
|
|
916
|
-
git tag v0.
|
|
917
|
-
git push origin v0.
|
|
995
|
+
python scripts/check_package_versions.py --tag v0.10.0
|
|
996
|
+
git tag v0.10.0
|
|
997
|
+
git push origin v0.10.0
|
|
918
998
|
```
|
|
919
999
|
|
|
920
1000
|
## Tests
|
|
@@ -945,6 +1025,15 @@ npm test
|
|
|
945
1025
|
|
|
946
1026
|
## Release Notes
|
|
947
1027
|
|
|
1028
|
+
### v0.10.0
|
|
1029
|
+
|
|
1030
|
+
- Sign in directly with ordinary browser OAuth; no Codex installation or existing
|
|
1031
|
+
Codex credentials are required. Device-code login is an explicit remote option.
|
|
1032
|
+
- Add independent admin-key-protected login start/status/cancel endpoints and a
|
|
1033
|
+
private application-owned credential store across Python, TypeScript and Rust.
|
|
1034
|
+
- Upgrading requires a new codex-as-api login; existing Codex credentials remain
|
|
1035
|
+
untouched. See [Standalone login](#standalone-login) and [full release notes](RELEASES.md).
|
|
1036
|
+
|
|
948
1037
|
### v0.8.0
|
|
949
1038
|
|
|
950
1039
|
- Add ChatGPT Live realtime voice to the TypeScript runtime: `POST
|
|
@@ -18,35 +18,31 @@ Use ChatGPT / Codex OAuth as a local OpenAI-compatible API server.
|
|
|
18
18
|
- **Codex features** — live authenticated model discovery, session-aware `prompt_cache_key`, account-scoped Chat continuation, subagent headers, and remote compaction
|
|
19
19
|
- **Codex config aware** — reads `CODEX_HOME` / `~/.codex/config.toml` for model, reasoning-effort, and context-window settings
|
|
20
20
|
- **Token estimate & compaction helpers** — Anthropic-compatible `/v1/messages/count_tokens` and `/v1/messages/compact`
|
|
21
|
-
- **
|
|
21
|
+
- **Standalone ChatGPT login** — ordinary browser OAuth by default, optional device-code login for remote servers, a private application-owned credential store, and managed refresh; no installed Codex CLI or existing Codex login required
|
|
22
22
|
- **3 implementations** — Python, TypeScript (npm), and Rust — identical behavior
|
|
23
23
|
|
|
24
24
|
## What it does
|
|
25
25
|
|
|
26
|
-
Runs a lightweight HTTP server on `localhost` that translates standard OpenAI API calls into authenticated requests against the ChatGPT / Codex backend
|
|
26
|
+
Runs a lightweight HTTP server on `localhost` that translates standard OpenAI API calls into authenticated requests against the ChatGPT / Codex backend. Sign in explicitly through this server's browser OAuth API; it stores and refreshes its own OAuth credentials without reading or changing your Codex login.
|
|
27
27
|
|
|
28
28
|
Python, Rust, and TypeScript (npm) implementations are provided — identical functionality, same endpoints, same behavior.
|
|
29
29
|
|
|
30
30
|
## Prerequisites
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
A ChatGPT account eligible for the Codex backend and a runtime for your chosen
|
|
33
|
+
implementation are required. The official Codex CLI is **not** required.
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
codex
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
managed ChatGPT OAuth tokens automatically. `auth_mode` may be omitted, `null`,
|
|
41
|
-
or `"chatgpt"`.
|
|
35
|
+
After starting the server, use [Standalone login](#standalone-login) to open
|
|
36
|
+
OpenAI's ordinary sign-in page in your browser and authorize this server. Credentials are saved privately to
|
|
37
|
+
`~/.codex-as-api/auth.json` by default, and the server handles refresh itself.
|
|
38
|
+
It does not discover, import or fall back to `~/.codex/auth.json`, `CODEX_HOME`
|
|
39
|
+
credentials or a Codex keychain entry. Upgrading from older versions therefore
|
|
40
|
+
requires a fresh login for codex-as-api; your existing Codex login is left alone.
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
host refresh callback. `personal_access_token`-, `agent_identity`-, and
|
|
48
|
-
Bedrock-only auth files are not ChatGPT OAuth credentials; run `codex login` to
|
|
49
|
-
create the supported managed-token file.
|
|
42
|
+
Use one server process per credential store. To run independent instances,
|
|
43
|
+
assign each its own `CODEX_AS_API_HOME` or `CODEX_AS_API_AUTH_PATH`.
|
|
44
|
+
Model settings may still be read from `~/.codex/config.toml`; that separate
|
|
45
|
+
configuration behavior is unchanged and does not require installing Codex.
|
|
50
46
|
|
|
51
47
|
## Install & Run
|
|
52
48
|
|
|
@@ -129,6 +125,87 @@ app.listen(18080);
|
|
|
129
125
|
|
|
130
126
|
All versions bind to `127.0.0.1:18080` (localhost only) by default.
|
|
131
127
|
|
|
128
|
+
## Standalone login
|
|
129
|
+
|
|
130
|
+
Login is an API operation; the `codex-as-api` command starts the server, not the
|
|
131
|
+
Codex CLI. Before starting, set `CODEX_AS_API_ADMIN_KEY` to a private random
|
|
132
|
+
administrator key. Supply that same key as a bearer credential on `/auth/*`.
|
|
133
|
+
This key is independent of both the OpenAI OAuth credentials and any inference
|
|
134
|
+
client authentication; never use your access or refresh token as the admin key.
|
|
135
|
+
|
|
136
|
+
1. Start the server with the key configured, then initiate login from a trusted
|
|
137
|
+
local terminal or authenticated management client:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
curl -sS -X POST http://127.0.0.1:18080/auth/login \
|
|
141
|
+
-H "Authorization: Bearer $CODEX_AS_API_ADMIN_KEY" \
|
|
142
|
+
-H 'Content-Type: application/json' -d '{}'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
2. The `202` response contains `id`, `method: "browser"`, `status: "pending"`,
|
|
146
|
+
`auth_url` and `expires_at`. Your app opens `auth_url` in the system browser;
|
|
147
|
+
sign in normally on OpenAI's page. No one-time device code or Codex CLI is
|
|
148
|
+
needed. On approval, the browser returns to a separate loopback callback
|
|
149
|
+
listener on the **same machine as the server**, and credentials are saved
|
|
150
|
+
privately. The server tries registered callback port 1455, then 1457; if both
|
|
151
|
+
are occupied it reports `409 callback_port_unavailable` instead of interfering
|
|
152
|
+
with another app. The API itself never launches a browser on a remote server.
|
|
153
|
+
The authorization URL contains temporary sensitive state; do not log or share
|
|
154
|
+
it. Only start login on a server you control.
|
|
155
|
+
|
|
156
|
+
3. Poll the login ID returned by step 1 (the placeholder below is not a real ID):
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
curl -sS http://127.0.0.1:18080/auth/login/LOGIN_ID \
|
|
160
|
+
-H "Authorization: Bearer $CODEX_AS_API_ADMIN_KEY"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Status becomes `succeeded` only after valid credentials are durably saved.
|
|
164
|
+
Other terminal states are `failed`, `cancelled` and `expired`. Routine status
|
|
165
|
+
responses include the method but never repeat the authorization URL or user
|
|
166
|
+
code, or return OAuth tokens, authorization codes, verifiers, device IDs or
|
|
167
|
+
storage paths.
|
|
168
|
+
|
|
169
|
+
4. To stop an outstanding attempt, send `DELETE /auth/login/LOGIN_ID` with the same
|
|
170
|
+
administrator bearer. Repeating cancellation is safe. A login already saved
|
|
171
|
+
remains `succeeded`; cancellation is not logout or provider-side revocation.
|
|
172
|
+
|
|
173
|
+
`GET /auth/status` with the administrator bearer returns only
|
|
174
|
+
`{"status":"authenticated"}`, `unauthenticated` or `reauthentication_required`.
|
|
175
|
+
This checks the local application-owned credential state, not provider-side
|
|
176
|
+
revocation or remote account validity; refresh is handled privately when needed.
|
|
177
|
+
Validation, cancellation and failures before credential replacement preserve a
|
|
178
|
+
prior valid login. If replacement succeeds but the final directory sync fails,
|
|
179
|
+
`login_persistence_uncertain` reports that durability could not be confirmed; a
|
|
180
|
+
new local credential may already exist. Cancellation is not a rollback.
|
|
181
|
+
|
|
182
|
+
### Explicit device login for remote/headless use
|
|
183
|
+
|
|
184
|
+
When the browser and API server are on different machines, a loopback browser
|
|
185
|
+
callback would reach the wrong machine. Explicitly send `{"method":"device"}`
|
|
186
|
+
to `POST /auth/login` instead. It returns `method: "device"`, `verification_url`,
|
|
187
|
+
`user_code`, `interval` and the common session fields. Open
|
|
188
|
+
`https://auth.openai.com/codex/device` in your own browser and enter the code.
|
|
189
|
+
Only approve a code from a login you initiated on a trusted server; never post
|
|
190
|
+
it in public channels or logs. Device-code login may need enabling in your
|
|
191
|
+
OpenAI account. No method silently falls back to another.
|
|
192
|
+
|
|
193
|
+
All management responses use `Cache-Control: no-store`. An unset admin key returns
|
|
194
|
+
`503 management_disabled`; a missing/wrong bearer returns `401 invalid_admin_key`.
|
|
195
|
+
An empty request body, `{}` or `{"method":"browser"}` selects browser login;
|
|
196
|
+
`{"method":"device"}` selects device login. No other body fields are accepted.
|
|
197
|
+
The API does not accept credentials to import, token export switches,
|
|
198
|
+
authentication endpoints or credential paths from a request. One active attempt per store is allowed; another
|
|
199
|
+
start returns `409 login_in_progress`. Unknown/retired IDs return `404`.
|
|
200
|
+
|
|
201
|
+
Keep the default loopback binding unless you deliberately deploy authenticated
|
|
202
|
+
HTTPS administration behind a trusted reverse proxy. A browser `Origin` must
|
|
203
|
+
match the request's own scheme and Host; the API does not blindly trust forwarded
|
|
204
|
+
headers. Configure proxy origins consistently. Origin checking supplements the
|
|
205
|
+
admin bearer and is not a replacement for authentication or network controls.
|
|
206
|
+
Each credential store must be owned by one server process, not shared between
|
|
207
|
+
independent workers. Choose separate store paths for separate instances.
|
|
208
|
+
|
|
132
209
|
## Configuration
|
|
133
210
|
|
|
134
211
|
Environment variables (Python, Rust, and TypeScript):
|
|
@@ -138,10 +215,12 @@ Environment variables (Python, Rust, and TypeScript):
|
|
|
138
215
|
| `CODEX_AS_API_HOST` | `127.0.0.1` | Bind address |
|
|
139
216
|
| `CODEX_AS_API_PORT` | `18080` | Listen port |
|
|
140
217
|
| `CODEX_AS_API_MODEL` | `~/.codex/config.toml` `model`, else live default | Model identifier passed to Codex backend |
|
|
141
|
-
| `CODEX_AS_API_AUTH_PATH` | `~/.codex/auth.json` |
|
|
218
|
+
| `CODEX_AS_API_AUTH_PATH` | `CODEX_AS_API_HOME/auth.json`, else `~/.codex-as-api/auth.json` | Explicit application-owned OAuth store path; not an import command |
|
|
219
|
+
| `CODEX_AS_API_HOME` | `~/.codex-as-api` | Application-owned credential directory |
|
|
220
|
+
| `CODEX_AS_API_ADMIN_KEY` | unset (management disabled) | Independent bearer key for `/auth/*`; never use an OAuth token as this key |
|
|
142
221
|
| `CODEX_AS_API_RESPONSES_LITE` | `auto` | Responses Lite mode: `auto`, `on`, or `off` |
|
|
143
222
|
| `CODEX_AS_API_CODEX_METADATA` | `off` | Add Codex-style per-turn `client_metadata` and related backend headers |
|
|
144
|
-
| `CODEX_HOME` | `~/.codex` | Codex
|
|
223
|
+
| `CODEX_HOME` | `~/.codex` | Optional Codex model/config discovery only; never used to find credentials |
|
|
145
224
|
|
|
146
225
|
The server also reads root-level Codex CLI settings from `~/.codex/config.toml`:
|
|
147
226
|
|
|
@@ -831,7 +910,7 @@ HTTP Server (FastAPI / Axum / Express)
|
|
|
831
910
|
|
|
|
832
911
|
+---> ChatGPTOAuthProvider
|
|
833
912
|
|
|
|
834
|
-
+---> ~/.codex/auth.json (
|
|
913
|
+
+---> ~/.codex-as-api/auth.json (own OAuth credentials, auto-refresh)
|
|
835
914
|
+---> https://chatgpt.com/backend-api/codex/models
|
|
836
915
|
+---> https://chatgpt.com/backend-api/codex/responses
|
|
837
916
|
```
|
|
@@ -878,9 +957,9 @@ registry setup is still required:
|
|
|
878
957
|
After bumping every version and passing the local gate, push the matching tag:
|
|
879
958
|
|
|
880
959
|
```bash
|
|
881
|
-
python scripts/check_package_versions.py --tag v0.
|
|
882
|
-
git tag v0.
|
|
883
|
-
git push origin v0.
|
|
960
|
+
python scripts/check_package_versions.py --tag v0.10.0
|
|
961
|
+
git tag v0.10.0
|
|
962
|
+
git push origin v0.10.0
|
|
884
963
|
```
|
|
885
964
|
|
|
886
965
|
## Tests
|
|
@@ -911,6 +990,15 @@ npm test
|
|
|
911
990
|
|
|
912
991
|
## Release Notes
|
|
913
992
|
|
|
993
|
+
### v0.10.0
|
|
994
|
+
|
|
995
|
+
- Sign in directly with ordinary browser OAuth; no Codex installation or existing
|
|
996
|
+
Codex credentials are required. Device-code login is an explicit remote option.
|
|
997
|
+
- Add independent admin-key-protected login start/status/cancel endpoints and a
|
|
998
|
+
private application-owned credential store across Python, TypeScript and Rust.
|
|
999
|
+
- Upgrading requires a new codex-as-api login; existing Codex credentials remain
|
|
1000
|
+
untouched. See [Standalone login](#standalone-login) and [full release notes](RELEASES.md).
|
|
1001
|
+
|
|
914
1002
|
### v0.8.0
|
|
915
1003
|
|
|
916
1004
|
- Add ChatGPT Live realtime voice to the TypeScript runtime: `POST
|
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# Release Notes
|
|
2
2
|
|
|
3
|
+
## v0.10.0
|
|
4
|
+
|
|
5
|
+
### Standalone browser login — no Codex installation required
|
|
6
|
+
|
|
7
|
+
- Python, TypeScript and Rust now own their ChatGPT OAuth login and refresh
|
|
8
|
+
lifecycle. `POST /auth/login` starts ordinary browser OAuth with PKCE and a
|
|
9
|
+
loopback callback by default. The trusted application opens the returned
|
|
10
|
+
`auth_url`; progress and cancellation are available through the management API.
|
|
11
|
+
- Use `CODEX_AS_API_ADMIN_KEY` as the independent management bearer credential.
|
|
12
|
+
Management is disabled without it; status responses never export OAuth tokens.
|
|
13
|
+
- Credentials are privately and atomically stored in
|
|
14
|
+
`CODEX_AS_API_AUTH_PATH`, `CODEX_AS_API_HOME/auth.json`, or
|
|
15
|
+
`~/.codex-as-api/auth.json`. Existing Codex credentials are neither discovered
|
|
16
|
+
nor imported. **Upgrading requires signing in once for codex-as-api.**
|
|
17
|
+
- Explicit `{"method":"device"}` remains available for remote/headless servers.
|
|
18
|
+
There is no silent fallback between login methods. Ordinary browser login
|
|
19
|
+
expects the browser and server to run on the same machine, using registered
|
|
20
|
+
callback port 1455 or 1457.
|
|
21
|
+
- Cancellation, expiry and failures before replacement preserve the previous
|
|
22
|
+
login. A post-replacement durability failure is reported separately, and an
|
|
23
|
+
already committed login is not rolled back by cancellation. Local status is
|
|
24
|
+
not a provider-side validity or revocation check.
|
|
25
|
+
- Preserve the pinned OpenAI Codex Apache-2.0 attribution in distributed artifacts.
|
|
26
|
+
Model configuration and existing inference/Realtime behavior are unchanged.
|
|
27
|
+
|
|
3
28
|
## v0.9.6
|
|
4
29
|
|
|
5
30
|
### Sideband join failure says why
|
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Third-Party Notices
|
|
2
2
|
|
|
3
|
+
## OpenAI Codex — standalone OAuth login protocol port
|
|
4
|
+
|
|
5
|
+
The standalone browser OAuth and device-code login implementations are adapted
|
|
6
|
+
from OpenAI Codex (`openai/codex`, Apache License 2.0), pinned to
|
|
7
|
+
`rust-v0.164.0`, commit `6aaac694803004a63c6f393d153c96d22521a6b9`, in particular
|
|
8
|
+
`codex-rs/login/src/server.rs`, `codex-rs/login/src/device_code_auth.rs`, and
|
|
9
|
+
`codex-rs/login/src/oauth/{authorization,pkce,client}.rs`.
|
|
10
|
+
The Apache License 2.0 is included in this distribution's `LICENSE` file.
|
|
11
|
+
|
|
12
|
+
Local modifications implement equivalent Python, TypeScript and Rust login
|
|
13
|
+
managers and authenticated REST start/status/cancel endpoints; use a dedicated
|
|
14
|
+
codex-as-api credential store with no discovery/import of existing Codex
|
|
15
|
+
credentials; add bounded deadlines, cancellation, atomic storage and private
|
|
16
|
+
refresh ownership. This is not an unmodified distribution of the Codex CLI.
|
|
17
|
+
|
|
18
|
+
The upstream NOTICE is retained below. The login port does not include the
|
|
19
|
+
Codex terminal UI or use Ratatui; its attribution is retained as part of the
|
|
20
|
+
upstream notice rather than a claim that the terminal UI is bundled here.
|
|
21
|
+
|
|
22
|
+
> OpenAI Codex
|
|
23
|
+
> Copyright 2025 OpenAI
|
|
24
|
+
>
|
|
25
|
+
> This project includes code derived from [Ratatui](https://github.com/ratatui/ratatui), licensed under the MIT license.
|
|
26
|
+
> Copyright (c) 2016-2022 Florian Dehau
|
|
27
|
+
> Copyright (c) 2023-2025 The Ratatui Developers
|
|
28
|
+
|
|
3
29
|
## OpenAI tiktoken
|
|
4
30
|
|
|
5
31
|
This project includes a port of the `o200k_base` ordinary-encoding logic and
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "codex-as-api"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.10.0"
|
|
8
8
|
description = "Use ChatGPT/Codex OAuth as a local OpenAI-compatible API server."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = { text = "Apache-2.0" }
|
|
@@ -26,6 +26,7 @@ classifiers = [
|
|
|
26
26
|
]
|
|
27
27
|
dependencies = [
|
|
28
28
|
"fastapi>=0.100",
|
|
29
|
+
"httpx>=0.27",
|
|
29
30
|
"pydantic>=2.0",
|
|
30
31
|
"regex",
|
|
31
32
|
"tomli>=2; python_version < '3.11'",
|
|
@@ -6,6 +6,32 @@ Generated by `python scripts/generate_rust_third_party_notices.py`.
|
|
|
6
6
|
|
|
7
7
|
# Third-Party Notices
|
|
8
8
|
|
|
9
|
+
## OpenAI Codex — standalone OAuth login protocol port
|
|
10
|
+
|
|
11
|
+
The standalone browser OAuth and device-code login implementations are adapted
|
|
12
|
+
from OpenAI Codex (`openai/codex`, Apache License 2.0), pinned to
|
|
13
|
+
`rust-v0.164.0`, commit `6aaac694803004a63c6f393d153c96d22521a6b9`, in particular
|
|
14
|
+
`codex-rs/login/src/server.rs`, `codex-rs/login/src/device_code_auth.rs`, and
|
|
15
|
+
`codex-rs/login/src/oauth/{authorization,pkce,client}.rs`.
|
|
16
|
+
The Apache License 2.0 is included in this distribution's `LICENSE` file.
|
|
17
|
+
|
|
18
|
+
Local modifications implement equivalent Python, TypeScript and Rust login
|
|
19
|
+
managers and authenticated REST start/status/cancel endpoints; use a dedicated
|
|
20
|
+
codex-as-api credential store with no discovery/import of existing Codex
|
|
21
|
+
credentials; add bounded deadlines, cancellation, atomic storage and private
|
|
22
|
+
refresh ownership. This is not an unmodified distribution of the Codex CLI.
|
|
23
|
+
|
|
24
|
+
The upstream NOTICE is retained below. The login port does not include the
|
|
25
|
+
Codex terminal UI or use Ratatui; its attribution is retained as part of the
|
|
26
|
+
upstream notice rather than a claim that the terminal UI is bundled here.
|
|
27
|
+
|
|
28
|
+
> OpenAI Codex
|
|
29
|
+
> Copyright 2025 OpenAI
|
|
30
|
+
>
|
|
31
|
+
> This project includes code derived from [Ratatui](https://github.com/ratatui/ratatui), licensed under the MIT license.
|
|
32
|
+
> Copyright (c) 2016-2022 Florian Dehau
|
|
33
|
+
> Copyright (c) 2023-2025 The Ratatui Developers
|
|
34
|
+
|
|
9
35
|
## OpenAI tiktoken
|
|
10
36
|
|
|
11
37
|
This project includes a port of the `o200k_base` ordinary-encoding logic and
|