Tool calling

Features

Tool calling

Expose functions the model can call, run them in your code, and feed the results back. The schema is OpenAI-compatible, so existing agent code works unchanged.

Define tools

Pass a tools array of function definitions. Use tool_choice to let the model decide ("auto"), force a specific tool, or disable tools.

request
{
  "model": "auto",
  "messages": [
    { "role": "user", "content": "What's the weather in Riyadh?" }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
          "type": "object",
          "properties": { "city": { "type": "string" } },
          "required": ["city"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}

Handle tool calls

When the model decides to call a tool, the response contains tool_calls. Execute the function in your code, then send the result back as a role: "tool" message to continue the turn.

response
"message": {
  "role": "assistant",
  "tool_calls": [
    {
      "id": "call_abc",
      "type": "function",
      "function": { "name": "get_weather", "arguments": "{\"city\":\"Riyadh\"}" }
    }
  ]
}

Routing

When a request includes tools, the router limits candidates to tool-capable models, so "auto" never selects a model that can't honor your tool schema.