← Back to API Guides

Tool Calls

Enable the model to call external tools and APIs. Build powerful agent workflows with structured tool interactions.

Define Tools

Provide a list of tools with JSON Schema descriptions. The model decides when and how to call them.
{
  "model": "deepseek-v4-pro",
  "messages": [
    {"role": "user", "content": "What is the weather in Beijing?"}
  ],
  "tools": [{
    "type": "function",
    "function": {
      "name": "get_weather",
      "description": "Get current weather",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {"type": "string"}
        },
        "required": ["city"]
      }
    }
  }]
}

Handle Tool Calls

When the model decides to use a tool, the response will contain a tool_calls array. Execute the function and send the result back as a "tool" role message to continue the conversation.