xAI has provided documentation on the technical aspects of tool usage within agentic requests, including billing practices and token consumption. These details apply to models such as Grok 4.6, which can leverage tools like code execution and image generation.
Key Points
- Tool call decisions made by the model can be observed in real-time via the
tool_callsattribute on the chunk object during streaming agentic requests. - The API provides
response.tool_callsfor all attempted tool calls andresponse.server_side_tool_usagefor successfully executed tools, which determines billing. - Only successful tool executions, as reported in
server_side_tool_usage, are billed; failed attempts are not charged. - Agentic requests track
completion_tokens(final text output),prompt_tokens(cumulative input tokens across all inference requests),internal_tokens(model's internal reasoning),cached_prompt_tokens(tokens served from cache), andimage_tokens(tokens from visual content). - The
max_turnsparameter controls the maximum number of assistant/tool-call turns an agent can perform, where a turn represents one iteration of the agentic reasoning loop. - The image generation tool allows Grok to create and edit images using Grok Imagine and the grok-imagine-image-2.0 models within a conversation.
- The code execution tool enables Grok to write and execute Python code for calculations, data analysis, and complex computations.
Context
According to xAI, agentic requests have distinct token usage patterns compared to standard chat completions. The system differentiates between attempted and successful tool calls for billing purposes. The max_turns parameter is designed to limit the agent's reasoning loop iterations, not individual tool invocations. xAI also notes that server-side tools, such as web search and code execution, are executed automatically by xAI, while client-side tools require developer intervention.
Why It Matters
Understanding these details is crucial for developers building agentic applications with xAI models, as it clarifies cost implications, performance monitoring, and how to manage the complexity of multi-turn interactions and tool orchestration. The ability to integrate tools like code execution and image generation expands the practical applications of these models.
What To Do
- Note that only successful tool executions are billed, which can influence how developers design error handling for tool use.
- Compare the
response.tool_callsandresponse.server_side_tool_usagemetrics to understand the distinction between attempted and successful tool invocations. - Test the
max_turnsparameter to manage the depth of agentic reasoning loops in specific applications. - Watch for
cached_prompt_tokensto gauge the efficiency of prompt caching in agentic workflows.
