SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
2.9 KB

# xAI function calling (type: "function")

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) 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 Last verified: 2026-09-19

# Definitions

API Tool entry Forced choice
Responses {"type":"function","name","description","parameters":{JSON Schema},"strict"?,"defer_loading"?} {"type":"function","name":"…"}
Chat Completions {"type":"function","function":{"name","description","parameters"}} {"type":"function","function":{"name":"…"}}
Messages (Anthropic) {"name","description" (required),"input_schema":{"type":"object","properties","required"}} {"type":"tool","name":"…"}; any, auto

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).

# Outputs (live)

  • 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,…}].
  • 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.
  • 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":"…"}]}.

# Round trip results (live)

Tool 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.

Examples: examples/xai/tools/function-calling/ (sh, py, ts). Tests: tests/xai/test_tools.py::test_chat_function_call_roundtrip, test_responses_function_call_roundtrip.