Skip to main content
Tool calling (also called function calling) lets an AI model request that your application execute a specific function and return the result. The model decides when to use a tool, what arguments to pass, and how to incorporate the result into its final response.
Routeway supports the OpenAI tool calling format. Any code that works with OpenAI function calling works with Routeway unchanged — just swap the base_url.

How It Works

  1. Define your tools in the request as JSON schemas.
  2. The model returns a tool_calls array when it wants to call a function.
  3. Your app executes the function and sends back a role: "tool" message.
  4. The model generates its final answer using the result.

Basic Example


Controlling Tool Use

Use tool_choice to control how the model selects tools.

Parallel Tool Calls

Models may request multiple tools simultaneously. Iterate over message.tool_calls, execute each in parallel, and send all results back before requesting the final answer.
Send all role: "tool" messages in the same follow-up request. The model needs all results together to compose its final answer.

Designing Good Tool Schemas

Tool names should clearly describe the action. The model uses the name and description to decide when to call the tool.
Descriptions directly influence the model’s decision to call a tool. Be specific about what the tool does and when to use it.
Avoid free-form string fields when enums or typed fields work. Tight schemas reduce parsing errors and improve reliability.
Return JSON objects from your functions instead of plain strings. The model can reason over structured data more reliably.

Common Mistakes

Don’t expose tools with dangerous side effects without application-level guards. The model can call tools in unexpected sequences. Always validate arguments before executing writes, deletions, or external API calls.
  • Forgetting to replay the assistant message — the messages array must include the assistant turn containing tool_calls before any role: "tool" messages.
  • Parsing arguments before the stream ends — when streaming, accumulate delta.tool_calls fragments before calling JSON.parse.
  • Assuming a final text response always follows — on the first turn, the model may return only tool calls with no content. Handle both cases.