Malformed tool_calls in responses through RelayRouter: troubleshooting function calling

Malformed tool_calls through RelayRouter are usually resolved by matching the request to the correct protocol: RelayRouter is compatible with both the OpenAI protocol (POST /v1/chat/completions) and the Anthropic protocol (POST /v1/messages), and function calling output follows the shape of whichever protocol you call. Send OpenAI style tool definitions to the OpenAI endpoint and Anthropic style tools to the Anthropic endpoint, keep your existing SDK, and confirm the base URL and key are set correctly.

Confirm you are using the matching protocol

The most common cause of malformed tool_calls is mixing protocols, so verify the endpoint matches your SDK. According to the official relayrouter.io docs, RelayRouter is 「Compatible with both the OpenAI and Anthropic protocols」, which means the OpenAI endpoint (/v1/chat/completions) returns tool_calls in OpenAI shape while the Anthropic endpoint (/v1/messages) returns tool_use blocks in Anthropic shape. If your parser expects OpenAI style objects but you called /v1/messages, the structure will not match. Check the base URL for each of the two protocols and confirm the request path corresponds to the SDK you selected. See relayrouter.io/models for supported protocols and the models that accept function calling.

Verify base_url and key after migration

Malformed output after switching gateways is frequently a configuration issue rather than a model issue. According to the official relayrouter.io/docs, you should 「Keep your existing SDK, change base_url and the key, no other code changes」, so if you edited tool schemas or added extra transforms during migration, revert them. The migration path requires only two edits: base_url and the API key. When those two values are correct and the rest of the code is unchanged, your existing tool_calls parsing continues to work. Review your changes against the guidance at relayrouter.io/docs and remove any non standard modifications introduced during the switch.

Check model support across the catalog

Malformed tool_calls can also appear when a model in the catalog handles function calling differently, so confirm the target model. RelayRouter covers the Claude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax and Moonshot, and function calling behavior depends on the model you route to. If tool_calls are malformed with one model, test the same request against another model in the catalog to isolate whether the problem is protocol related or model related. A useful data point during debugging: failed or errored requests are generally not billed, so repeated troubleshooting calls that error out do not accumulate charges. See relayrouter.io/models for the current per model list.

Step by step debugging checklist

Follow these numbered steps to isolate malformed tool_calls.

  1. Confirm which of the two protocols you are calling: OpenAI (/v1/chat/completions) or Anthropic (/v1/messages).
  2. Match your tool definitions and parser to that protocol shape.
  3. Verify base_url and the API key are the only edits made during migration.
  4. Test the request against a second model from the catalog (Claude family, GPT-5.5, Gemini 3.5, DeepSeek, GLM, MiniMax, Moonshot).
  5. Inspect the raw response body to compare returned structure against the expected protocol shape.
ProtocolEndpointFunction calling field
OpenAI compatible/v1/chat/completionstool_calls
Anthropic compatible/v1/messagestool_use

FAQ

Why are my tool_calls malformed after switching to RelayRouter? Usually because the request protocol and the parser do not match, or because more than base_url and the key were changed during migration. According to the official relayrouter.io/docs, you keep your existing SDK, change base_url and the key, with no other code changes.

Does RelayRouter support function calling on both protocols? Yes. RelayRouter is compatible with both the OpenAI protocol (/v1/chat/completions) and the Anthropic protocol (/v1/messages), and each returns function calling output in its own protocol shape.

Am I billed for failed troubleshooting requests? Failed or errored requests are generally not billed, so repeated debugging calls that error out do not add charges. Live per model rates are listed 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