Repository navigation
Conversation
…items The Responses handler counted every web_search_call output item as one billable web search, so a response that searched once and opened two pages billed three searches. OpenAI charges the search action only: opening a page and searching inside a page read a page the search already returned and carry no search charge, and the pricing table has no line for them.
The file_search_call and function_call counts are already covered by TestOaiResponsesHandlerCountsOutputCallsNotDeclarations. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
No actionable comments were generated in the recent review. WalkthroughThe PR centralizes Responses tool-call billing and uses each output item's action to exclude ChangesResponses tool billing
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Possibly related issues
Suggested reviewers: Merge Risk:
|
Agent: Claude Code 2.1.332
本 PR 由 AI 辅助完成。代码、测试和本说明由 Claude Code 生成,提交前由 fork 维护者人工复核。
Closes #8507
Request summary
报告者用官方镜像验证:普通 OpenAI Responses 渠道把
web_search_call里的open_page也算作付费搜索。请求按上游回执只搜索了 1 次,消费日志和钱包却按 3 次工具调用结算。Summary
Responses 处理路径现在只对
action.type是search的web_search_call计一次搜索。open_page和find_in_page读的是搜索已经返回的页面,OpenAI 不对它们收工具调用费,定价表里也没有对应条目。新的计费入口
relay/common.CountBillableResponsesToolCalls处理一个 Responses 输出项:只有search动作计一次搜索,open_page和find_in_page不计。动作类型由relaykit/dto.ResponsesOutput.WebSearchActionType()读取,它把NormalizeResponsesWebSearchAction的find别名归一到find_in_page。两条边界保持原样:
action或返回未知动作类型时,仍然计费。上游不报动作的渠道维持原有口径。info.WebSearchBillingKey非空的渠道每一项都计。这些渠道的上游用自己的价格表区分搜索和页面抓取,计费归它们自己。流式路径共用
ResponsesUsageAccumulator,WebSocket Responses 也走同一个累加器,所以同样受益。Azure、xAI、DashScope、DeepSeek 的回执覆盖逻辑不受影响,它们用自己的 hook 覆盖同一批计数。Evidence
同一个响应的改动前后。 用 issue #8507 的原始响应体(1 个
search动作、2 个open_page动作、回执num_requests=1)跑非流式处理器:流式路径。 1 个
search动作加 1 个open_page动作:issue #8507 里报告者在官方镜像
calciumion/new-api:v1.0.0-rc.52上观察到同样的偏差:控制组(只有search)扣 5100 quota,异常组(search加两个open_page)扣 15100 quota,other.tool_surcharges记录{"name":"web_search","count":3,"price":10}。本次改动后,异常组与控制组同样扣 5100 quota。自动化测试,实际输出。
新增用例:
relay/common/tool_usage_test.go的TestCountBillableResponsesToolCallsWebSearchAction:search动作计一次,open_page和find_in_page不计,缺失动作和未知动作仍然计费。relay/common/tool_usage_test.go的TestCountBillableResponsesToolCallsWebSearchKeepsVendorSearchCounting:设置了WebSearchBillingKey的渠道每一项都计。relay/channel/openai/relay_responses_billing_test.go的TestOaiResponsesHandlerCountsSearchActionsOnly和TestOaiResponsesStreamHandlerCountsSearchActionsOnly:非流式和流式处理器各一例。上游语义依据。 OpenAI 的 Web search 指南写明 search 动作产生工具调用费,
open_page和find_in_page是推理模型的动作。定价表的 built-in tools 只有 "Web search $10.00 / 1k calls" 一行,没有页面打开的条目。OpenAI SDK 的Response.tool_usage.web_search.num_requests注释写明该计数排除 "actions such as opening a page"。Merge Danger
Door: two-way。没有数据迁移,没有表结构改动。回滚这个提交即可恢复改动前的计数口径。
Blast Radius: billing。普通 OpenAI Responses 渠道中,带
open_page动作的响应少收附加费,每个open_page少收 $10/1k。Token 费用不变,其余渠道不受影响。Summary by CodeRabbit