Use Tool Calling
Give a model tools it can call: define functions as JSON Schema in the chat request, control them with tool_choice, and run the calls in your code.
Tool calling lets a model ask your code to do something — look up the weather, query a database, run a calculation — instead of answering from memory alone. You define the tools in the request, the model names the one it wants and the arguments to pass, your code runs it, and you send the result back so the model can finish its answer.
Define the tools
Tools ride in the chat request as a tools array. Each tool is a function with a name, a description, and a JSON Schema for its parameters — the same shape as the OpenAI format. This example is the one documented in the cURL reference:
curl https://api.nrouter.ai/v1/chat/completions \
-H "Authorization: Bearer $NROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{"role": "user", "content": "What is the weather in Tokyo?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name, e.g. Tokyo, Japan"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
],
"tool_choice": "auto"
}'The Python SDK takes the same definitions as typed JSON Schema tools — see Python SDK, which also links a complete tool-calling demo.
Control when tools are used
tool_choice decides how freely the model may call. On Chat Completions the documented value is "auto" — the model chooses. The other endpoints spell the control out in their references:
| Endpoint | tool_choice values |
|---|---|
| Responses | auto, required, none, or a specific function |
| Messages | auto, any, or a named tool |
The loop
- Send the request with your
tools. - The model replies with a tool call: the function name and the arguments, shaped by your schema.
- Your code runs the function — the gateway never executes your tools.
- Send the result back as the next message, and the model answers using it.
Agent-style loops that chain many calls are what the Responses endpoint is built for: multi-step tool execution and multi-turn state are its documented purpose.
Related guides
- Get Structured Output — The same JSON Schema discipline, applied to the answer itself
- Use Reasoning Models — Models that think through multi-step problems before answering
- Send Image Input — Add images to the messages a model reads