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 decides a tool would help answer the user's question, it returns a function_call output with the tool name and arguments for you to execute.
const apiKey = process.env.AI_GATEWAY_API_KEY;
const response = await fetch('https://ai-gateway.vercel.sh/v1/responses', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: 'deepseek/deepseek-v3.2-thinking',
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',
}),
});When the model decides to call a tool, the response includes a function_call output:
{
"output": [
{
"type": "function_call",
"name": "get_weather",
"arguments": "{\"location\": \"New York, NY\"}",
"call_id": "call_abc123"
}
]
}auto- The model decides whether to call a toolrequired- The model must call at least one toolnone- The model cannot call any tools
Was this helpful?