Python 88.3%
TypeScript 7.6%
Shell 4.1%
1# xAI function calling (`type: "function"`)23**Status:** DOCUMENTED · LIVE_VERIFIED (2026-09-19, grok-4.3 — Chat: forced, `required` → 2 parallel calls, `parallel_tool_calls:false` → 1, round trip, streaming; Responses: forced `function_call` + `function_call_output` via `previous_response_id`; Messages: `tool_use`/`tool_result`)4**Sources:** https://docs.x.ai/developers/tools/function-calling · https://docs.x.ai/developers/model-capabilities/text/structured-outputs (tool schemas strict) · OpenAPI `FunctionDefinition`, `Tool`, `ToolChoice`, `ModelToolChoice`, `FunctionToolCall`, `FunctionToolCallOutput`5**Last verified:** 2026-09-1967## Definitions8| API | Tool entry | Forced choice |9|---|---|---|10| Responses | `{"type":"function","name","description","parameters":{JSON Schema},"strict"?,"defer_loading"?}` | `{"type":"function","name":"…"}` |11| Chat Completions | `{"type":"function","function":{"name","description","parameters"}}` | `{"type":"function","function":{"name":"…"}}` |12| Messages (Anthropic) | `{"name","description" (required),"input_schema":{"type":"object","properties","required"}}` | `{"type":"tool","name":"…"}`; `any`, `auto` |1314`tool_choice`: `auto` (default) · `required` · `none` · forced. `parallel_tool_calls` default true. ≤350 tools. `parameters` root must be an object or `anyOf/oneOf` of objects (else 400 naming the tool). Arguments always conform to the schema (`strict` implicit; the explicit flag is accepted and ignored). `defer_loading:true` needs the alpha `tool_search` tool (403 otherwise).1516## Outputs (live)17- Chat: `finish_reason:"tool_calls"`, `message.content:""`, `message.tool_calls:[{"id":"call-24b65428-…-0","type":"function","function":{"name":"get_weather","arguments":"{\"city\":\"Paris\"}"}}]`, `reasoning_content` present. Streaming: one chunk with `delta.tool_calls[{index:0,…}]`.18- Responses: item `{"type":"function_call","id":"fc_<resp>_0","call_id":"call-…-0","name","arguments","status":"completed"}`; reply `{"type":"function_call_output","call_id","output":"{…}"}` (string or content parts). Stream: `response.output_item.added` → `response.function_call_arguments.delta` (single, whole JSON) → `…done` → `response.output_item.done`.19- Messages: `content[] {type:"tool_use", id:"call-…", name, input:{…}}`, `stop_reason:"tool_use"`; reply with `{"role":"user","content":[{"type":"tool_result","tool_use_id","content":"…"}]}`.2021## Round trip results (live)22Tool result `{"temp_c":18,"sky":"sunny"}` → "The weather in Paris is currently 18°C and sunny." on all three APIs. Mixed with server tools: the request pauses at the first client-side call (`max_turns` resets afterwards) — see [../../xai/tool-loop.md](../../xai/tool-loop.md).2324Examples: `examples/xai/tools/function-calling/` (sh, py, ts). Tests: `tests/xai/test_tools.py::test_chat_function_call_roundtrip`, `test_responses_function_call_roundtrip`.25