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
Query the model metadata endpoint rather than relying on a static support table:
curl -sS https://api.tensorx.ai/v1/model/info \
-H "Authorization: Bearer $TENSORX_API_KEY" \
| jq -r '.data[]
| select(.model_info.supports_function_calling == true)
| .model_name'Use one of the returned IDs in the examples below.
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 callid- Unique ID for this tool call (use when sending results back)arguments- JSON string of function parametersfinish_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
Web Search
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?

