Skip to main content

Tool calling

Function/tool calling passes through the gateway untouched — define tools in the format of the surface you call, and the model's tool_calls come back in the same format, whichever provider actually served the request.

Define tools (OpenAI surface)

{
"model": "claude-opus-4-7",
"messages": [{"role": "user", "content": "What's the weather in Osaka?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"}
},
"required": ["city"]
}
}
}
]
}

The loop

  1. Model responds with tool_calls instead of content.
  2. Run the tool yourself, append a role: "tool" message with the result and the matching tool_call_id.
  3. Call the endpoint again with the extended conversation; the model produces the final answer.

Cross-provider notes

  • Not every model supports tools — the model catalog tags tool-capable models.
  • Tool call ids are provider-generated; always echo the id you received, never fabricate one.
  • Parallel tool calls (multiple entries in tool_calls) are surfaced as the provider emits them; handle the array, not just index 0.