---
agent:
  instructions: "Search the site by keyword or question. The search API returns Markdown."
  endpoint: "https://platform.invideo.io/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Tools (function calling)

> Let a chat model call your functions with OpenAI-compatible tools and tool_choice, then send the results back for the final answer.

# Tools

Give a model `tools` and it can answer with calls to them instead of text. You
run the functions, send the results back as `tool` messages, and the model
writes its answer. Models with tools have `chat.capabilities.tools: true` in
`GET /v1/models`.

## 1. Offer the tools

```bash
curl https://platform-api.invideo.io/v1/chat/completions \
  -H "Authorization: Bearer $INVIDEO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-4-carbon",
    "messages": [{"role": "user", "content": "What is the weather in Pune?"}],
    "tools": [{
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "The weather now in a city.",
        "parameters": {
          "type": "object",
          "properties": {"city": {"type": "string"}},
          "required": ["city"]
        }
      }
    }]
  }'
```

The answer has `finish_reason: "tool_calls"`:

```json
{
  "choices": [{
    "index": 0,
    "finish_reason": "tool_calls",
    "message": {
      "role": "assistant",
      "content": null,
      "tool_calls": [{"id": "toolu_01", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\":\"Pune\"}"}}]
    }
  }]
}
```

## 2. Send the results back

Send the whole conversation again: the assistant message with its
`tool_calls`, then one `tool` message per call with its `tool_call_id`.

```json
{
  "model": "gemini-4-carbon",
  "messages": [
    {"role": "user", "content": "What is the weather in Pune?"},
    {"role": "assistant", "content": null, "tool_calls": [{"id": "toolu_01", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\":\"Pune\"}"}}]},
    {"role": "tool", "tool_call_id": "toolu_01", "content": "{\"temp_c\": 29, \"sky\": \"clear\"}"}
  ],
  "tools": [ ... the same tools ... ]
}
```

The next answer is text (or more tool calls).

## tool_choice

| Value | The model |
| --- | --- |
| `"auto"` (default) | Answers in text or calls tools. |
| `"none"` | Answers in text; the tools are not sent. |
| `"required"` | Must call one or more tools. |
| `{"type": "function", "function": {"name": "get_weather"}}` | Must call that tool. |

Each call is one request in Logs and is charged its own tokens: a tool loop of
three turns is three requests.
