Skip to main content
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.

Overview

Function calling works in two steps:
  1. Request: Send a request with tool definitions. The model may request to call one or more tools.
  2. Execute & Respond: Execute the requested functions and send the results back to the model.

Tool Definition

A tool is defined using the Tool interface:

FunctionDefinition

Parameters Schema

The parameters field uses JSON Schema format:
Example - Defining a Tool:

Tool Choice

The tool_choice parameter controls when and which tools the model should call:

ToolChoice Type

Example - Force a Specific Tool:
Example - Disable Tool Calls:

Tool Call Object Structure

When the model requests a tool call, you receive a ToolCall object:

Parsing Arguments

Complete Example

Here’s a complete end-to-end example with error handling:
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:

Streaming with Tools

The stream() method also supports tools. For details about streaming, see the Stream Method documentation.

Best Practices

1. Always Provide Descriptions

Descriptions help the model understand when to use each function:

2. Use Clear Parameter Names

3. Mark Required Parameters

4. Handle Multiple Tool Calls

Models can request multiple tool calls in a single response. Use Promise.all() to execute them in parallel:

5. Error Handling in Tool Execution

6. Keep Tools Available

Include tools in follow-up requests so the model can call them again if needed: