Loading...
Loading...
Define callable functions via the tools parameter. The model will decide whether to call functions based on user intent.
Filter by "π§ Function Calling" tag on the models page.
β View models{
"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"
]
}
}
}
]
}When the model decides to call a function, finish_reason is "tool_calls" and the message contains a tool_calls array.
{
"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"
}
]
}Send request with tools parameter defining available functions
Model returns tool_calls (function name + arguments)
Your code executes the function and gets the result
Send the result as a tool role message to the model
Model generates the final answer based on function results