Skip to main content

Tool Calling Across Providers

Advanced
What you'll learn
  • Read the same tool definition in all four wire dialects — Anthropic, OpenAI Chat Completions, OpenAI Responses, and Gemini — and translate between them without guessing field names
  • Avoid the single most common porting bug: arguments arrive as a JSON string on some providers and as a parsed object on others
  • Know which provider gives you no correlation ID at all, and what to do about it
  • Understand why forcing a tool call is portable everywhere EXCEPT Claude's newest models — the opposite of what most people assume
  • Tell the three schema dialects apart: raw JSON Schema, OpenAI's strict-mode subset, and Gemini's OpenAPI subset with its own rejection limits
  • Design a provider adapter that isolates the five things that actually differ, instead of rewriting your agent loop per vendor

Tool calling is the most portable idea in agent engineering and the least portable code. The concept is identical everywhere: you describe some functions with a JSON schema, the model replies asking for one, you run it, you hand back the result, the loop continues. Four providers, one concept — and not one field name in common across the round trip.

This page is the translation layer. If you want the Anthropic shape in depth — the three message-shape rules that return a 400, strict: true, server tools — that's Tool Use / Function Calling. Here we only care about what changes when you move.

The same tool, four dialects​

One tool, get_weather, written four ways. Read the three rows that differ, not the ones that match.

Anthropic MessagesOpenAI Chat CompletionsOpenAI ResponsesGemini (classic)
Where tools gotools: [...]tools: [...]tools: [...]tools: [{functionDeclarations: [...]}]
Definition shapeflat: name, description, input_schemanested: {type: "function", function: {...}}flat: {type: "function", name, ...}flat, inside functionDeclarations
Schema keyinput_schemaparametersparametersparameters
Model's requesttool_use content blocktool_calls[] on the messagefunction_call itemfunctionCall part
Arguments fieldinput — an objectfunction.arguments — a stringarguments — a stringargs — an object
Correlation IDididcall_idid
Your replytool_result blockmessage with role: "tool"function_call_output itemfunctionResponse part
ID field on the replytool_use_idtool_call_idcall_idid
Result payloadcontent (string or typed blocks)content (string)output (string)response (structured object)
Error signallingis_error: true on the resultno dedicated fieldno dedicated fieldno dedicated field

Mistral follows the OpenAI Chat Completions column exactly — nested function object, tool_calls with id, and a role: "tool" reply carrying name, content, and tool_call_id.

The three rows that cost people a day

input_schema vs parameters, input vs arguments, and tool_use_id vs tool_call_id vs call_id vs id. Everything else in that table is cosmetic. These three are where a port silently produces a loop that never terminates.

The arguments-is-a-string bug​

This is the single most common cross-provider defect, and it does not announce itself with a type error.

Guided walkthrough1 of 5
  1. Anthropic's tool_use block carries input as a JSON object. Gemini's functionCall part carries args as an object. You read the fields directly and move on.

A normalizer that collapses all four dialects into one internal shape

// One adapter, four dialects. Every tool handler downstream sees {id, name, args}.
function normalizeToolCalls(providerResponse, provider) {
switch (provider) {
  case "anthropic":
    // stop_reason === "tool_use"; arguments are ALREADY an object
    return providerResponse.content
      .filter((b) => b.type === "tool_use")
      .map((b) => ({ id: b.id, name: b.name, args: b.input }));

  case "openai-chat":
  case "mistral": {
    const calls = providerResponse.choices[0].message.tool_calls ?? [];
    // .arguments is a STRING — parse it exactly here and nowhere else
    return calls.map((c) => ({
      id: c.id,
      name: c.function.name,
      args: parseOrError(c.function.arguments),
    }));
  }

  case "openai-responses":
    return providerResponse.output
      .filter((i) => i.type === "function_call")
      .map((i) => ({
        id: i.call_id,                      // note: call_id, not id
        name: i.name,
        args: parseOrError(i.arguments),    // also a STRING
      }));

  case "gemini": {
    const parts = providerResponse.candidates[0].content.parts ?? [];
    return parts
      .filter((p) => p.functionCall)
      // Gemini echoes an id you must send back on the functionResponse
      .map((p) => ({ id: p.functionCall.id, name: p.functionCall.name, args: p.functionCall.args }));
  }
}
}

function parseOrError(s) {
try { return JSON.parse(s); } catch { return { __parseError: s }; }
}

Ollama has no correlation ID​

Worth its own heading, because it breaks an assumption your adapter almost certainly encodes. Ollama's /api/chat accepts the OpenAI-style tools field and returns tool_calls whose entries carry a function with name and arguments — but the documented tool-result message has no tool_call_id field. Correlation is by position and tool name rather than by an ID.

That matters the moment a model asks for two tools at once: with no ID to match on, you cannot hand results back out of order, and two calls to the same tool with different arguments are distinguishable only by their position in the array. If you run the same agent against both a hosted provider and a local Ollama model — a common cost-saving setup described in Claude plus local models — make your adapter synthesize an index-based ID locally and preserve array order strictly. Ollama also exposes an OpenAI-compatible /v1 endpoint, which is the easier target if your client is already written against the OpenAI shape.

Forcing a tool: the portability trap nobody expects​

Every provider has a knob for "you must call a tool." They mostly agree — and then Claude's newest models break the pattern, which is the reverse of the usual story where Anthropic is the portable baseline.

ProviderValuesForce-a-specific-tool
Anthropicauto (default with tools), any, tool, none{"type": "tool", "name": "..."}
OpenAI"auto" (default), "required", "none"{"type": "function", "name": "..."}, or allowed_tools
Gemini (classic)VALIDATED, AUTO, ANY, NONEANY plus allowed_function_names
Mistralauto (default), any, none—
Watch out
  • On Claude Fable 5.2 and 5.1, Mythos 5.2 and 5.1, Opus 5.5 and Sonnet 5.5, tool_choice values any and tool return a 400 error. The portable-looking line in your adapter is the one that fails, and only on the newest models — which is also where you most want to run.
  • Anthropic's guidance is to use auto together with strict tool use instead. none still works everywhere.

Two more asymmetries in that table are easy to miss:

  • Gemini's VALIDATED is a mode the others don't have. It becomes the default when built-in tools or structured outputs are also enabled, and it constrains output to a function call or text with schema adherence — a middle setting between "decide freely" and "you must call something."
  • Gemini's ANY mode has a schema complexity ceiling. The docs are explicit that in ANY mode very large or deeply nested schemas may be rejected, because the schema is compiled into a state machine with limits on states, branching, and nesting; exceeding them yields a 400 INVALID_ARGUMENT. A schema that is merely verbose on other providers can be invalid here.

For the deeper story on why forced tool use is being retired on Claude — and the two unrelated jobs it was doing — see Tool Use / Function Calling.

Three schema dialects, not one​

Everyone says "JSON Schema." Only some of them mean it.

Guided walkthrough1 of 4
  1. You pass an ordinary JSON Schema object and the model treats it as guidance. Unsupported keywords tend to be ignored rather than rejected, which is forgiving at request time and unhelpful at debug time: a constraint the provider silently dropped looks identical to a model that ignored it.

Anthropic's own strict: true is covered in Tool Use, and the schema-constrained response path (as opposed to a tool call) in Structured Output.

What the result may contain​

Asymmetric in a way that matters for multimodal agents:

  • Anthropic — tool_result.content takes a plain string or an array of typed content blocks: text, image, document, search_result. A tool can hand back a screenshot and Claude will look at it.
  • Gemini — functionResponse.response is a structured object by design, not a bare string.
  • OpenAI — the Chat Completions tool message content and the Responses API function_call_output.output are documented as string fields, so you JSON-encode structured data yourself.

The portable lowest common denominator is therefore "a JSON string," and the cost of adopting it is giving up Anthropic's ability to return an image from a tool. If your agent screenshots, scrapes, or renders, that's not a small loss — keep it as a provider-specific capability behind a feature flag rather than flattening it away.

Open weights: the parser is part of the deployment​

Running an open-weight model doesn't inherit tool calling for free. The wire shape is OpenAI-compatible, but the extraction of a tool call from the model's raw text is a server-side concern you have to configure.

  • vLLM serves the OpenAI-compatible tools/tool_calls shape on /v1/chat/completions, but requires --enable-auto-tool-choice plus a --tool-call-parser naming a model-specific parser (the shipped set includes llama3_json, mistral, hermes, granite, jamba, deepseek_v3, pythonic and more, and custom parsers can be registered with --tool-parser-plugin).
  • Without a loaded parser, a request with a named tool_choice returns HTTP 400. The first use of a named choice also pays a one-off state-machine compile latency.
  • The honest caveat is in vLLM's own docs: for some Mistral-format models, a call is not guaranteed even when tool choice is forced. Any contract your agent builds on "forced means forced" needs a fallback path here.

Serving an open-weight model with working tool calls (vLLM)

# The two flags are not optional: without them a named tool_choice returns 400.
vllm serve <model-id> \
--enable-auto-tool-choice \
--tool-call-parser hermes          # must match the model's tool-call format

# Then point any OpenAI-shaped client at it:
#   base_url = "http://localhost:8000/v1"
# Your adapter's "openai-chat" branch works unchanged — but keep a fallback
# for the documented case where a forced call does not arrive.

See Run models locally with Ollama and Local coding agents for the surrounding setup.

Google moved the docs — and the API​

Timely enough to call out on its own, because it changes which shape you should be writing against. Google's function-calling documentation migrated: the page at ai.google.dev now serves a new Interactions API by default and redirects to AI Studio, while the classic Generate Content shape — functionDeclarations, functionCall, functionResponse, tool_config.function_calling_config.mode — is explicitly labeled "Legacy."

The new Interactions API uses a flat tool shape closer to OpenAI's: {type: "function", name, description, parameters}, with the model's request arriving as a FunctionCallStep carrying name and arguments, and the mode set through tool_choice inside generation_config using auto, any, and none, plus allowed_tools to restrict which tools may be called.

The strategic read: the industry is converging on OpenAI's flat shape, and Google just moved toward it. That doesn't make the problem go away — the argument-encoding split and the ID-field split survive the convergence — but it does mean a new integration written today should target the flat shape, and that the classic Gemini column in the table above is now maintenance work rather than new work.

The portability checklist​

Guided walkthrough1 of 7
  1. Two functions: one that renders your internal tool list into the provider's definition shape, and one that normalizes the provider's response into {id, name, args}. If provider names appear anywhere else in your codebase, you will port twice.
Field names worth memorizing
Press Enter or Space to flip the card. Use the left and right arrow keys to move between cards.Term shown.
1 / 9

Check yourself

0/4
  1. Your agent works on Claude and you port it to OpenAI. Tools now run but receive empty fields, with no type errors anywhere. What is the first thing to check?
  2. You wrote one adapter and set tool_choice to force a specific tool, because that line looked identical across vendors. Where does it fail?
  3. You run the same agent against a hosted provider and a local Ollama model. The model asks for two tools in one turn and your results get attached to the wrong calls. Why?
  4. A schema that works fine on Anthropic is rejected with 400 INVALID_ARGUMENT by Gemini in ANY mode. What is the most likely cause?
Key takeaways
  • One concept, four dialects: the only rows that really differ are the schema key (input_schema vs parameters), the arguments field, and the correlation-ID name.
  • Arguments are a JSON string on OpenAI and Mistral, and a parsed object on Anthropic and Gemini — normalize exactly once, at the adapter boundary.
  • Ollama supplies no correlation ID; synthesize one and never reorder tool results.
  • Forcing a tool call is portable everywhere EXCEPT Claude's newest models, which return a 400 on any and tool — feature-detect it instead of assuming it.
  • Three schema dialects, so write for the narrowest: flat, shallow, explicit required, additionalProperties false, no exotic keywords.
  • Open weights need server-side configuration — vLLM wants --enable-auto-tool-choice plus a matching --tool-call-parser, and does not guarantee a forced call for every model format.
  • Google now labels the classic Gemini shape Legacy and its new API uses OpenAI's flat shape — target the flat shape for anything new.

Next​