Skip to main content
Lesson 3 of 16 · Integrated Tools: Web, X, Code

Tool costs and billing

Lesson 3 of 16 Updated July 30, 2026 Developer
On this page
  1. Understanding Grok tool billing
  2. Two-part billing structure
  3. Cumulative cost scenarios
  4. Cost optimization strategies
  5. Comparison with SDKs
  6. Key takeaways

Understanding Grok tool billing

Using Grok API integrated tools incurs additional costs beyond standard token consumption. Understanding this billing structure is essential to forecast your spending and optimize your integration.

Two-part billing structure

Each tool call is billed in two ways:

1. Token consumption

Tools consume tokens like any interaction with the model. Input tokens include your prompt, the tool definitions, and the conversation context. Output tokens include the model response and the tool results.

Search results (web or X) add significant input token volume because the model receives excerpts from the pages or posts found. The more numerous or detailed the results, the higher the token consumption.

2. Cost per invocation

In addition to tokens, each tool call is billed at a flat rate of $5 per 1,000 invocations, or $0.005 per call. This rate is identical for the three main tools:

  • Web Search: $0.005 per search
  • X Search: $0.005 per search
  • Code Execution: $0.005 per execution

This cost is billed per tool call, regardless of the number of results returned or the execution complexity.

Cumulative cost scenarios

The model can make multiple tool calls for a single user request. Here are common scenarios:

Simple request (1 call)

A user asks for the latest news on a specific topic. The model performs a single web search. Additional cost: $0.005 + tokens for results.

Complex request (multiple calls)

A user requests a comparative analysis requiring web data and a calculation. The model performs a web search, then uses Code Execution to process the data. Additional cost: $0.010 + tokens for both results.

Iterative request (successive calls)

The model deems the initial results insufficient and refines its search with a second web call. Additional cost: $0.010 for both searches.

Cost optimization strategies

Be precise in your prompts

An ambiguous prompt leads the model to perform multiple searches to cover different possible interpretations. A precise prompt reduces the number of calls.

Enable only necessary tools

If your use case requires only web search, do not add X Search or Code Execution to the tools array. The model might use them unnecessarily.

Use domain filtering

For Web Search, the allowed_domains and excluded_domains parameters limit the search scope. More targeted results mean fewer iterations.

Monitor your usage

The xAI console lets you track your costs in real time. Set up billing alerts to avoid overspending, especially during the development phase when tests can accumulate.

Comparison with SDKs

Billing is identical regardless of the SDK used (xAI SDK, OpenAI SDK, Vercel AI SDK, or direct cURL). Costs depend only on the number of invocations and tokens consumed, not the access method.

Key takeaways

  • Billing combines tokens (standard consumption) and invocations ($0.005 per call)
  • The rate is uniform: $5 for 1,000 calls, regardless of the tool
  • The model can make multiple calls per request, multiplying costs
  • Precise prompts and appropriate filtering reduce unnecessary calls
  • The xAI console lets you monitor consumption in real time