For the complete documentation index, see llms.txt. This page is also available as Markdown.

Function Calling

Let AI models call your functions to take actions and retrieve information.


Overview

Function calling (also called "tools") allows models to:

  • Request specific data from your systems

  • Trigger actions in your application

  • Access real-time information

  • Perform calculations

The model doesn't execute functions directly—it returns a structured request for your code to handle.


Supported Models

Model
Function Calling

z-ai/glm-5.1

minimax/minimax-m2.5

moonshotai/kimi-k2.5

deepseek/deepseek-chat-v3.1

deepseek/deepseek-r1-0528

minimax/minimax-m2

qwen/qwen3-235b-a22b-2507

openai/gpt-oss-120b


Basic Example

Here's a weather function the model can call:


Response Format

When the model decides to call a function:

Key fields:

  • tool_calls - Array of functions the model wants to call

  • id - Unique ID for this tool call (use when sending results back)

  • arguments - JSON string of function parameters

  • finish_reason: "tool_calls" - Indicates model is waiting for results


Complete Flow

A full function calling conversation:


Tool Choice Options

Control when the model uses functions:


Parallel Tool Calls

Models can request multiple functions at once:

Handle all calls and return all results:


Common Tool Examples

Calculator

Database Query


Best Practices

Writing Good Descriptions

The description field is crucial—it tells the model when to use the function:

Parameter Descriptions

Help the model provide correct arguments:

Error Handling

Return errors as tool results so the model can respond appropriately:


See Also

  • Chat Completions - Full API reference

  • Streaming - Stream function call responses

  • Models - Models that support function calling

Last updated

Was this helpful?