Skip to content
Docs

Guides

Tool calling

Describe your functions in tools. The model replies with tool_calls; you run them and send the results back.

A tool call round trip

Python
tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a city.",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

messages = [{"role": "user", "content": "What's the weather in Lisbon?"}]
response = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017", messages=messages, tools=tools
)
message = response.choices[0].message

# Send the assistant message back unchanged, then one result per call.
messages.append(message)
for call in message.tool_calls:
    messages.append({
        "role": "tool",
        "tool_call_id": call.id,
        "content": '{"temp_c": 21, "sky": "clear"}',
    })

final = client.chat.completions.create(
    model="deepseek-v4.1-flash-1017", messages=messages, tools=tools
)
print(final.choices[0].message.content)

Send the assistant message back as it came, including reasoning_content. The model needs its own thinking to continue after a tool result.

Tool calling works on every model, in the three API formats.

tool_choice "auto" and "none" work on every model. "required" and a named tool are sent on every model, but only the models that list tool_choice in supported_parameters (GET /v1/models) always follow them. Add "provider": {"require_parameters": true} to get 404 instead of a model that may not.

Anthropic and Responses

Tool use works the same way on /v1/messages (tool_use and tool_result blocks): the model returns tool_use blocks, and you answer with tool_result blocks in the next user message.

Server tools

Two tools run on our side, without code of yours: web search and web fetch, available on standard models. Every other tool runs in your code.