# Tool calling
Let a model request a function that your application executes deliberately.

## Describe a tool
Add a `tools` array with a function name, description and JSON Schema parameters. Choose a model with `tools` support. `provider.require_parameters: true` avoids silently dropping required tool settings on an incompatible route.

## Offer one function
The example describes a weather lookup. `tool_choice: auto` lets the model decide whether to request it; declaring a function does not execute any code in your application.

### curl

```curl
curl --request POST \
  --url 'https://api.tokenlane.de/v1/chat/completions' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "deepseek/deepseek-v4-flash-0731",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 400,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Read the weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ],
          "additionalProperties": false
        }
      }
    }
  ],
  "tool_choice": "auto",
  "provider": {
    "require_parameters": true
  }
}'
```

### node

```node
import OpenAI from 'openai';

const client = new OpenAI({ baseURL: "https://api.tokenlane.de/v1", apiKey: process.env.TOKENLANE_API_KEY });
const response = await client.chat.completions.create({
  "model": "deepseek/deepseek-v4-flash-0731",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 400,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Read the weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ],
          "additionalProperties": false
        }
      }
    }
  ],
  "tool_choice": "auto",
  "provider": {
    "require_parameters": true
  }
}, {});
console.log(response);
```

### python

```python
import os
import json
from openai import OpenAI

client = OpenAI(base_url="https://api.tokenlane.de/v1", api_key=os.environ["TOKENLANE_API_KEY"])
body = json.loads(r'''{
  "model": "deepseek/deepseek-v4-flash-0731",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 400,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Read the weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ],
          "additionalProperties": false
        }
      }
    }
  ],
  "tool_choice": "auto",
  "provider": {
    "require_parameters": true
  }
}''')
response = client.chat.completions.create(
    model=body["model"],
    messages=body["messages"],
    max_tokens=body["max_tokens"],
    tool_choice=body["tool_choice"],
    tools=body["tools"],
    extra_body=json.loads(r'''{
  "provider": {
    "require_parameters": true
  }
}''')
)
print(response)
```

### vercel

```vercel
// This operation uses HTTP directly.
const response = await fetch("https://api.tokenlane.de/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.TOKENLANE_API_KEY,
    "Content-Type": "application/json",
  },
  body: `{
  "model": "deepseek/deepseek-v4-flash-0731",
  "messages": [
    {
      "role": "user",
      "content": "Hello"
    }
  ],
  "max_tokens": 400,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Read the weather for a city.",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ],
          "additionalProperties": false
        }
      }
    }
  ],
  "tool_choice": "auto",
  "provider": {
    "require_parameters": true
  }
}`,
});
console.log(await response.text());
```

## Complete the conversation
Inspect `message.tool_calls`, validate the function name and parsed arguments, apply your permissions and execute the allowed action. Append the assistant tool-call message and a `tool` message with the matching `tool_call_id`, then request the final answer. Bound the number of tool rounds and handle parallel calls only if your implementation supports them.

## Keep execution safe
Treat arguments as untrusted model output. Never let a model invent permissions, arbitrary code or destinations. If no route supports the requested tool shape, choose an eligible model; do not remove validation to make the request succeed. Use timeouts and an explicit error result when a tool fails.
