induwara.lk
induwara.lkDeveloper · AI

Claude to Gemini API Request Converter

Paste an Anthropic (Claude) Messages request and get the equivalent Google Gemini generateContent request — endpoint, headers and body remapped field by field — as ready-to-run cURL, Python or Node/TS. Works both ways. Runs entirely in your browser: no key, no upload, no signup.

By Induwara AshinsanaUpdated Jul 12, 2026
Convert a Claude requestto Gemini
Direction

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

Output language
Gemini auth style
Endpoint
/v1beta/models/gemini-2.5-flash:generateContent
Fields mapped
5
Dropped / manual
0 / 0
Auth header
x-goog-api-key

Request headers (Gemini)

x-goog-api-key: $GEMINI_API_KEY
content-type: application/json
cURL — ready to run
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "systemInstruction": {
      "parts": [
        {
          "text": "You are a terse assistant."
        }
      ]
    },
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Capital of Sri Lanka?"
          }
        ]
      }
    ],
    "generationConfig": {
      "maxOutputTokens": 50,
      "temperature": 0.2
    }
  }'
Converted Gemini generateContent body
{
  "systemInstruction": {
    "parts": [
      {
        "text": "You are a terse assistant."
      }
    ]
  },
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Capital of Sri Lanka?"
        }
      ]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 50,
    "temperature": 0.2
  }
}

Field-by-field mapping

FromToStatusDetail
model: claude-haiku-4-5path: /models/gemini-2.5-flash:generateContentMappedSuggested tier: gemini-2.5-flash-lite — confirm before shipping. Gemini takes the model in the URL, not the body.
system (top-level)systemInstruction.parts[].textHoistedAnthropic's top-level system field is hoisted to Gemini's systemInstruction.
messages (user/assistant)contents (user/model)RenamedOrder preserved. assistant → model; each string content becomes parts:[{text}].
max_tokens: 50generationConfig.maxOutputTokens: 50RenamedRequired in Anthropic, optional in Gemini. Folded into maxOutputTokens.
temperature: 0.2generationConfig.temperature: 0.2MappedAnthropic caps at 1.0; Gemini accepts up to 2.0, so no clamp is needed here.

Response-shape cheat sheet

Where the generated text and token usage live in each provider's response.

WhatClaude (Messages)Gemini (generateContent)
Generated textcontent[0].textcandidates[0].content.parts[0].text
Finish reasonstop_reasoncandidates[0].finishReason
Input tokensusage.input_tokensusageMetadata.promptTokenCount
Output tokensusage.output_tokensusageMetadata.candidatesTokenCount
Tool callcontent[] block type:"tool_use"candidates[0].content.parts[].functionCall

Mapping follows the official Anthropic Messages and Gemini generateContent references (listed below the tool). No live API call is made — the conversion is a static, deterministic transform that runs on your device.

How it works

The converter is a deterministic transformation of two published request schemas — there is no model call. It reads your Anthropic Messages request, applies a fixed set of mapping rules transcribed from the official Anthropic and Google Gemini API references, and emits the equivalent Gemini generateContent request. Every rule is a static table entry, so the same input always produces the same output, and the result is testable.

  1. Endpoint. POST /v1/messages on api.anthropic.com becomes POST /v1beta/models/{model}:generateContent on generativelanguage.googleapis.com. When stream:true it switches to :streamGenerateContent?alt=sse. The model goes in the URL path, not the body.
  2. Auth headers. x-api-key + anthropic-version: 2023-06-01 become a single x-goog-api-key header (or a ?key= query parameter — your choice in the tool).
  3. System prompt. Claude's top-level system(a string or an array of text blocks) is hoisted into Gemini's systemInstruction.parts[].text, because Gemini has no in-array system role.
  4. messages → contents. Turns keep their order. role:"assistant" becomes role:"model"; user stays user. A string content becomes parts:[{text}]; an image base64 block becomes inlineData{mimeType,data}.
  5. Sampling → generationConfig. max_tokens maxOutputTokens, top_ptopP, top_k topK, stop_sequencesstopSequences. temperature passes through, but note Claude caps it at 1 while Gemini allows up to 2, so the reverse direction clamps any value above 1.
  6. Extended thinking. thinking:{type:"enabled",budget_tokens} maps to generationConfig.thinkingConfig.thinkingBudget.
  7. tools & tool_choice. Anthropic's tools[].{name,description,input_schema} is wrapped into tools[].functionDeclarations[] (input_schema parameters). tool_choice maps to toolConfig.functionCallingConfig.mode: {type:auto}→AUTO, {type:any}→ANY, {type:none}→NONE, and {type:tool,name}→ANY plus allowedFunctionNames.
  8. Required max_tokens gotcha. Anthropic requires max_tokens. When converting Gemini → Claude and the source has no maxOutputTokens, the tool injects max_tokens: 1024 and flags it so Anthropic will not reject the request.
  9. No equivalent. metadata.user_id, cache_control and service_tier have no Gemini field; going the other way, safetySettings, cachedContent, candidateCount and responseMimeType/responseSchema have no Anthropic field. Each is dropped and noted rather than silently mis-converted.

As a credibility check, three worked conversions ship as fixtures and are reconciled against the references on every load, and the converter is verified by a round-trip invariant: converting Claude → Gemini → Claude must recover the same system content, max_tokens, stop sequences and tool definitions. Two independent code paths agreeing is the guarantee that the rename rules are inverse.

Worked examples

A — basic chat with a system prompt (Claude → Gemini)

  1. In: {"model":"claude-haiku-4-5",
  2. "system":"You are a terse assistant.",
  3. "messages":[{"role":"user","content":"Capital of Sri Lanka?"}],
  4. "max_tokens":50,"temperature":0.2}
  5. Out: systemInstruction: {"parts":[{"text":"You are a terse assistant."}]}
  6. contents: [{"role":"user","parts":[{"text":"Capital of Sri Lanka?"}]}]
  7. generationConfig: {"maxOutputTokens":50,"temperature":0.2}
  8. Endpoint → /v1beta/models/gemini-2.5-flash:generateContent
  9. Header → x-goog-api-key

B — tools + tool_choice + extended thinking (Claude → Gemini)

  1. In: tools:[{"name":"get_weather","description":"Get weather",
  2. "input_schema":{"type":"object","properties":{"city":{...}},"required":["city"]}}],
  3. tool_choice:{"type":"tool","name":"get_weather"},
  4. thinking:{"type":"enabled","budget_tokens":1024}, max_tokens:1024
  5. Out: tools:[{"functionDeclarations":[{"name":"get_weather",
  6. "description":"Get weather","parameters":{...}}]}] (input_schema → parameters)
  7. toolConfig:{"functionCallingConfig":{"mode":"ANY",
  8. "allowedFunctionNames":["get_weather"]}} (tool → ANY + allow-list)
  9. generationConfig:{"maxOutputTokens":1024,"thinkingConfig":{"thinkingBudget":1024}}

C — reverse + edge cases (Gemini → Claude)

  1. In: systemInstruction {"parts":[{"text":"Be terse."}]},
  2. contents [{"role":"user","parts":[{"text":"Hi"}]}],
  3. generationConfig {"maxOutputTokens":256,"stopSequences":["\n\n"],"temperature":0.5}
  4. Out: {"model":"claude-sonnet-5","max_tokens":256,"system":"Be terse.",
  5. "messages":[{"role":"user","content":"Hi"}],"temperature":0.5,
  6. "stop_sequences":["\n\n"]}
  7. Edge cases: no maxOutputTokens → max_tokens 1024 injected + flagged (Anthropic
  8. requires it); temperature 1.6 → clamped to 1.0 + flagged (Anthropic caps at 1.0).

Frequently asked questions

Sources & references

The mapping rules, the Gemini endpoint shape and the 1/2 temperature ceilings were last cross-checked against the official references on 2026-07-12. This page is reviewed whenever either provider ships a breaking request-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 parameter that maps wrong, or want another provider added?

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