Function Calling
Define callable functions via the tools parameter. The model will decide whether to call functions based on user intent.
Models Supporting Function Calling
Filter by "Function Calling" tag on the models page.
β View modelsRequest Example
JSON
{
"model": "deepseek-v4-flash",
"messages": [
{
"role": "user",
"content": "What's the weather in Beijing?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather information for a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name"
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "Temperature unit"
}
},
"required": [
"city"
]
}
}
}
]
}Model Response
When the model decides to call a function, finish_reason is "tool_calls" and the message contains a tool_calls array.
JSON
{
"id": "chatcmpl-abc123",
"model": "deepseek-v4-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_abc123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"city\":\"Beijing\",\"unit\":\"celsius\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
]
}Call Flow
1
Send request with tools parameter defining available functions
2
Model returns tool_calls (function name + arguments)
3
Your code executes the function and gets the result
4
Send the result as a tool role message to the model
5
Model generates the final answer based on function results