Skip to content

Guides

Tool calling

Let a model call functions you define, then send the results back.

Tool calling works on models that list tools in supported_parameters. Check GET /v1/models or the model's page before relying on it.

Define a tool

curl https://deference.si/v1/chat/completions \
  -H "Authorization: Bearer $DEFERENCE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-5.5",
    "messages": [{ "role": "user", "content": "What is the weather in Lisbon?" }],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get the current weather for a city.",
        "parameters": {
          "type": "object",
          "properties": { "city": { "type": "string" } },
          "required": ["city"]
        }
      }
    }]
  }'

Read the call

When the model wants a tool, finish_reason is tool_calls and message.tool_calls holds the name and a JSON string of arguments.

Return the result

Append the assistant message, then one tool message per call with its tool_call_id, and send the conversation again.

{
  "role": "tool",
  "tool_call_id": "call_abc123",
  "content": "{\"temperature_c\": 21, \"sky\": \"clear\"}"
}

Control the choice

tool_choice accepts "auto" (default), "none", "required" or a specific function.

On Messages and Responses

The Messages endpoint takes Anthropic's tools and tool_use blocks. The Responses endpoint takes function tools in tools and returns function_call items. Both pass through unchanged.