Skip to content

fix(grok): bill search calls from xAI usage success counts - #8864

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
Anankke:fix/grok-search-billing-usage
Nov 20, 2026
Merged

Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
Anankke:fix/grok-search-billing-usage

Conversation

@Anankke

@Anankke Anankke commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #8863

With server_side_tool_usage_details in usage, SearchCount is web_search_calls + x_search_calls + document_search_calls, xAI's success counts for the web_search_call, xs_ and as_ calls counted before. Without it, items are counted as before. Failed calls stop being billed. X Search stays per call.

The added tests fail on main.

When a Grok response usage carries server_side_tool_usage_details, take SearchCount from web_search_calls, x_search_calls and document_search_calls instead of counting output items.

xAI documents server_side_tool_usage as the successful calls that determine billing, so failed calls and server-side tools that return nothing are no longer billed. Classes the item counter does not count and the x_posts_fetched / x_users_fetched item counts are not read.

Without server_side_tool_usage_details the existing item counting is unchanged. The usage is read from the JSON body, the SSE body and the terminal stream event, for /v1/responses, /v1/messages and /v1/chat/completions, streaming and not. ResponsesUsage keeps the raw object so the buffered paths, which count from a decoded response, can read it.
@Wei-Shaw
Wei-Shaw merged commit 9cf9921 into Wei-Shaw:main Nov 20, 2026
9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] grok: SearchCount bills failed search calls

2 participants