fix(billing): make Responses image generation prices configurable - #6471
fix(billing): make Responses image generation prices configurable#6471chenyoubei wants to merge 1 commit into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughImage-generation quality and size now flow from Responses requests and outputs into built-in tool usage records. Quota calculation selects model-specific configurable image-generation prices, including per-tier overrides and fallback pricing. ChangesImage-generation pricing flow
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ResponsesRequest
participant GenRelayInfoResponses
participant ImageGenerationCallCounter
participant TextQuota
participant OperationSettings
ResponsesRequest->>GenRelayInfoResponses: provide quality and size
GenRelayInfoResponses->>ImageGenerationCallCounter: retain request options
ImageGenerationCallCounter->>ImageGenerationCallCounter: observe and aggregate response tiers
ImageGenerationCallCounter->>TextQuota: commit billable tool usage
TextQuota->>OperationSettings: resolve model, quality, and size price
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
922b306 to
e93cefb
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
relay/common/tool_usage_test.go (1)
53-67: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winGuard the reserved-names assertions with
require, not a conditional skip.
info.ResponsesUsageInfois always initialized unconditionally insideCountBillableToolCall(see tool_usage.go lines 28-32) before any reserved-name filtering happens, so theif info.ResponsesUsageInfo != nilguard here is always true — but if that ever regressed, the assertions would be silently skipped rather than failing the test.As per coding guidelines,
**/*_test.gotests should "prefer deterministic table tests with explicit inputs and exact outputs" — replace the conditional with a directrequire.NotNilso a regression fails loudly.✅ Proposed fix
info.CountBillableToolCall(dto.BuildInCallFunctionCall, dto.BuildInToolWebSearchPreview) info.CountBillableToolCall(dto.BuildInCallFunctionCall, dto.BuildInToolFileSearch) info.CountBillableToolCall(dto.BuildInCallFunctionCall, dto.BuildInToolGoogleSearch) info.CountBillableToolCall(dto.BuildInCallFunctionCall, dto.BuildInToolImageGeneration) - if info.ResponsesUsageInfo != nil { - assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolWebSearchPreview) - assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolFileSearch) - assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolGoogleSearch) - assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolImageGeneration) - } + require.NotNil(t, info.ResponsesUsageInfo) + assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolWebSearchPreview) + assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolFileSearch) + assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolGoogleSearch) + assert.NotContains(t, info.ResponsesUsageInfo.BuiltInTools, dto.BuildInToolImageGeneration)🤖 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 `@relay/common/tool_usage_test.go` around lines 53 - 67, Replace the conditional guard around the reserved-tool assertions in TestCountBillableToolCallFunctionCallSkipsReservedNames with require.NotNil on info.ResponsesUsageInfo, then keep the existing assert.NotContains checks unconditional so initialization regressions fail loudly.Source: Coding guidelines
🤖 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 `@relay/common/tool_usage.go`:
- Around line 79-198: Update ImageGenerationCallCounter to track deduplicated
completed outputs by each observed non-auto quality/size combination instead of
retaining only the last values. Update Commit to transfer every tier’s count and
quality/size metadata into the billing representation consumed by
non-image-generation surcharge pricing, while preserving request-level capping
and existing deduplication. Ensure auto or missing dimensions follow the
established default tier behavior.
---
Outside diff comments:
In `@relay/common/tool_usage_test.go`:
- Around line 53-67: Replace the conditional guard around the reserved-tool
assertions in TestCountBillableToolCallFunctionCallSkipsReservedNames with
require.NotNil on info.ResponsesUsageInfo, then keep the existing
assert.NotContains checks unconditional so initialization regressions fail
loudly.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4d185b60-ad80-4d4c-b043-cf2b8cd06bb1
📒 Files selected for processing (4)
relay/common/relay_info.gorelay/common/relay_info_test.gorelay/common/tool_usage.gorelay/common/tool_usage_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
- relay/common/relay_info.go
- relay/common/relay_info_test.go
be6bbc7 to
1741325
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@relay/common/relay_info_test.go`:
- Line 51: Update the test request setup in the relevant test to use
httptest.NewRequestWithContext instead of httptest.NewRequest, add the context
import, and pass context.Background() explicitly while preserving the existing
POST method, URL, and nil body.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b848d30-e073-4ce5-8825-baa506bfd87b
📒 Files selected for processing (8)
relay/common/relay_info.gorelay/common/relay_info_test.gorelay/common/tool_usage.gorelay/common/tool_usage_test.goservice/text_quota.goservice/text_quota_test.gosetting/operation_setting/tools.gosetting/operation_setting/tools_price_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
- service/text_quota_test.go
- relay/common/relay_info.go
- setting/operation_setting/tools.go
- setting/operation_setting/tools_price_test.go
- service/text_quota.go
- relay/common/tool_usage.go
1741325 to
bc0ab3d
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
bc0ab3d to
51a2f4b
Compare
Important
本 PR 由 chenyoubei 提交;过程中使用 AI 辅助,所有代码、测试和说明均已由提交者人工复核。
📝 变更描述 / Description
基于最新
main已引入的统一工具附加费架构,补全 Responses API 图片生成工具按实际请求参数计价的能力。image_generation工具声明中记录quality和size。auto时保留请求参数。quality/size组合分别累计和计价,不会把全部图片套用最后一张的价格。GetImageGenerationToolPriceForModel(modelName, quality, size):image_generation/<quality>/<size>;auto时回退到image_generation。main的默认行为不变:未配置具体档位时仍使用image_generation = 150(单位为 $/1K calls)。0的具体档位会终止查找并禁用该档位收费,不会错误回退到默认价格。例如,若某个上游把
gpt-5.5*的托管图片工具路由到 GPT Image 2,可在现有“工具价格”设置中配置:{ "image_generation:gpt-5.5*": 211, "image_generation/high/1024x1024:gpt-5.5*": 211, "image_generation/high/1024x1536:gpt-5.5*": 165, "image_generation/high/1536x1024:gpt-5.5*": 165 }代码不猜测 OpenAI 内部最终使用的图片模型;管理员可以按 Responses 模型前缀、质量和尺寸显式配置并审计计费规则。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
main一致。📸 运行证明 / Proof of Work
新增回归测试覆盖:
quality/size提取。auto时保留请求参数。image_generation默认价格。0时不回退、不收费。Summary by CodeRabbit
New Features
Bug Fixes