Tool calling explained: OpenAI, Anthropic, Gemini, and MCP formats

Tool calling across OpenAI, Anthropic, and Gemini: the request loop, field-by-field format differences, tool_choice, parallel calls, MCP, and gateways.

Published
Reading time
12 min read
Level
Intermediate
By
AI for Devs
TL;DR
  • Tool calling is a four-step loop: you send tool schemas, the model returns a call, your code runs it, and you send the result back. The model never executes your function.
  • OpenAI returns arguments as a JSON string, while Anthropic and Gemini return an object, and each API matches results to calls with a different id field.
  • tool_choice and parallel-call controls differ by name and placement, and as of November 23, 2026, Claude Opus 5.5 and Sonnet 5.5 reject forced tool use with a 400 error.
  • MCP standardizes the tool side (tools/list, tools/call), not the model side, so a client still converts between MCP and each provider's tool calling format.
  • Bifrost, an open-source AI gateway, translates OpenAI-format tool calls for Anthropic and Gemini, but drops strict for both and parallel_tool_calls for Gemini.

Tool calling is the mechanism that lets a language model ask your code to run a function. You send the model a list of tool definitions, the model replies with a structured request naming a tool and its arguments, and your application runs it and sends the result back. OpenAI, Anthropic, and Google all implement this loop, and they disagree on field names, argument encoding, result placement, and the controls that force or limit calls. Those differences are what break an agent when it moves between providers.

This article lines up the three formats field by field from each provider's current docs, then covers tool_choice, parallel calls, where MCP fits, and how a gateway such as Bifrost, an open-source AI gateway, normalizes tool calls across providers. The loop control around these calls, such as turn limits and error handling, is covered in what is an AI agent.

#What is tool calling

Tool calling is a model returning a structured request to run a function you defined, instead of plain text. The request names the function and carries arguments that match a JSON Schema you supplied. Your code runs the function, and the next request carries the result so the model can answer or ask for another call.

Google's function calling guide states the boundary plainly: the model does not execute the function itself. It predicts which function to call and with which arguments. Every API follows the same four steps:

  1. You send the conversation plus a tools array. Each tool has a name, a description, and a JSON Schema for its parameters.
  2. The model returns one or more calls, each with an id, a tool name, and arguments.
  3. Your code validates the arguments and runs the function.
  4. You send the output back, tagged with the call's id, and call the model again.
The tool calling loop has four steps in every API. Only the names change: OpenAI sends arguments as a JSON string, Anthropic and Gemini send an object, and each API matches the result to the call by a different id field.model called again: another call, or a final answer1. Request with toolsmessages + JSON Schemas2. Model returns a callname, id, arguments3. Your code runs itthe model never does4. Result goes backmatched by the call idAPIStep 2: the call arrives asStep 4: the result is sent asOpenAI Responsesfunction_call item: call_id, arguments (string)function_call_output item: call_id, outputOpenAI Chatmessage.tool_calls[]: id, arguments (string)role: "tool" message: tool_call_idAnthropictool_use block: id, input (object)tool_result block in a user turn: tool_use_idGeminifunction_call step: id, arguments (object)function_result step: call_id, resultAnthropic results ride in a user turn because the Messages API has only user and assistant roles.
Fig. 1The four steps never change. Notice that only steps 2 and 4 carry provider-specific names, and that OpenAI is the one API that sends arguments as a string you must parse.

Two costs come with every tool. The description decides whether the model picks the tool at all: Anthropic's tool definition guide calls detailed descriptions "by far the most important factor in tool performance." And tool names, descriptions, and schemas are billed as input tokens on each request, so fifty verbose tools take room in the context window before the user has typed anything.

#OpenAI function calling format

OpenAI's Responses API defines a tool as a flat object with type: "function", a name, a description, a JSON Schema parameters object, and a strict flag. A call comes back as a function_call item in the response output, and you return the result as a function_call_output item with the same call_id.

OpenAI Responses API tool
JSON
{
  "type": "function",
  "name": "get_weather",
  "description": "Get the current weather for a city. Returns temperature in Celsius and a short condition.",
  "parameters": {
    "type": "object",
    "properties": { "city": { "type": "string" } },
    "required": ["city"],
    "additionalProperties": false
  },
  "strict": true
}

The arguments field of a function_call is a JSON-encoded string, so your code parses it before use. The Chat Completions reference warns that the model does not always generate valid JSON there, which is a reason to parse inside a try block and send a parse failure back as the tool result.

Strict mode is where the two OpenAI APIs differ most, as of November 23, 2026:

  • In the Responses API, an omitted strict makes the API try to normalize the schema into strict mode, and it falls back to non-strict when it cannot. Set strict: false to opt out.
  • In Chat Completions, requests stay non-strict by default.
  • A strict schema needs additionalProperties: false on every object and every property listed in required. An optional field becomes a nullable type such as ["string", "null"].

Chat Completions, which most OpenAI-compatible servers copy, nests the same data differently. The call arrives in message.tool_calls with an id and a function object holding name and string arguments, the turn ends with finish_reason: "tool_calls", and you reply with a role: "tool" message carrying tool_call_id.

#Anthropic tool use format

Anthropic calls the feature tool use, and its schema field is input_schema rather than parameters. When Claude calls a tool, the response has stop_reason: "tool_use" and one or more tool_use content blocks, each with an id, a name, and an input object that is already parsed JSON.

Anthropic tool_use block in the assistant turn
JSON
{
  "type": "tool_use",
  "id": "toolu_01A09q90qw90lq917835lq9",
  "name": "get_weather",
  "input": { "location": "San Francisco, CA" }
}

You send the output in the next user message as a tool_result block whose tool_use_id matches the call. Results travel inside a user turn because the Messages API has only user and assistant roles. A failed tool returns a tool_result with is_error: true and a short explanation, which the model reads as input for its next attempt.

Tool names must match ^[a-zA-Z0-9_-]{1,128}$, so a dotted name that is valid in MCP needs renaming before Claude sees it. A definition can also carry input_examples, an array of sample inputs that each cost about 100 to 200 input tokens, and strict: true for schema-valid inputs. Anthropic-hosted server tools, such as web search and code execution, run on Anthropic's side and need no handler in your code.

#Gemini function calling format

Google's current function calling docs use the Interactions API. A tool is a flat object with type: "function", a name, a description, and a parameters schema, close in shape to OpenAI's Responses API. A call returns as a function_call step with an id, the name, and arguments as an object, and you answer with a function_result step that references it through call_id.

The result field of a function_result is a list of content blocks, and Gemini 3 and later models accept image, document, audio, and video blocks there. Tool declarations are not stored with an interaction, so the guide says to resend the same tools array on every request, including requests that continue from previous_interaction_id.

Many production integrations still call generateContent, which uses different names again: tools go in functionDeclarations, a call arrives as a functionCall part with an args map, and the answer is a function response part. That is the format most gateways target for Gemini, including Bifrost's converter described below.

#Where the three formats differ

The differences that break portable code are small, specific, and easy to list. Seven fields account for most of them, and each one turns into an if provider == branch in an agent loop that talks to providers directly.

FieldOpenAI (Responses / Chat)Anthropic MessagesGemini (Interactions)
Schema keyparametersinput_schemaparameters
ArgumentsJSON string you parseinput objectarguments object
Call signalfunction_call item / finish_reason: "tool_calls"stop_reason: "tool_use"function_call step
Resultfunction_call_output / role: "tool"tool_result block in a user turnfunction_result step
Result id fieldcall_id / tool_call_idtool_use_idcall_id
Error flag on a resultNone, the text carries itis_error: trueNo field shown in the guide
Schema enforcementstrictstrictvalidated tool choice mode

Streaming multiplies the branches, because each provider streams partial tool arguments in its own event format. A unified layer, whether a library or a gateway, earns its place at this point. The sibling article on a unified AI API covers the broader case beyond tools.

#tool_choice and parallel tool calls across providers

All three APIs default to auto, where the model decides whether to call a tool. They differ on how to force a call, how to name one tool, and where the switch for parallel calls lives. One model-specific restriction matters more than the naming: some current Claude models refuse forced tool use outright.

ControlOpenAIAnthropicGemini
Model decides"auto" (default){"type": "auto"} (default)auto (default)
Must call a tool"required"{"type": "any"}any
One named tool{"type": "function", "name": "..."}{"type": "tool", "name": "..."}allowed_tools with mode any
No tools"none"{"type": "none"}none
Limit to a subsetallowed_toolsNot a tool_choice modeallowed_tools
Turn off parallel callsparallel_tool_calls: falsedisable_parallel_tool_use: true inside tool_choiceNo switch in the guide

As of November 23, 2026, Anthropic's define tools page lists Claude Opus 5.5, Sonnet 5.5, Fable 5.2, Mythos 5.2, Fable 5.1, and Mythos 5.1 as returning a 400 error for any and tool. Manual extended thinking also blocks both modes. The suggested replacement is auto plus strict tool use, or structured outputs when the goal is a fixed JSON shape. Code that forces a tool to extract data will fail on these models even though the same request works on OpenAI.

Parallel calls need care on the result side. Anthropic's parallel tool use page requires one tool_result per tool_use, all in the next user message, placed before any text. Splitting results across messages "teaches" Claude to stop calling tools in parallel. If an earlier call fails and you skip the rest, return a tool_result with is_error: true for each skipped call anyway.

OpenAI's guide adds one limit of its own: on GPT-5 and later models, built-in tools cannot be part of a parallel batch of function calls.

#How MCP standardizes tools

The Model Context Protocol standardizes the other side of tool calling: how a tool is described and invoked, regardless of which model asks for it. An MCP server answers tools/list with tool definitions and tools/call with results, so a tool written once works with every MCP client. The overview of MCP covers hosts, transports, and authorization.

MCP does not replace provider tool calling. The model still emits an OpenAI, Anthropic, or Gemini call, and the MCP client sits behind it. For each call, the client converts in both directions:

  • Definition, server to model. The MCP inputSchema becomes parameters for OpenAI and Gemini, or input_schema for Anthropic. The name and description copy across, and the client renames any tool whose name breaks a provider's rules.
  • Call, model to server. The model's arguments become the arguments object of tools/call, which means parsing OpenAI's string first.
  • Result, server to model. The MCP content array becomes the provider's result format, and isError: true maps to Anthropic's is_error or to plain text for the others.

The tools page of revision 2026-07-28 sets three rules that matter at this boundary. Tool names are unique only within one server, so a client that aggregates servers should prefix names with a server identifier. Servers should return tools in a deterministic order, which keeps the tool block stable for prompt caching. Input validation failures come back as tool execution errors with isError: true, which the client should pass to the model so it can correct its arguments.

The spec also says a human should always be able to deny a tool invocation, and that clients should confirm sensitive operations and log tool usage for audit. Building a server that asks for confirmation is the subject of build an MCP server.

#How a gateway normalizes tool calls across providers

An AI gateway normalizes tool calling by accepting one request format from your code, translating it into each provider's native format, and translating the response back. The agent loop is written once against one shape, and the provider changes with the model name.

Bifrost takes this approach for 10,000+ models across 25+ providers, with about 11 microseconds of overhead per request at 5,000 requests per second in the Bifrost team's published benchmarks. All providers return responses in an OpenAI-compatible format, and the tool calling quickstart sends OpenAI-style tool schemas to /v1/chat/completions with a provider-prefixed model such as anthropic/<model>.

The conversion guides document what changes underneath. The Anthropic guide maps function.parameters to input_schema, "required" to any, and parallel_tool_calls: false to disable_parallel_tool_use. It merges consecutive role: "tool" messages into one user message of tool_result blocks, which also satisfies Anthropic's parallel-result rule. The Gemini guide targets generateContent, mapping a named tool to ANY with allowedFunctionNames.

Bifrost maps each OpenAI tool field to the Anthropic and Gemini equivalents. Strict mode is dropped for both providers and parallel_tool_calls is dropped for Gemini. On the way back, both providers' argument objects become an OpenAI JSON string.Your code sends (OpenAI format)Anthropic receivesGemini receivesBifrostfunction.parametersinput_schemafunctionDeclarations.parameterstool_choice: "required"tool_choice: anymode: ANYtool_choice: one functiontype: tool, nameANY + allowedFunctionNamesparallel_tool_calls: falsedisable_parallel_tool_usedroppedfunction.strict: truedroppeddroppedconsecutive role: toolone user turn, tool_result blocksone user turn, function responsesOn the way backtool_calls[].arguments (string)tool_use input (object)functionCall args (map)mappeddropped, no errorwhat your code parses
Fig. 2Most fields map cleanly. The hatched cells are the ones to plan around: strict mode is dropped for both providers and parallel_tool_calls is dropped for Gemini, all without an error.

Translation has limits, and the guides state them. As of November 23, 2026, function.strict is silently dropped for Anthropic and Gemini, so schema enforcement that OpenAI would apply does not happen on those providers. parallel_tool_calls is ignored for Gemini. Validate arguments against the schema in your own code before you execute anything, whatever the provider.

A gateway also gives governance a single place to live. Bifrost applies governance and security controls, such as virtual keys, budgets, guardrails, and audit logs, to every model and tool call that passes through it. Bifrost Edge extends the same governance and security to AI traffic on employee machines, and enforces MCP server allow and deny decisions on each device, so a tool call from a desktop app follows the same rules as one from a service.

#Running MCP tools through Bifrost

Used as an MCP gateway, Bifrost connects to MCP servers over STDIO, HTTP, or SSE, discovers their tools, and adds them to inference requests for any provider it routes to. By default it does not execute the resulting tool calls. They come back to your application, which approves each one and sends it to an execute endpoint.

By default Bifrost adds the allowed MCP tools to the model request and returns the model's tool calls to your app unrun. Your app approves each call and sends it to the execute endpoint, which calls the MCP server. In Agent Mode, tools on the auto-execute list run inside the gateway instead.Agent Mode: auto-execute list runs in Bifrostin parallel, up to max_agent_depth (default 10)Chat request/v1/chat/completionsBifrost adds toolsclient ∩ header ∩ keyModelany providertool_calls returnedunrun, to your appYour app reviewsapprove or rejectExecute endpointPOST /v1/mcp/tool/executeMCP servertools/callrole: tool reply, then the next requestDefault path: solid. Agent Mode: dashed.
Fig. 3The default path keeps a person or a policy in your app between the model's call and the tool running. Agent Mode moves only the tools on its auto-execute list inside the gateway.

The tool execution flow has four steps. The chat response carries tool_calls with finish_reason: "tool_calls". Your code reviews them and posts each approved call, in the same shape as the tool call object, to POST /v1/mcp/tool/execute. The default response is a role: "tool" message with the matching tool_call_id, and ?format=responses returns a function_call_output item instead. Tool names carry the MCP client name as a prefix, such as filesystem_list_directory, so two servers with a search tool do not collide.

Agent Mode adds auto-execution for tools on a tools_to_auto_execute list, which must be a subset of tools_to_execute. Auto-executable tools run in parallel inside the gateway, up to max_agent_depth iterations (default 10), and any other tool calls return to your application for approval. A sensible split is read-only tools on the auto list and writes behind review.

Tool filtering decides which tools a model sees at all. The available set is the intersection of the client's tools_to_execute, the request's x-bf-mcp-include-tools header, and the virtual key's mcp_configs, and a header can narrow the key's allow-list but never widen it. When an agent needs hundreds of tools, Code Mode exposes four generic tools and has the model write Python that runs in a sandboxed Starlark interpreter. In the Bifrost team's test with 508 tools across 16 servers, input tokens fell 92.8 percent and all 65 tasks still passed.

The MCP gateway resource page covers the gateway side in more depth, and the MCP gateway comparison ranks the options.

#Choosing an approach for portable tool calling

Call a provider's API directly when the agent uses one provider and needs its newest tool features first, such as Anthropic's server tools or Gemini's multimodal function results. Every field is available, and every format quirk belongs to your code.

Put a gateway in front when the same agent routes across two or more providers, needs failover between them, or needs one place to govern which tools each team can call. Bifrost is the gateway to evaluate first for that case, because one self-hosted service handles the OpenAI-compatible translation, MCP tool execution, and per-key tool access. Check its conversion guide for each field the agent depends on before switching providers.

Whichever path you pick, these habits keep tool calling portable:

  1. Write tool descriptions of three or four sentences that say what the tool returns and when not to use it.
  2. Keep tool names short and limited to letters, digits, underscores, and hyphens, so they pass every provider's naming rules.
  3. Parse and validate arguments in your own code, even with strict mode on, since a gateway or provider may drop it.
  4. Return errors as tool results the model can read, and never skip a result for a call the model made.
  5. Do not rely on forced tool choice for extraction; use structured outputs where the model supports them.
  6. Keep the active tool set small, around 10 to 20 tools, and filter per request.
  7. Write shared tools as MCP servers, so any client, gateway, or agent loop can use them.

#Questions

What is the difference between tool calling and function calling?

They name the same feature. OpenAI and Google call it function calling, Anthropic calls it tool use, and tool calling has become the generic term. In each API the model returns a structured request to run a function you defined, with arguments that match a JSON Schema, and your code sends back the result. Tool calling also covers provider-hosted tools such as web search.

Does the LLM execute the tool itself?

No, not for tools you define. The model only predicts which function to call and with which arguments. Your application runs the function and returns the output in the next request. The exception is provider-hosted tools, such as Anthropic's server tools for web search and code execution, which run on the provider's infrastructure and return results without a handler in your code.

What does tool_choice do?

tool_choice controls whether the model may, must, or must not call a tool. All three APIs default to auto, where the model decides. OpenAI uses required to force at least one call, Anthropic and Gemini use any, and each has a form that forces one named tool. As of November 23, 2026, Claude Opus 5.5 and Sonnet 5.5 reject forced tool choice with a 400 error.

Can a model call several tools at once?

Yes. OpenAI, Anthropic, and Gemini can all return several independent tool calls in one response, and your code can run them concurrently. OpenAI turns this off with parallel_tool_calls set to false, and Anthropic with disable_parallel_tool_use inside tool_choice. Anthropic also requires every result to come back in a single user message, or the model learns to stop calling tools in parallel.

Is MCP the same as tool calling?

No. Tool calling is the model API feature that returns a structured call. MCP is a protocol for how tools are listed and invoked, through tools/list and tools/call, so a tool written once works with any MCP client. The model still emits a call in its provider's format, and an MCP client or gateway turns that call into a tools/call request.

Why does tool calling code break when switching from OpenAI to Claude?

The shapes differ. Claude expects input_schema instead of parameters, returns arguments as an input object instead of a JSON string, signals a call with stop_reason tool_use, and expects results as tool_result blocks inside a user message. An adapter in your own code fixes this, or a gateway that translates OpenAI-format requests into each provider's native format.

How many tools should you give a model?

Fewer than most teams start with. Google's Gemini guide recommends keeping the active set to 10 to 20 tools, because selection accuracy falls as the list grows, and every tool definition is billed as input tokens on each request. Filter tools per request, consolidate related operations into one tool, or use a code-execution pattern when an agent needs hundreds of tools.