induwara.lk
induwara.lkDeveloper · AI

Gemini to Anthropic API Converter

Paste a Google Gemini generateContent request or response and get the equivalent Anthropic Messages JSON — systemInstruction, functionCall, finishReason and usageMetadatamapped field by field into Claude's system / messages / content-block shape. Runs entirely in your browser: no key, no upload, no signup.

By Induwara AshinsanaUpdated Jul 12, 2026
Convert a Gemini requestto Anthropic Messages
Payload type

Paste a Gemini request body. It is parsed in your browser — nothing is uploaded.

Written to the Anthropic model field. Confirm the tier fits your use case.

Used only when Gemini maxOutputTokens is absent — Anthropic requires max_tokens.

Output format
Messages
3
Fields mapped
6
Tool blocks
1
Notes / warnings
0
Converted Anthropic Messages request
{
  "model": "claude-sonnet-4-6",
  "system": "You are terse.",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Weather in Colombo?"
        }
      ]
    },
    {
      "role": "assistant",
      "content": [
        {
          "type": "tool_use",
          "id": "toolu_0",
          "name": "get_weather",
          "input": {
            "city": "Colombo"
          }
        }
      ]
    },
    {
      "role": "user",
      "content": [
        {
          "type": "tool_result",
          "tool_use_id": "toolu_0",
          "content": "{\"tempC\":31}"
        }
      ]
    }
  ],
  "max_tokens": 1024,
  "top_k": 40,
  "tools": [
    {
      "name": "get_weather",
      "description": "Get weather",
      "input_schema": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string"
          }
        },
        "required": [
          "city"
        ]
      }
    }
  ]
}

Field-by-field mapping

GeminiAnthropicStatusDetail
model: claude-sonnet-4-6MappedYou pick the target Claude model; Gemini requests have no model in the body.
systemInstructionsystem (top-level string)HoistedJoined part text into Anthropic's top-level system field (not a message).
contentsmessagesRenamedrole:"model" → "assistant"; each part → a content block (text / image / tool_use / tool_result).
tools[].functionDeclarations[]tools[]Renamedparameters → input_schema; name + description kept at the tool top level.
generationConfig.maxOutputTokens: 1024max_tokens: 1024RenamedCarried over — Anthropic requires max_tokens on every request.
generationConfig.topK: 40top_k: 40Renamed1:1 — Anthropic supports top_k sampling.

Mapping follows the official Google Gemini generateContent and Anthropic Messages references — sources are listed below the tool. The converted request targets https://api.anthropic.com/v1/messages (header anthropic-version: 2023-06-01).

How it works

The converter is a deterministic transformation of a published schema — there is no model call. It reads your Gemini generateContent payload, applies a fixed set of rules transcribed from the official Google and Anthropic API references, and emits the equivalent Anthropic Messages JSON. Every rule is a static mapping, so the same input always produces the same output, and three worked examples are reconciled field-by-field on every load.

Requests are rebuilt turn by turn:

  1. System prompt. The top-level systemInstruction.parts[].text is hoisted into Anthropic's top-level system string. Unlike OpenAI, Claude keeps the system prompt outside the messages array.
  2. contents → messages. Order is preserved. role:"model" becomes assistant; user stays user. Every message's content is an array of blocks: a text part becomes {type:"text"} and an inlineData part becomes {type:"image",source:{type:"base64"}}.
  3. functionCall → tool_use. A model functionCall{name,args} becomes an assistant {type:"tool_use",id,name,input} block. The args object stays a JSON object in input — Claude does not stringify arguments. Gemini calls carry no id, so a stable toolu_0, toolu_1… is synthesized in order.
  4. functionResponse → tool_result. A user-turn functionResponse{name,response} becomes a {type:"tool_result",tool_use_id,content} block inside a user message, linked back to the matching synthesized tool_use id.
  5. tools & toolConfig. tools[].functionDeclarations[] becomes tools[] with parameters moved to input_schema (upper-case Type enums like STRING are lower-cased to JSON Schema). functionCallingConfig.mode: AUTO→{type:"auto"}, ANY→{type:"any"} (or {type:"tool",name} for one allowed function), NONE→{type:"none"}.
  6. generationConfig. maxOutputTokens max_tokens (injected from the fallback box when absent, because Anthropic requires it), temperaturetemperature(clamped to 1.0, Anthropic's maximum), topPtop_p, topKtop_k (1:1 — Claude supports top-k, unlike OpenAI), and stopSequencesstop_sequences.

Responses wrap candidates[0] into a Messages object: {type:"message",role:"assistant",content,stop_reason,stop_sequence,usage}. Part text becomes {type:"text"} blocks, functionCall parts become tool_use blocks, and finishReason maps to stop_reason (STOP→end_turn, MAX_TOKENS→max_tokens; forced tool_use when a tool_use block is present; SAFETY/RECITATION→end_turn, flagged). usageMetadata maps to usage promptTokenCount→input_tokens, candidatesTokenCount→output_tokens. Fields with no clean target — totalTokenCount, responseSchema, safetySettings, extra candidates, cachedContent — are listed in the notes panel, never silently dropped.

Worked examples

1 — request with a tool call and tool response

  1. In: systemInstruction {"parts":[{"text":"You are terse."}]},
  2. contents: user "Weather in Colombo?",
  3. model functionCall get_weather{"city":"Colombo"},
  4. user functionResponse get_weather{"tempC":31},
  5. tools: get_weather, generationConfig {"maxOutputTokens":1024,"topK":40}
  6. Out: model "claude-sonnet-4-6", system "You are terse.",
  7. max_tokens 1024, top_k 40,
  8. messages:[{"role":"user","content":[{"type":"text","text":"Weather in Colombo?"}]},
  9. {"role":"assistant","content":[{"type":"tool_use","id":"toolu_0",
  10. "name":"get_weather","input":{"city":"Colombo"}}]},
  11. {"role":"user","content":[{"type":"tool_result","tool_use_id":"toolu_0",
  12. "content":"{\"tempC\":31}"}]}]
  13. tools:[{"name":"get_weather","input_schema":{...}}]
  14. Check: input stays an OBJECT (not stringified); toolu_0 links result to call.

2 — response mapping (MAX_TOKENS → max_tokens)

  1. In: candidates:[{"content":{"role":"model",
  2. "parts":[{"text":"It is 31°C in Colombo."}]},
  3. "finishReason":"MAX_TOKENS","index":0}],
  4. usageMetadata {"promptTokenCount":18,"candidatesTokenCount":9,
  5. "totalTokenCount":27}, modelVersion "gemini-2.5-flash"
  6. Out: {"type":"message","role":"assistant","model":"gemini-2.5-flash",
  7. "content":[{"type":"text","text":"It is 31°C in Colombo."}],
  8. "stop_reason":"max_tokens","stop_sequence":null,
  9. "usage":{"input_tokens":18,"output_tokens":9}}
  10. Check: MAX_TOKENS → max_tokens; totalTokenCount 27 surfaced as a note
  11. (Anthropic has no total_tokens field); modelVersion → model.

3 — edge cases (handled deliberately, no crash)

  1. Non-object input (array / "hi" / null) → a friendly, specific error, no output.
  2. maxOutputTokens absent → max_tokens injected from the fallback box (flagged Required-now).
  3. temperature 1.5 → clamped to 1.0 (Anthropic max), flagged Range-changed.
  4. functionResponse with no preceding functionCall → a fresh toolu_N id + a flag.
  5. Uppercase parameter Type enums (STRING, OBJECT) → lower-cased JSON Schema + a flag.
  6. candidateCount 3 → only candidates[0] converts; the extra 2 are flagged, not dropped silently.

Frequently asked questions

Sources & references

The mapping rules were last cross-checked against the official Gemini and Anthropic references on 2026-07-12. This page is reviewed whenever either provider ships a breaking request- or response-schema change.

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a field that maps wrong, or want another provider pair added?

Email me at [email protected] — most fixes ship within 24 hours.