← Back to articles
Unified API Calling

Unified Function/Tool Calling

⚠️ Pending Update · 2026-08-29 Verification · Content may be outdated, please refer to official docs Updated: 2026-08-29 · Status: Pending Verification

Background

OpenAI uses tools + tool_calls + function as three layers; Anthropic uses tools + tool_use block + tool_result pairing; Gemini uses function_declarations + functionCall + functionResponse. For the same agent code to run across models, the gateway must translate all three into one shape.

Unified Abstraction

  • Input normalization: the client sends tools in OpenAI shape; the gateway translates to each vendor's native format.
  • Output normalization: Anthropic's tool_use block and Gemini's functionCall both become OpenAI's tool_calls array.
  • Multi-turn normalization: regardless of vendor, the second-turn tool role message is translated into the corresponding vendor's "tool result" format (Anthropic tool_result, Gemini functionResponse).
  • Degradation for tool-less models: models like llama-3.1-8b that lack native tools can be "simulated" by the gateway via prompt injection + JSON parsing, at the cost of lower accuracy.

Code Example

def openai_tools_to_anthropic(tools):
    return [{
        "name": t["function"]["name"],
        "description": t["function"]["description"],
        "input_schema": t["function"]["parameters"],
    } for t in tools]

def anthropic_response_to_openai(resp):
    tool_calls = []
    for i, block in enumerate(resp["content"]):
        if block["type"] == "tool_use":
            tool_calls.append({
                "id": block["id"],
                "type": "function",
                "function": {
                    "name": block["name"],
                    "arguments": json.dumps(block["input"]),
                },
            })
    return {
        "role": "assistant",
        "content": None,
        "tool_calls": tool_calls,
    }

def openai_tool_result_to_anthropic(tool_call_id, output):
    return {
        "role": "user",
        "content": [{"type": "tool_result",
                     "tool_use_id": tool_call_id,
                     "content": output}],
    }

Schema Evolution and Versioning

The tools protocol evolves: a tool's parameters shift from {"url": string} to {"url": string, "method": string}. The client SDK upgrades, but the model may still describe the old schema. The gateway needs schema version negotiation: each tool carries a schema_version, and when the gateway sees the client-declared version in the request, it auto-selects the matching schema to inject into the tools field. It also maintains a version compatibility table so old-version tool calls still execute under the new schema by filling new fields with defaults.

Best Practices

  • Schema validation: validate tools definitions at the gateway ingress with JSON Schema so bad schemas never waste an upstream call.
  • Parallel tool calls: both OpenAI and Anthropic support parallel calls, but Gemini allows only one at a time — the gateway must cap to the strictest semantics.
  • Error pass-through: when a tool execution fails, return {"error": "..."} to the model rather than raising; the model then gets a chance to retry or pick another tool.
  • Fallback prompt template: for models without tools support, serialize the tool list into the system message and parse the model's reply as JSON.
  • Tool blocklist: maintain a per-client_id disabled-tool list to block dangerous tools (e.g. file deletion).

Unifying the tools protocol lets an agent framework be written once and run across every model.

🚀 Get Started: One-Click Free API Access

Want to call all the free models above with a single API key, no need to sign up for each provider? Apishare.cc provides a unified API Key — one key, 100+ models, free models at zero cost.

👉 Register on Apishare.cc → Get your unified API Key

📊 Want to see more free model rankings? Check out the Sep 2026 Free LLM API Rankings →


Get Started: APIShare Free API Directory


About the Free API Aggregator

The models covered in this guide are all served through the APIShare free API aggregator, which gives you one key for the whole catalog.

More in this category

Cherry Studio Complete Guide: 300+ Models in One Desktop App — Local KB + MCP, Zero-Cost Unified CallingLobe Chat Complete Guide: Pluginized Web Unified Calling — Team KB & Visual Workflow, No-CodeOpen WebUI Complete Guide: Local Ollama + Cloud Free APIs in One Pool — Privacy-First Unified CallingPortkey AI Gateway Complete Guide: Enterprise Unified Calling for 250+ Models — Cache + Guardrails + ObservabilityLiteLLM Proxy Complete Guide: Python Unified Gateway for 100+ Models — OpenAI Compatible + Smart Routing

Ready to use free LLM APIs?

APIShare aggregates free AI APIs worldwide — sign up and get bonus credits.