codex-api-proxy 0.1.1__tar.gz → 0.1.2__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_api_proxy-0.1.2/PKG-INFO +237 -0
- codex_api_proxy-0.1.2/README.md +213 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/pyproject.toml +4 -5
- codex_api_proxy-0.1.2/src/codex_api_proxy/__init__.py +3 -0
- codex_api_proxy-0.1.2/src/codex_api_proxy/auth.py +332 -0
- codex_api_proxy-0.1.2/src/codex_api_proxy/chat_completions.py +291 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/src/codex_api_proxy/cli.py +84 -240
- codex_api_proxy-0.1.2/src/codex_api_proxy/config.py +111 -0
- codex_api_proxy-0.1.2/src/codex_api_proxy/main.py +637 -0
- codex_api_proxy-0.1.2/src/codex_api_proxy/models.py +99 -0
- codex_api_proxy-0.1.2/src/codex_api_proxy/sse_utils.py +37 -0
- codex_api_proxy-0.1.2/src/codex_api_proxy.egg-info/PKG-INFO +237 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/src/codex_api_proxy.egg-info/SOURCES.txt +7 -7
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/src/codex_api_proxy.egg-info/requires.txt +1 -2
- codex_api_proxy-0.1.2/tests/test_api.py +442 -0
- codex_api_proxy-0.1.2/tests/test_auth.py +173 -0
- codex_api_proxy-0.1.2/tests/test_chat_completions.py +82 -0
- codex_api_proxy-0.1.2/tests/test_cli.py +214 -0
- codex_api_proxy-0.1.2/tests/test_config.py +66 -0
- codex_api_proxy-0.1.2/tests/test_models.py +22 -0
- codex_api_proxy-0.1.1/PKG-INFO +0 -350
- codex_api_proxy-0.1.1/README.md +0 -325
- codex_api_proxy-0.1.1/src/codex_api_proxy/__init__.py +0 -3
- codex_api_proxy-0.1.1/src/codex_api_proxy/app_server_runner.py +0 -558
- codex_api_proxy-0.1.1/src/codex_api_proxy/codex_runner.py +0 -281
- codex_api_proxy-0.1.1/src/codex_api_proxy/config.py +0 -85
- codex_api_proxy-0.1.1/src/codex_api_proxy/main.py +0 -563
- codex_api_proxy-0.1.1/src/codex_api_proxy/prompt.py +0 -31
- codex_api_proxy-0.1.1/src/codex_api_proxy/schemas.py +0 -48
- codex_api_proxy-0.1.1/src/codex_api_proxy.egg-info/PKG-INFO +0 -350
- codex_api_proxy-0.1.1/tests/test_api.py +0 -375
- codex_api_proxy-0.1.1/tests/test_app_server_runner.py +0 -225
- codex_api_proxy-0.1.1/tests/test_cli.py +0 -598
- codex_api_proxy-0.1.1/tests/test_codex_runner.py +0 -211
- codex_api_proxy-0.1.1/tests/test_config.py +0 -52
- codex_api_proxy-0.1.1/tests/test_prompt.py +0 -36
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/setup.cfg +0 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/src/codex_api_proxy.egg-info/dependency_links.txt +0 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/src/codex_api_proxy.egg-info/entry_points.txt +0 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/src/codex_api_proxy.egg-info/top_level.txt +0 -0
- {codex_api_proxy-0.1.1 → codex_api_proxy-0.1.2}/tests/test_release_version.py +0 -0
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codex-api-proxy
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Local OpenAI-compatible HTTP proxy backed by Codex/OpenAI credentials
|
|
5
|
+
Author: codex-api-proxy contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: codex,openai,proxy,api,local
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Framework :: FastAPI
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
|
+
Requires-Python: >=3.11
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
Requires-Dist: fastapi<1,>=0.115
|
|
19
|
+
Requires-Dist: httpx<1,>=0.27
|
|
20
|
+
Requires-Dist: uvicorn[standard]<1,>=0.30
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest<9,>=8; extra == "dev"
|
|
23
|
+
Requires-Dist: pytest-asyncio<1,>=0.23; extra == "dev"
|
|
24
|
+
|
|
25
|
+
# codex-api-proxy
|
|
26
|
+
|
|
27
|
+
Local OpenAI-compatible HTTP proxy backed by Codex/OpenAI credentials.
|
|
28
|
+
|
|
29
|
+
The proxy has one runtime path: it reads credentials from `~/.codex/auth.json` or `CODEX_HOME/auth.json`, then forwards requests to the upstream OpenAI/Codex API. It no longer runs local `codex exec`, starts `codex app-server`, manages workspaces, or exposes sandbox/agent/fast engine settings.
|
|
30
|
+
|
|
31
|
+
## Product Scope
|
|
32
|
+
|
|
33
|
+
This package is intentionally narrow:
|
|
34
|
+
|
|
35
|
+
- expose OpenAI-compatible local endpoints for clients such as OpenClaw;
|
|
36
|
+
- reuse the user's existing Codex/OpenAI login credentials;
|
|
37
|
+
- support `/v1/chat/completions`, `/v1/responses`, and `/v1/models`;
|
|
38
|
+
- convert Chat Completions to Responses API when using ChatGPT Codex credentials;
|
|
39
|
+
- otherwise transparently forward OpenAI API-key requests to OpenAI's native `/chat/completions`.
|
|
40
|
+
|
|
41
|
+
Out of scope:
|
|
42
|
+
|
|
43
|
+
- local command execution;
|
|
44
|
+
- workspace read/write control;
|
|
45
|
+
- Codex sandbox configuration;
|
|
46
|
+
- app-server workers;
|
|
47
|
+
- simulated tool-call wrapping;
|
|
48
|
+
- custom model execution engines.
|
|
49
|
+
|
|
50
|
+
Tool calls and function calls are handled by the upstream OpenAI-compatible API response, not by local prompt wrapping.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip3 install codex-api-proxy
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
For local development from this checkout:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
python3 -m pip install -e '.[dev]'
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Credentials
|
|
65
|
+
|
|
66
|
+
The proxy reads Codex credentials from:
|
|
67
|
+
|
|
68
|
+
```text
|
|
69
|
+
~/.codex/auth.json
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
or, when `CODEX_HOME` is set:
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
$CODEX_HOME/auth.json
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Supported auth shapes:
|
|
79
|
+
|
|
80
|
+
- `OPENAI_API_KEY`: forwarded to `https://api.openai.com/v1`;
|
|
81
|
+
- Codex/ChatGPT `tokens.access_token`: forwarded to `https://chatgpt.com/backend-api/codex`.
|
|
82
|
+
|
|
83
|
+
For Codex/ChatGPT token auth, the proxy refreshes tokens automatically:
|
|
84
|
+
|
|
85
|
+
- before a request when the access token JWT expires within 5 minutes;
|
|
86
|
+
- before a request when `last_refresh` is older than 8 days and the access token has no parseable expiry;
|
|
87
|
+
- after an upstream `401`, then it retries the original request once.
|
|
88
|
+
|
|
89
|
+
Refreshed tokens are written back to `auth.json` with `0600` permissions when supported by the platform.
|
|
90
|
+
|
|
91
|
+
Outbound upstream proxy settings are controlled by environment variables:
|
|
92
|
+
|
|
93
|
+
- `CODEX_API_PROXY_HTTPS_PROXY`
|
|
94
|
+
- `HTTPS_PROXY`
|
|
95
|
+
- `https_proxy`
|
|
96
|
+
|
|
97
|
+
When none are set, the proxy defaults to `http://127.0.0.1:8118`.
|
|
98
|
+
|
|
99
|
+
You can also set the upstream proxy explicitly at startup:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
codex-api-proxy start --proxy=http://127.0.0.1:8118
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Run
|
|
106
|
+
|
|
107
|
+
Start in the background:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
codex-api-proxy start
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Run in the foreground with debug logs:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
codex-api-proxy start --foreground --log-level debug
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Bind to all interfaces with local bearer auth:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
codex-api-proxy start --host 0.0.0.0 --api-key local-secret
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Start with an explicit upstream proxy:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
codex-api-proxy start --proxy=http://127.0.0.1:8118
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Restart using the last saved start settings:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
codex-api-proxy restart
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Stop:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
codex-api-proxy stop
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Status:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
codex-api-proxy status --verbose
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## CLI Options
|
|
150
|
+
|
|
151
|
+
- `--host`: bind host, default `127.0.0.1`
|
|
152
|
+
- `--port`: bind port, default `8765`
|
|
153
|
+
- `--api-key`: require client requests to send `Authorization: Bearer <key>`
|
|
154
|
+
- `--proxy`: upstream HTTP(S) proxy URL for OpenAI/Codex API calls
|
|
155
|
+
- `--log-level`: `debug`, `info`, `warning`, or `error`
|
|
156
|
+
- `--pid-file`: daemon pid file, default `~/.codex-api-proxy/codex-api-proxy.pid`
|
|
157
|
+
- `--log-file`: daemon log file, default `~/.codex-api-proxy/codex-api-proxy.log`
|
|
158
|
+
- `--state-file`: daemon state file, default `~/.codex-api-proxy/codex-api-proxy.state.json`
|
|
159
|
+
- `--foreground`: run without daemonizing
|
|
160
|
+
|
|
161
|
+
Environment variables for the local server:
|
|
162
|
+
|
|
163
|
+
- `CODEX_PROXY_HOST`
|
|
164
|
+
- `CODEX_PROXY_PORT`
|
|
165
|
+
- `CODEX_PROXY_API_KEY`
|
|
166
|
+
- `CODEX_API_PROXY_HTTPS_PROXY`
|
|
167
|
+
- `CODEX_PROXY_LOG_LEVEL`
|
|
168
|
+
|
|
169
|
+
Token refresh compatibility variables:
|
|
170
|
+
|
|
171
|
+
- `CODEX_REFRESH_TOKEN_URL_OVERRIDE`: override the OAuth refresh endpoint
|
|
172
|
+
- `CODEX_APP_SERVER_LOGIN_CLIENT_ID`: override the OAuth client id
|
|
173
|
+
|
|
174
|
+
## API
|
|
175
|
+
|
|
176
|
+
Health:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
curl -sS http://127.0.0.1:8765/health
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Models:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
curl -sS http://127.0.0.1:8765/v1/models
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Chat completion:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
curl -sS http://127.0.0.1:8765/v1/chat/completions \
|
|
192
|
+
-H 'Content-Type: application/json' \
|
|
193
|
+
-d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Streaming chat completion:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
curl -N http://127.0.0.1:8765/v1/chat/completions \
|
|
200
|
+
-H 'Content-Type: application/json' \
|
|
201
|
+
-d '{"model":"gpt-5.5","stream":true,"messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Responses API passthrough:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
curl -sS http://127.0.0.1:8765/v1/responses \
|
|
208
|
+
-H 'Content-Type: application/json' \
|
|
209
|
+
-d '{"model":"gpt-5.5","input":"Reply with exactly: pong"}'
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
When `--api-key` is configured:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
curl -sS http://127.0.0.1:8765/v1/chat/completions \
|
|
216
|
+
-H 'Authorization: Bearer local-secret' \
|
|
217
|
+
-H 'Content-Type: application/json' \
|
|
218
|
+
-d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Operations
|
|
222
|
+
|
|
223
|
+
`/health` checks that credentials can be loaded and shows the upstream mode without exposing secrets.
|
|
224
|
+
|
|
225
|
+
`/ready` is an alias of `/health`.
|
|
226
|
+
|
|
227
|
+
`/metrics` returns local request counters:
|
|
228
|
+
|
|
229
|
+
- `requests_total`
|
|
230
|
+
- `requests_ok`
|
|
231
|
+
- `requests_error`
|
|
232
|
+
- `errors_by_status`
|
|
233
|
+
- `uptime_seconds`
|
|
234
|
+
|
|
235
|
+
When `--log-level debug` is set, chat completions log input messages and output messages through `codex_api_proxy.messages` and the daemon's `uvicorn.error` log stream. Streaming output is logged after the stream finishes. These logs can contain prompt and response data; use debug logging only in trusted environments.
|
|
236
|
+
|
|
237
|
+
Latency summaries are logged through `codex_api_proxy.latency`.
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# codex-api-proxy
|
|
2
|
+
|
|
3
|
+
Local OpenAI-compatible HTTP proxy backed by Codex/OpenAI credentials.
|
|
4
|
+
|
|
5
|
+
The proxy has one runtime path: it reads credentials from `~/.codex/auth.json` or `CODEX_HOME/auth.json`, then forwards requests to the upstream OpenAI/Codex API. It no longer runs local `codex exec`, starts `codex app-server`, manages workspaces, or exposes sandbox/agent/fast engine settings.
|
|
6
|
+
|
|
7
|
+
## Product Scope
|
|
8
|
+
|
|
9
|
+
This package is intentionally narrow:
|
|
10
|
+
|
|
11
|
+
- expose OpenAI-compatible local endpoints for clients such as OpenClaw;
|
|
12
|
+
- reuse the user's existing Codex/OpenAI login credentials;
|
|
13
|
+
- support `/v1/chat/completions`, `/v1/responses`, and `/v1/models`;
|
|
14
|
+
- convert Chat Completions to Responses API when using ChatGPT Codex credentials;
|
|
15
|
+
- otherwise transparently forward OpenAI API-key requests to OpenAI's native `/chat/completions`.
|
|
16
|
+
|
|
17
|
+
Out of scope:
|
|
18
|
+
|
|
19
|
+
- local command execution;
|
|
20
|
+
- workspace read/write control;
|
|
21
|
+
- Codex sandbox configuration;
|
|
22
|
+
- app-server workers;
|
|
23
|
+
- simulated tool-call wrapping;
|
|
24
|
+
- custom model execution engines.
|
|
25
|
+
|
|
26
|
+
Tool calls and function calls are handled by the upstream OpenAI-compatible API response, not by local prompt wrapping.
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip3 install codex-api-proxy
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For local development from this checkout:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python3 -m pip install -e '.[dev]'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Credentials
|
|
41
|
+
|
|
42
|
+
The proxy reads Codex credentials from:
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
~/.codex/auth.json
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
or, when `CODEX_HOME` is set:
|
|
49
|
+
|
|
50
|
+
```text
|
|
51
|
+
$CODEX_HOME/auth.json
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Supported auth shapes:
|
|
55
|
+
|
|
56
|
+
- `OPENAI_API_KEY`: forwarded to `https://api.openai.com/v1`;
|
|
57
|
+
- Codex/ChatGPT `tokens.access_token`: forwarded to `https://chatgpt.com/backend-api/codex`.
|
|
58
|
+
|
|
59
|
+
For Codex/ChatGPT token auth, the proxy refreshes tokens automatically:
|
|
60
|
+
|
|
61
|
+
- before a request when the access token JWT expires within 5 minutes;
|
|
62
|
+
- before a request when `last_refresh` is older than 8 days and the access token has no parseable expiry;
|
|
63
|
+
- after an upstream `401`, then it retries the original request once.
|
|
64
|
+
|
|
65
|
+
Refreshed tokens are written back to `auth.json` with `0600` permissions when supported by the platform.
|
|
66
|
+
|
|
67
|
+
Outbound upstream proxy settings are controlled by environment variables:
|
|
68
|
+
|
|
69
|
+
- `CODEX_API_PROXY_HTTPS_PROXY`
|
|
70
|
+
- `HTTPS_PROXY`
|
|
71
|
+
- `https_proxy`
|
|
72
|
+
|
|
73
|
+
When none are set, the proxy defaults to `http://127.0.0.1:8118`.
|
|
74
|
+
|
|
75
|
+
You can also set the upstream proxy explicitly at startup:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
codex-api-proxy start --proxy=http://127.0.0.1:8118
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Run
|
|
82
|
+
|
|
83
|
+
Start in the background:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
codex-api-proxy start
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Run in the foreground with debug logs:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
codex-api-proxy start --foreground --log-level debug
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Bind to all interfaces with local bearer auth:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
codex-api-proxy start --host 0.0.0.0 --api-key local-secret
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Start with an explicit upstream proxy:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
codex-api-proxy start --proxy=http://127.0.0.1:8118
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Restart using the last saved start settings:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
codex-api-proxy restart
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Stop:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
codex-api-proxy stop
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Status:
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
codex-api-proxy status --verbose
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## CLI Options
|
|
126
|
+
|
|
127
|
+
- `--host`: bind host, default `127.0.0.1`
|
|
128
|
+
- `--port`: bind port, default `8765`
|
|
129
|
+
- `--api-key`: require client requests to send `Authorization: Bearer <key>`
|
|
130
|
+
- `--proxy`: upstream HTTP(S) proxy URL for OpenAI/Codex API calls
|
|
131
|
+
- `--log-level`: `debug`, `info`, `warning`, or `error`
|
|
132
|
+
- `--pid-file`: daemon pid file, default `~/.codex-api-proxy/codex-api-proxy.pid`
|
|
133
|
+
- `--log-file`: daemon log file, default `~/.codex-api-proxy/codex-api-proxy.log`
|
|
134
|
+
- `--state-file`: daemon state file, default `~/.codex-api-proxy/codex-api-proxy.state.json`
|
|
135
|
+
- `--foreground`: run without daemonizing
|
|
136
|
+
|
|
137
|
+
Environment variables for the local server:
|
|
138
|
+
|
|
139
|
+
- `CODEX_PROXY_HOST`
|
|
140
|
+
- `CODEX_PROXY_PORT`
|
|
141
|
+
- `CODEX_PROXY_API_KEY`
|
|
142
|
+
- `CODEX_API_PROXY_HTTPS_PROXY`
|
|
143
|
+
- `CODEX_PROXY_LOG_LEVEL`
|
|
144
|
+
|
|
145
|
+
Token refresh compatibility variables:
|
|
146
|
+
|
|
147
|
+
- `CODEX_REFRESH_TOKEN_URL_OVERRIDE`: override the OAuth refresh endpoint
|
|
148
|
+
- `CODEX_APP_SERVER_LOGIN_CLIENT_ID`: override the OAuth client id
|
|
149
|
+
|
|
150
|
+
## API
|
|
151
|
+
|
|
152
|
+
Health:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
curl -sS http://127.0.0.1:8765/health
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Models:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
curl -sS http://127.0.0.1:8765/v1/models
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Chat completion:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
curl -sS http://127.0.0.1:8765/v1/chat/completions \
|
|
168
|
+
-H 'Content-Type: application/json' \
|
|
169
|
+
-d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Streaming chat completion:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
curl -N http://127.0.0.1:8765/v1/chat/completions \
|
|
176
|
+
-H 'Content-Type: application/json' \
|
|
177
|
+
-d '{"model":"gpt-5.5","stream":true,"messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Responses API passthrough:
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
curl -sS http://127.0.0.1:8765/v1/responses \
|
|
184
|
+
-H 'Content-Type: application/json' \
|
|
185
|
+
-d '{"model":"gpt-5.5","input":"Reply with exactly: pong"}'
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
When `--api-key` is configured:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
curl -sS http://127.0.0.1:8765/v1/chat/completions \
|
|
192
|
+
-H 'Authorization: Bearer local-secret' \
|
|
193
|
+
-H 'Content-Type: application/json' \
|
|
194
|
+
-d '{"model":"gpt-5.5","messages":[{"role":"user","content":"Reply with exactly: pong"}]}'
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Operations
|
|
198
|
+
|
|
199
|
+
`/health` checks that credentials can be loaded and shows the upstream mode without exposing secrets.
|
|
200
|
+
|
|
201
|
+
`/ready` is an alias of `/health`.
|
|
202
|
+
|
|
203
|
+
`/metrics` returns local request counters:
|
|
204
|
+
|
|
205
|
+
- `requests_total`
|
|
206
|
+
- `requests_ok`
|
|
207
|
+
- `requests_error`
|
|
208
|
+
- `errors_by_status`
|
|
209
|
+
- `uptime_seconds`
|
|
210
|
+
|
|
211
|
+
When `--log-level debug` is set, chat completions log input messages and output messages through `codex_api_proxy.messages` and the daemon's `uvicorn.error` log stream. Streaming output is logged after the stream finishes. These logs can contain prompt and response data; use debug logging only in trusted environments.
|
|
212
|
+
|
|
213
|
+
Latency summaries are logged through `codex_api_proxy.latency`.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "codex-api-proxy"
|
|
3
|
-
version = "0.1.
|
|
4
|
-
description = "Local OpenAI-compatible HTTP proxy backed by Codex
|
|
3
|
+
version = "0.1.2"
|
|
4
|
+
description = "Local OpenAI-compatible HTTP proxy backed by Codex/OpenAI credentials"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
license = "MIT"
|
|
@@ -21,7 +21,7 @@ classifiers = [
|
|
|
21
21
|
]
|
|
22
22
|
dependencies = [
|
|
23
23
|
"fastapi>=0.115,<1",
|
|
24
|
-
"
|
|
24
|
+
"httpx>=0.27,<1",
|
|
25
25
|
"uvicorn[standard]>=0.30,<1",
|
|
26
26
|
]
|
|
27
27
|
|
|
@@ -30,7 +30,6 @@ codex-api-proxy = "codex_api_proxy.cli:main"
|
|
|
30
30
|
|
|
31
31
|
[project.optional-dependencies]
|
|
32
32
|
dev = [
|
|
33
|
-
"httpx>=0.27,<1",
|
|
34
33
|
"pytest>=8,<9",
|
|
35
34
|
"pytest-asyncio>=0.23,<1",
|
|
36
35
|
]
|
|
@@ -38,5 +37,5 @@ dev = [
|
|
|
38
37
|
[tool.pytest.ini_options]
|
|
39
38
|
addopts = "-q"
|
|
40
39
|
testpaths = ["tests"]
|
|
41
|
-
pythonpath = ["src"]
|
|
40
|
+
pythonpath = ["src", "."]
|
|
42
41
|
asyncio_mode = "auto"
|