Function Calling
Let models invoke external tools and APIs through function definitions.
Function Calling enables AI models to interact with external tools and APIs. You define functions the model can call, and it returns structured arguments for you to execute.
How it works
Define your tools with JSON Schema parameters in the
tools array.Send the request — the model may return a
tool_calls response instead of text.Execute the function locally with the returned arguments.
Send the function result back to the model for a final answer.
Complete example
1. Initialize the client
2. Define the function
3. Send the request with tools
4. Execute and send result back
Tool schema reference
| Field | Type | Description |
|---|---|---|
name | string | Function name (a-z, A-Z, 0-9, underscores/dashes, max 64 chars) |
description | string | Helps the model decide when to call this function |
parameters | object | JSON Schema describing the function's parameters |
strict | boolean | When true, the model strictly follows the schema |
Last updated on