Tool Calling

The OpenResponses API supports tool calling to give models access to external functions. Define tools in your request with a name, description, and JSON schema for parameters. When the model determines it needs a tool to answer the user's question, it returns a function_call output with the tool name and arguments for you to execute.

import requests
import json

url = "https://llm.onerouter.pro/v1/responses"

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <API_KEY>",
}

data = {
    "model": "google/gemini-3-flash",
    "input": [
        {
            "type": "message",
            "role": "user",
            "content": "What is the weather like in New York?",
        }
    ],
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_weather",
                "description": "Get the current weather in a location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA",
                        },
                    },
                    "required": ["location"],
                },
            },
        }
    ],
    "tool_choice": "auto",
}

response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
result = response.json()

print(json.dumps(result, indent=2))

Tool call response

When the model decides to call a tool, the response includes a function_call output:

Tool choice options

  • auto - The model decides whether to call a tool

  • required - The model must call at least one tool

  • none - The model cannot call any tools

Last updated