Use this file to discover all available pages before exploring further.
The Edgee TypeScript SDK supports OpenAI-compatible function calling (tools), allowing models to request execution of functions you define. This enables models to interact with external APIs, databases, and your application logic.
Here’s a complete end-to-end example with error handling:
import Edgee from 'edgee';const edgee = new Edgee('your-api-key');// Define the weather functionasync function getWeather(location: string, unit: string = 'celsius') { // Simulate API call return { location, temperature: 15, unit, condition: 'sunny' };}// Step 1: Initial request with toolsconst response1 = await edgee.send({ model: 'gpt-5.2', input: { messages: [ { role: 'user', content: 'What is the weather in Paris and Tokyo?' } ], tools: [ { type: 'function', function: { name: 'get_weather', description: 'Get the current weather for a location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'The city name' }, unit: { type: 'string', enum: ['celsius', 'fahrenheit'], description: 'Temperature unit' } }, required: ['location'] } } } ], tool_choice: 'auto' }});// Step 2: Execute all tool callsconst messages = [ { role: 'user', content: 'What is the weather in Paris and Tokyo?' }, response1.message! // Include assistant's message];if (response1.toolCalls) { for (const toolCall of response1.toolCalls) { const args = JSON.parse(toolCall.function.arguments); const result = await getWeather(args.location, args.unit); messages.push({ role: 'tool', tool_call_id: toolCall.id, content: JSON.stringify(result) }); }}// Step 3: Send results backconst response2 = await edgee.send({ model: 'gpt-5.2', input: { messages, tools: [ // Keep tools available for follow-up { type: 'function', function: { name: 'get_weather', description: 'Get the current weather for a location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'The city name' }, unit: { type: 'string', enum: ['celsius', 'fahrenheit'] } }, required: ['location'] } } } ] }});console.log(response2.text);
Example - Multiple Tools:You can provide multiple tools and let the model choose which ones to call:You can provide multiple tools and let the model choose:
const response = await edgee.send({ model: 'gpt-5.2', input: { messages: [ { role: 'user', content: 'Get the weather in Paris and send an email about it' } ], tools: [ { type: 'function', function: { name: 'get_weather', description: 'Get the current weather for a location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'City name' } }, required: ['location'] } } }, { type: 'function', function: { name: 'send_email', description: 'Send an email to a recipient', parameters: { type: 'object', properties: { to: { type: 'string', description: 'Recipient email address' }, subject: { type: 'string', description: 'Email subject' }, body: { type: 'string', description: 'Email body' } }, required: ['to', 'subject', 'body'] } } } ], tool_choice: 'auto' }});