Tools
Region
Function calling in the OpenAI shape. Define tools on the request; the model returns tool_calls; run the function and send the result back as a tool message.
Request with a tool
{
"model": "deepseek-flash",
"messages": [{"role": "user", "content": "What is the weather in Brisbane?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
}
}
],
"tool_choice": "auto"
}Response
{
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"tool_calls": [
{
"id": "call_8f2a",
"type": "function",
"function": { "name": "get_weather", "arguments": "{\"city\":\"Brisbane\"}" }
}
]
},
"finish_reason": "tool_calls"
}
]
}Run get_weather, then send the whole conversation back with the result:
Second request
{
"model": "deepseek-flash",
"messages": [
{"role": "user", "content": "What is the weather in Brisbane?"},
{"role": "assistant", "content": null, "tool_calls": [{ "id": "call_8f2a", "type": "function",
"function": { "name": "get_weather", "arguments": "{\"city\":\"Brisbane\"}" } }]},
{"role": "tool", "tool_call_id": "call_8f2a", "content": "{\"temp_c\": 24, \"sky\": \"clear\"}"}
]
}