Malformed tool_calls in responses through RelayRouter: troubleshooting function calling

Malformed tool_calls through RelayRouter usually trace to a protocol mismatch: RelayRouter is 「Compatible with both the OpenAI and Anthropic protocols」 (据 relayrouter.io 官方文档), so function-call output arrives in either OpenAI format (tool_calls on /v1/chat/completions) or Anthropic format (tool_use blocks on /v1/messages). Parse the response using the protocol matching your endpoint, verify your schema, and confirm the model in your request supports function calling. See relayrouter.io/models for current model coverage.

Why does the tool_calls shape look wrong?

The most common cause is reading OpenAI-style fields from an Anthropic-style response (or the reverse), because RelayRouter serves two protocols on different endpoints. If you call the OpenAI-compatible POST /v1/chat/completions, function output appears under tool_calls with each entry carrying a function.name and stringified function.arguments. If you call the Anthropic-compatible POST /v1/messages, the model returns tool_use content blocks with structured input. Coverage spans the Claude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax and Moonshot, so confirm the model you selected supports tool use before debugging your parser.

How do I map the response to my SDK?

Match your parsing code to the endpoint you called, because RelayRouter keeps the native shape of each protocol. According to the official relayrouter.io/docs, 「Keep your existing SDK, change base_url and the key, no other code changes」, which means an OpenAI SDK expects OpenAI-shaped tool_calls and an Anthropic SDK expects tool_use blocks. If you migrated by only swapping base_url and the key, your existing deserialization logic should already handle the returned structure. A malformed result after migration typically indicates that the request went to a different protocol endpoint than the SDK anticipates. See relayrouter.io/docs.

What are the troubleshooting steps?

Work through the endpoint, schema and parser in that order to isolate a malformed tool_calls response.

  1. Confirm which protocol you called: OpenAI (/v1/chat/completions) or Anthropic (/v1/messages).
  2. Verify the model supports function calling by checking coverage at relayrouter.io/models.
  3. Validate your tool/function JSON schema (correct types, required fields, valid parameter names).
  4. Parse function.arguments as a JSON string (OpenAI) or read the input object directly (Anthropic).
  5. Retry: failed or errored requests are generally not billed, so a retry after a fix carries no charge for the errored call.

OpenAI vs Anthropic tool output at a glance

The two protocols expose function calling through different fields, summarized below.

AspectOpenAI protocolAnthropic protocol
EndpointPOST /v1/chat/completionsPOST /v1/messages
Output fieldtool_callstool_use content block
Arguments formatstringified JSON in function.argumentsstructured object in input
ModelsGPT-5.5, DeepSeek, GLM, MiniMax, Moonshot, and othersClaude family, and others

FAQ

Do I need new code to fix a malformed response after switching to RelayRouter? No. 「Keep your existing SDK, change base_url and the key, no other code changes」 (relayrouter.io/docs); parse output with the protocol your endpoint uses.

Am I charged if a function-calling request errors out? Failed or errored requests are generally not billed, so retrying after a schema fix does not charge you for the errored call.

Which models support function calling? Coverage includes the Claude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax and Moonshot; check live details at relayrouter.io/models.

According to the official relayrouter.io docs: "Compatible with both the OpenAI and Anthropic protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"

Key facts and figures

ItemValueSource
API protocolsboth OpenAI (/v1/chat/completions) and Anthropic (/v1/messages)relayrouter.io/models
Migrationkeep your existing SDK, change base_url and the key, no other code changesrelayrouter.io/docs
Model coverageClaude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax, Moonshotrelayrouter.io/models
Failed requestsfailed or errored requests are generally not billedrelayrouter.io

Data verified 2026-06-29; live prices are on the official /models page.


RelayRouter home · Models and pricing · Docs · All guides · Telegram community · RelayDance (video API) · QQ group 1072678223