Skip to main content

Function & Tool Calling

GoRoute AI Gateway standardizes OpenAI-format tool calling across all supported providers. It automatically translates tool definitions and execution arguments between OpenAI, Anthropic Claude, and Google Gemini, while seamlessly integrating with the Model Context Protocol (MCP).


Tool Definition Schema​

Pass tool definitions in the tools array using standard JSON Schema definitions:

{
"model": "fast",
"messages": [
{"role": "user", "content": "What is the stock price of AAPL and MSFT?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_stock_quote",
"description": "Returns current real-time stock price and trading volume.",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"ticker": {
"type": "string",
"description": "Stock ticker symbol (e.g. AAPL, MSFT)"
},
"currency": {
"type": "string",
"enum": ["USD", "EUR", "GBP"],
"description": "Currency for quotation"
}
},
"required": ["ticker", "currency"],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto"
}

Strict Parameter Schemas (strict: true)​

When strict: true is configured:

  1. Schema Constraints: The schema must explicitly define "additionalProperties": false and include every property in the "required" array.
  2. Deterministic Output: Downstream providers that support Structured Outputs (OpenAI, Gemini) enforce a constrained decoding grammar, guaranteeing 100% schema conformance.
  3. Gateway Pre-Flight Check: GoRoute inspects tool parameter schemas during pre-flight admission, returning an immediate 400 Bad Request if schema syntax is invalid.

Model Context Protocol (MCP) Alignment​

GoRoute natively aligns HTTP tool definitions with the Model Context Protocol:

  • Namespace Prefixing: Tools registered on connected MCP servers can be invoked directly over standard HTTP chat completions by referencing the tool name or using the scoped format:
    mcp__<server_slug>__<tool_name>
  • Autonomous Execution: If a tool call matches a registered server-side MCP tool, the gateway's Autonomous Tool Loop can intercept and execute it server-side, eliminating client roundtrips.
  • Bi-Directional Translation: MCP tool schemas (inputSchema) map cleanly into OpenAPI parameters without manual bridging.

Cross-Provider Translation Matrix​

Gateway Schema (OpenAI Format)Anthropic Claude Wire FormatGoogle Gemini Wire Format
type: "function"Inferred functionfunctionDeclarations
function.parametersinput_schemaparameters
tool_calls[].idtool_use.idInferred function call call ID
role: "tool"role: "user" with type: "tool_result"role: "user" with functionResponse

[!NOTE] When models emit parallel tool calls, GoRoute automatically consolidates consecutive role: "tool" turns into a single alternating turn when routing to Anthropic or Gemini.


Code Examples​

curl -X POST http://localhost:8080/v1/chat/completions \
-H "Authorization: Bearer sk-gw-prod-7f9a2b8c4d1e" \
-H "Content-Type: application/json" \
-d '{
"model": "fast",
"messages": [
{"role": "user", "content": "What is the weather in Tokyo?"}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather for a given city",
"strict": true,
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["city", "unit"],
"additionalProperties": false
}
}
}
],
"tool_choice": "auto"
}'