Commit a4a51b8
feat(llm-access): add standalone Codex image gateway (#52)
* feat(llm-access): add standalone Codex image gateway
* fix(llm-access): address codex image gateway review
* feat(llm-access): track codex image key usage
* feat(llm-access): share codex image gateway
* refactor(codex-image): tidy shared gateway and document the dual-mode design
Apply low-risk review improvements and add the detailed comments the shared
gateway was missing:
- Decouple the per-key image usage rollup from the response hot path
(fire-and-forget spawn) so the account/key concurrency permits release and
the image bytes return without waiting on a control-plane write. The rollup
is an admin-visibility metric, not a billing/quota gate.
- Reclaim ImageKeyLimiter map entries once a key is idle and carries no
min-start-interval clock (stamp last_start only when an interval is
configured), fixing the asymmetric unbounded growth vs ImageAccountLimiter.
- Rebuild hydrate_codex_image_route with struct-update (..candidate) so new
ProviderCodexRoute fields are carried through automatically.
- Strip the standalone/direct Codex image toggles in normalize_kiro_key_patch
so Codex-only flags never persist onto a Kiro key.
- Document the dual-mode gateway, the two per-key gates, the dispatch/failover
flow, the limiter semantics, and the deployment caveats (0032 backfill,
path-split Caddy routing, per-process image-log dir).
- Convert unwrap()/unwrap_err() in the new gateway tests to expect/expect_err
for the workspace unwrap_used lint under -D warnings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* refactor(codex-image): dedupe helpers and tighten request-id/base64 hot paths
Reduce duplication and tidy conventions in the shared image gateway:
- Route the gateway's and session.rs's copies of the header-value helper to the
existing shared llm_access_codex::request::extract_header_value, and use the
shared codex_user_agent directly instead of a local wrapper.
- Consolidate now_ms() (duplicated in gateway.rs + logging.rs) and the
poison-safe lock_unpoisoned() (a limiter local plus two inline copies) into a
small crate-internal util module.
- Make request ids collision-free within a millisecond via a per-process atomic
counter, and count base64 padding over bytes instead of chars to skip UTF-8
decoding of multi-megabyte image payloads.
- Refresh the crate module doc to describe the shared dual-entrypoint design.
No behavior change; verified via clippy -D warnings and the codex-image / codex
/ provider test suites.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* feat(codex-image): trace requests and record integrated-mode usage
Optimize observability and analytics for the Codex image gateway.
Tracing: emit a structured info! line on every completed image request
(request_id, mode, key, account, endpoint, status, failover, duration,
image_count, usage_tokens), a warn! on account exhaustion, an info! on
per-key limit rejection, and a debug! per candidate dispatch, so a
request's status is traceable end to end.
Integrated-mode usage: when running inside the main Codex API binary
(IntegratedCodexApi) emit one UsageEvent per request via the usage
journal, so image traffic lands in the DuckDB usage log alongside
text/Kiro requests. gpt-image usage tokens are folded into the output
and billable columns (Codex bills image generation by token, so it
counts toward the key quota); failures carry the upstream error
message/class for inline display. The standalone binary has no usage
worker and keeps relying on the JSONL image log + per-key image rollup.
Image visualization: add a response_image_count field to UsageEvent,
persisted through the journal wire and DuckDB (migration 0005, appended
at the tail of the summary/detail selects so no positional index shifts),
surfaced on the public/admin usage DTOs, and rendered in the usage UI as
a "生图 xN" badge plus an image-count line in the token column.
Round-trip tests cover the new field through both the journal postcard
codec and the DuckDB summary/detail decode paths.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(usage): preserve image metrics during duckdb compaction
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 3350d78 commit a4a51b8
79 files changed
Lines changed: 4407 additions & 103 deletions
File tree
- crates
- frontend/src
- pages
- llm-access-codex-image
- src
- tests
- llm-access-codex/src/request
- llm-access-core/src
- store
- llm-access-migrations
- migrations
- duckdb
- postgres
- src
- llm-access-store/src
- duckdb
- postgres
- llm-access
- src
- provider
- llm-usage-journal/src
- deployment-examples
- caddy
- systemd
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5972 | 5972 | | |
5973 | 5973 | | |
5974 | 5974 | | |
5975 | | - | |
| 5975 | + | |
| 5976 | + | |
5976 | 5977 | | |
5977 | 5978 | | |
5978 | 5979 | | |
| |||
5981 | 5982 | | |
5982 | 5983 | | |
5983 | 5984 | | |
| 5985 | + | |
| 5986 | + | |
| 5987 | + | |
5984 | 5988 | | |
5985 | 5989 | | |
5986 | 5990 | | |
| |||
6066 | 6070 | | |
6067 | 6071 | | |
6068 | 6072 | | |
| 6073 | + | |
| 6074 | + | |
| 6075 | + | |
| 6076 | + | |
6069 | 6077 | | |
6070 | 6078 | | |
6071 | 6079 | | |
| |||
6095 | 6103 | | |
6096 | 6104 | | |
6097 | 6105 | | |
| 6106 | + | |
| 6107 | + | |
| 6108 | + | |
| 6109 | + | |
| 6110 | + | |
| 6111 | + | |
6098 | 6112 | | |
6099 | 6113 | | |
6100 | 6114 | | |
| |||
6113 | 6127 | | |
6114 | 6128 | | |
6115 | 6129 | | |
| 6130 | + | |
| 6131 | + | |
| 6132 | + | |
| 6133 | + | |
| 6134 | + | |
| 6135 | + | |
6116 | 6136 | | |
6117 | 6137 | | |
6118 | 6138 | | |
| |||
6170 | 6190 | | |
6171 | 6191 | | |
6172 | 6192 | | |
| 6193 | + | |
| 6194 | + | |
| 6195 | + | |
| 6196 | + | |
6173 | 6197 | | |
6174 | 6198 | | |
6175 | 6199 | | |
| |||
6324 | 6348 | | |
6325 | 6349 | | |
6326 | 6350 | | |
6327 | | - | |
| 6351 | + | |
| 6352 | + | |
6328 | 6353 | | |
6329 | 6354 | | |
6330 | 6355 | | |
| |||
6333 | 6358 | | |
6334 | 6359 | | |
6335 | 6360 | | |
| 6361 | + | |
| 6362 | + | |
| 6363 | + | |
6336 | 6364 | | |
6337 | 6365 | | |
6338 | 6366 | | |
| |||
6382 | 6410 | | |
6383 | 6411 | | |
6384 | 6412 | | |
| 6413 | + | |
| 6414 | + | |
6385 | 6415 | | |
6386 | 6416 | | |
6387 | 6417 | | |
| |||
8956 | 8986 | | |
8957 | 8987 | | |
8958 | 8988 | | |
| 8989 | + | |
| 8990 | + | |
| 8991 | + | |
8959 | 8992 | | |
8960 | 8993 | | |
8961 | 8994 | | |
| |||
8985 | 9018 | | |
8986 | 9019 | | |
8987 | 9020 | | |
| 9021 | + | |
| 9022 | + | |
| 9023 | + | |
8988 | 9024 | | |
8989 | 9025 | | |
8990 | 9026 | | |
| |||
9032 | 9068 | | |
9033 | 9069 | | |
9034 | 9070 | | |
| 9071 | + | |
| 9072 | + | |
| 9073 | + | |
9035 | 9074 | | |
9036 | 9075 | | |
9037 | 9076 | | |
| |||
9068 | 9107 | | |
9069 | 9108 | | |
9070 | 9109 | | |
| 9110 | + | |
| 9111 | + | |
| 9112 | + | |
9071 | 9113 | | |
9072 | 9114 | | |
9073 | 9115 | | |
| |||
9179 | 9221 | | |
9180 | 9222 | | |
9181 | 9223 | | |
| 9224 | + | |
| 9225 | + | |
| 9226 | + | |
| 9227 | + | |
| 9228 | + | |
| 9229 | + | |
| 9230 | + | |
| 9231 | + | |
| 9232 | + | |
| 9233 | + | |
| 9234 | + | |
| 9235 | + | |
| 9236 | + | |
| 9237 | + | |
| 9238 | + | |
| 9239 | + | |
| 9240 | + | |
| 9241 | + | |
9182 | 9242 | | |
9183 | 9243 | | |
9184 | 9244 | | |
| |||
9855 | 9915 | | |
9856 | 9916 | | |
9857 | 9917 | | |
| 9918 | + | |
| 9919 | + | |
| 9920 | + | |
| 9921 | + | |
9858 | 9922 | | |
9859 | 9923 | | |
9860 | 9924 | | |
| |||
9883 | 9947 | | |
9884 | 9948 | | |
9885 | 9949 | | |
| 9950 | + | |
| 9951 | + | |
| 9952 | + | |
9886 | 9953 | | |
9887 | 9954 | | |
9888 | 9955 | | |
| |||
10248 | 10315 | | |
10249 | 10316 | | |
10250 | 10317 | | |
| 10318 | + | |
| 10319 | + | |
| 10320 | + | |
10251 | 10321 | | |
10252 | 10322 | | |
10253 | 10323 | | |
| |||
10347 | 10417 | | |
10348 | 10418 | | |
10349 | 10419 | | |
| 10420 | + | |
| 10421 | + | |
10350 | 10422 | | |
10351 | 10423 | | |
10352 | 10424 | | |
| |||
10373 | 10445 | | |
10374 | 10446 | | |
10375 | 10447 | | |
| 10448 | + | |
| 10449 | + | |
| 10450 | + | |
| 10451 | + | |
10376 | 10452 | | |
10377 | 10453 | | |
10378 | 10454 | | |
| |||
10430 | 10506 | | |
10431 | 10507 | | |
10432 | 10508 | | |
| 10509 | + | |
| 10510 | + | |
| 10511 | + | |
10433 | 10512 | | |
10434 | 10513 | | |
10435 | 10514 | | |
| |||
10492 | 10571 | | |
10493 | 10572 | | |
10494 | 10573 | | |
| 10574 | + | |
| 10575 | + | |
| 10576 | + | |
10495 | 10577 | | |
10496 | 10578 | | |
10497 | 10579 | | |
| |||
10563 | 10645 | | |
10564 | 10646 | | |
10565 | 10647 | | |
| 10648 | + | |
| 10649 | + | |
| 10650 | + | |
10566 | 10651 | | |
10567 | 10652 | | |
10568 | 10653 | | |
| |||
11196 | 11281 | | |
11197 | 11282 | | |
11198 | 11283 | | |
| 11284 | + | |
| 11285 | + | |
| 11286 | + | |
11199 | 11287 | | |
11200 | 11288 | | |
11201 | 11289 | | |
| |||
11225 | 11313 | | |
11226 | 11314 | | |
11227 | 11315 | | |
| 11316 | + | |
| 11317 | + | |
| 11318 | + | |
11228 | 11319 | | |
11229 | 11320 | | |
11230 | 11321 | | |
| |||
11960 | 12051 | | |
11961 | 12052 | | |
11962 | 12053 | | |
| 12054 | + | |
| 12055 | + | |
| 12056 | + | |
| 12057 | + | |
| 12058 | + | |
| 12059 | + | |
| 12060 | + | |
| 12061 | + | |
| 12062 | + | |
| 12063 | + | |
| 12064 | + | |
| 12065 | + | |
| 12066 | + | |
| 12067 | + | |
11963 | 12068 | | |
11964 | 12069 | | |
11965 | 12070 | | |
| |||
12084 | 12189 | | |
12085 | 12190 | | |
12086 | 12191 | | |
| 12192 | + | |
| 12193 | + | |
12087 | 12194 | | |
12088 | 12195 | | |
12089 | 12196 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1899 | 1899 | | |
1900 | 1900 | | |
1901 | 1901 | | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
1902 | 1905 | | |
1903 | 1906 | | |
1904 | 1907 | | |
| |||
2006 | 2009 | | |
2007 | 2010 | | |
2008 | 2011 | | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
2009 | 2015 | | |
2010 | 2016 | | |
2011 | 2017 | | |
| |||
0 commit comments