Tool Calling
Function calling and tool integration with the Responses API
Basic Tool Definition
const weatherTool = {
type: 'function' as const,
name: 'get_weather',
description: 'Get the current weather in a location',
strict: null,
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'The city and state, e.g. San Francisco, CA',
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit'],
},
},
required: ['location'],
},
};
const response = await fetch('https://llm.onerouter.pro/v1/responses', {
method: 'POST',
headers: {
'Authorization': 'Bearer <<API_KEY>>',
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'o4-mini',
input: [
{
type: 'message',
role: 'user',
content: [
{
type: 'input_text',
text: 'What is the weather in San Francisco?',
},
],
},
],
tools: [weatherTool],
tool_choice: 'auto',
max_output_tokens: 9000,
}),
});
const result = await response.json();
console.log(result);Tool Choice Options
Tool Choice
Description
Force Specific Tool
Disable Tool Calling
Multiple Tools
Parallel Tool Calls
Tool Call Response
Tool Responses in Conversation
Streaming Tool Calls
Tool Validation
Best Practices
Next Steps
Last updated