Tool Calls
The API supports OpenAI-compatible function calling. Define your functions in the request; the model decides when to call them, and the server returns the call details for you to execute on the client
Step 1 — Define tools and get a tool call
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.API_KEY,
baseURL: 'http://localhost:9000/v1',
});
const completion = await client.chat.completions.create({
model: 'openai/gpt-4o',
messages: [
{ role: 'user', content: 'What is the weather in Tokyo?' }
],
tools: [
{
type: 'function',
function: {
name: 'get_weather',
description: 'Get the current weather for a city',
parameters: {
type: 'object',
properties: {
location: {
type: 'string',
description: 'City name, e.g. Tokyo, Japan'
},
unit: {
type: 'string',
enum: ['celsius', 'fahrenheit'],
description: 'Temperature unit'
}
},
required: ['location']
}
}
}
],
tool_choice: 'auto',
built_in_tools: 'none' // disable server tools so only yours are offered
});
console.log(completion.choices[0].message.tool_calls);Step 2 — Execute the function and send the result back
Controlling tool selection
Multi-tool call in one turn
Last updated