Browse documentation

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 enables models to request client-side function execution by emitting schema-conforming JSON arguments during multi-turn conversation loops across OpenAI and Anthropic wire formats.

Execution & Schemas

Define tools as JSON Schema and control invocation via tool_choice ("auto", "required", or "none" on OpenAI routes; {"type": "auto"} or {"type": "any"} on /v1/messages):

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": "Weather in Tokyo?"}],
    "tools": [{"type": "function", "function": {"name": "get_weather", "parameters": {"type": "object", "properties": {"location": {"type": "string"}}, "required": ["location"]}}}],
    "tool_choice": "auto"
  }'

See cURL reference and Python SDK. The model returns arguments and your client runs the code locally before returning results to Chat Completions, Responses, or Messages. Related guides: Structured Output, Reasoning Models, and Image Input.

Frequently asked questions

Does tool calling work with nrouter/auto?

Yes; multi-turn requests with tools mark the call as heavy for nrouter/auto routing. See Chat Completions.

Who runs the function when the model calls a tool?

Your application; the gateway returns parsed arguments and your client runs the function locally.

What does an invalid tool definition return?

An HTTP 400 error; ensure parameter schemas adhere to standard JSON Schema specifications.

Was this page helpful?