feat(proxy): forward Anthropic speed:fast to Codex priority tier#170
Conversation
📝 WalkthroughWalkthroughAdds Anthropic Messages ( ChangesAnthropic Messages Service Tier Support
Sequence DiagramsequenceDiagram
participant Client
participant TranslateAnthropicToCodex
participant upstreamServiceTier
participant CodexUpstream
participant Handler
participant UsageLogger
Client->>TranslateAnthropicToCodex: POST /v1/messages (speed)
TranslateAnthropicToCodex->>TranslateAnthropicToCodex: shouldUseCodexPriorityForAnthropicSpeed()
TranslateAnthropicToCodex->>upstreamServiceTier: upstreamServiceTier("priority")
upstreamServiceTier-->>TranslateAnthropicToCodex: priority tier value
TranslateAnthropicToCodex->>CodexUpstream: send Codex request (maybe service_tier)
CodexUpstream-->>Handler: response.completed (may include response.service_tier)
Handler->>Handler: resolveServiceTier(actualServiceTier, serviceTier)
Handler->>UsageLogger: record UsageLogInput.ServiceTier
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
360e46e to
bd19194
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/API.md`:
- Line 312: The table cell containing the text "模型映射映射到 Codex 模型名(如 Claude →
`gpt-5.5`)" has a duplicated word "映射"; update that string to read "模型映射到 Codex
模型名(如 Claude → `gpt-5.5`)" (remove the duplicate "映射") so the description is
correct.
- Line 315: Docs state the fallback for reasoning.effort is "medium" but runtime
actually falls back to "high" when no output_config.effort is provided and
Anthropic thinking.type is not set; update the docs entry for reasoning.effort
to reflect the runtime default "high" (keeping the rest about preferring
output_config.effort, the Anthropic thinking.type/budget_tokens mapping, and
normalization to low/medium/high/xhigh intact) so documentation matches the
implementation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7d7f37d4-0e29-4b0e-a8d1-fa73c1bd8189
📒 Files selected for processing (5)
docs/API.mddocs/ARCHITECTURE.mdproxy/anthropic.goproxy/anthropic_test.goproxy/handler_anthropic.go
|
|
||
| | 主题 | 行为 | | ||
| |------|------| | ||
| | **模型** | 经管理台模型映射映射到 Codex 模型名(如 Claude → `gpt-5.5`) | |
There was a problem hiding this comment.
Fix duplicated wording in the model mapping description.
Line 312 contains 模型映射映射 (duplicate “映射”).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/API.md` at line 312, The table cell containing the text "模型映射映射到 Codex
模型名(如 Claude → `gpt-5.5`)" has a duplicated word "映射"; update that string to
read "模型映射到 Codex 模型名(如 Claude → `gpt-5.5`)" (remove the duplicate "映射") so the
description is correct.
| | **模型** | 经管理台模型映射映射到 Codex 模型名(如 Claude → `gpt-5.5`) | | ||
| | **`speed`** | Anthropic 入参仅识别官方 `speed:"fast"`,并映射为 Codex `service_tier:"priority"`;其它 `speed` 值不触发 priority | | ||
| | **`service_tier`** | Anthropic 请求侧 `service_tier` 不在当前兼容范围内,不从该字段解析 fast mode | | ||
| | **`reasoning.effort`** | 优先使用 `output_config.effort`(经归一为 `low` / `medium` / `high` / `xhigh`);否则若存在 Anthropic **`thinking.type=enabled`**,按 `budget_tokens` 粗映射档位;否则默认 **`medium`**(避免未带 `output_config` 的客户端始终吃满 `high` 推理成本) | |
There was a problem hiding this comment.
Default reasoning.effort in docs conflicts with runtime behavior.
Line 315 says the fallback is medium, but current behavior is high (see proxy/anthropic.go Line 474-479 and proxy/anthropic_test.go Line 59-61). Please align docs and implementation to the same default to avoid cost/latency surprises.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@docs/API.md` at line 315, Docs state the fallback for reasoning.effort is
"medium" but runtime actually falls back to "high" when no output_config.effort
is provided and Anthropic thinking.type is not set; update the docs entry for
reasoning.effort to reflect the runtime default "high" (keeping the rest about
preferring output_config.effort, the Anthropic thinking.type/budget_tokens
mapping, and normalization to low/medium/high/xhigh intact) so documentation
matches the implementation.
bd19194 to
20f37ef
Compare
Map official speed:"fast" to upstream service_tier priority, omit priority when absent, and log resolved service_tier on /v1/messages for Usage admin fast stats.
20f37ef to
0e77bee
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
proxy/anthropic_test.go (1)
87-127: ⚡ Quick winAdd normalization cases for
speedmapping.Line 94 currently validates only exact lowercase
"fast". Since translator logic trims and lowercases, add uppercase/whitespace variants to lock that contract in tests.✅ Proposed test additions
cases := []struct { name string field string wantTier bool }{ {"absent omits priority", "", false}, {"speed fast maps to priority", `,"speed":"fast"`, true}, + {"speed FAST maps to priority", `,"speed":"FAST"`, true}, + {"speed with spaces maps to priority", `,"speed":" fast "`, true}, {"speed standard omits priority", `,"speed":"standard"`, false}, }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@proxy/anthropic_test.go` around lines 87 - 127, The test TestTranslateAnthropicToCodex_SpeedFastMapsToCodexPriority currently only checks the exact lowercase "fast" string; add additional table-driven cases to assert that trimmed/upper/mixed-case variants also map to service_tier "priority" (e.g., fields containing `,"speed":" FAST "`, `,"speed":"Fast"`), keeping the same assertions that "speed" is not forwarded in the Codex body; update the cases slice in the test and keep the call to TranslateAnthropicToCodexWithModels and subsequent gjson.GetBytes checks unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@proxy/anthropic_test.go`:
- Around line 87-127: The test
TestTranslateAnthropicToCodex_SpeedFastMapsToCodexPriority currently only checks
the exact lowercase "fast" string; add additional table-driven cases to assert
that trimmed/upper/mixed-case variants also map to service_tier "priority"
(e.g., fields containing `,"speed":" FAST "`, `,"speed":"Fast"`), keeping the
same assertions that "speed" is not forwarded in the Codex body; update the
cases slice in the test and keep the call to TranslateAnthropicToCodexWithModels
and subsequent gjson.GetBytes checks unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 113d30b9-66b3-4a4b-b1d2-90d4e94d608e
📒 Files selected for processing (5)
docs/API.mddocs/ARCHITECTURE.mdproxy/anthropic.goproxy/anthropic_test.goproxy/handler_anthropic.go
✅ Files skipped from review due to trivial changes (2)
- docs/ARCHITECTURE.md
- docs/API.md
There was a problem hiding this comment.
🧹 Nitpick comments (1)
proxy/anthropic_test.go (1)
87-127: ⚡ Quick winAdd normalization coverage for
speedinput.Please add one case like mixed-case/whitespace (
" FAST "), since runtime mapping trims and lowercases before checkingfast.Proposed test case addition
cases := []struct { name string field string wantTier bool }{ {"absent omits priority", "", false}, {"speed fast maps to priority", `,"speed":"fast"`, true}, + {"speed fast with spaces/case maps to priority", `,"speed":" FAST "`, true}, {"speed standard omits priority", `,"speed":"standard"`, false}, }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@proxy/anthropic_test.go` around lines 87 - 127, Add a new table case in TestTranslateAnthropicToCodex_SpeedFastMapsToCodexPriority to cover normalization: include a case with field `,"speed":" FAST "` (mixed-case with surrounding whitespace) and expect wantTier true; this verifies TranslateAnthropicToCodexWithModels trims and lowercases the speed before comparing to "fast" and ensures service_tier becomes "priority" and speed is not forwarded to the Codex body.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@proxy/anthropic_test.go`:
- Around line 87-127: Add a new table case in
TestTranslateAnthropicToCodex_SpeedFastMapsToCodexPriority to cover
normalization: include a case with field `,"speed":" FAST "` (mixed-case with
surrounding whitespace) and expect wantTier true; this verifies
TranslateAnthropicToCodexWithModels trims and lowercases the speed before
comparing to "fast" and ensures service_tier becomes "priority" and speed is not
forwarded to the Codex body.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 120efeaa-43d9-43c3-ae6e-5c7792072f41
📒 Files selected for processing (5)
docs/API.mddocs/ARCHITECTURE.mdproxy/anthropic.goproxy/anthropic_test.goproxy/handler_anthropic.go
✅ Files skipped from review due to trivial changes (2)
- docs/ARCHITECTURE.md
- docs/API.md
Summary
speed:"fast"to upstream Codexservice_tier:"priority"(matches official Codex CLIServiceTier::Fastmapping).service_tierwhenspeedis absent or notfast; do not parse Anthropic request-sideservice_tier(Priority Tier is a separate capability).service_tieron/v1/messagesfor Usage admin fast-mode stats; document behavior indocs/API.mdanddocs/ARCHITECTURE.md.Test plan
go test ./proxy/... -run 'Anthropic|ServiceTier|Speed'/fastON → upstream WS body includesservice_tier: prioritydefaultEnvidence
Claude Code:
Codex upstream request log:
Admin UI Show:
Summary by CodeRabbit
New Features
Documentation