induwara.lk
induwara.lkDeveloper · AI

OpenAI to Gemini API Request Converter

Paste an OpenAI Chat Completions 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 8, 2026
Convert a OpenAI requestto Gemini
Direction

Paste a OpenAI 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: gpt-4o-minipath: /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.
1 system messagesystemInstruction.parts[].textHoistedExtracted from messages and concatenated into the top-level systemInstruction.
messages (user/assistant)contents (user/model)RenamedOrder preserved. assistant → model; each string content becomes parts:[{text}].
max_tokens: 50generationConfig.maxOutputTokens: 50RenamedFolded into maxOutputTokens (optional in both APIs).
temperature: 0.2generationConfig.temperature: 0.2MappedBoth APIs accept 0.0–2.0 on current models; passed through.

Mapping follows the official OpenAI Chat Completions and Gemini generateContent references. Prefer a near drop-in migration? Point the OpenAI SDK at https://generativelanguage.googleapis.com/v1beta/openai/ — sources are listed below the tool.

How it works

The converter is a deterministic transformation of a published request schema — there is no model call. It reads your OpenAI Chat Completions request, applies a fixed set of mapping rules transcribed from the official OpenAI 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/chat/completions on api.openai.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 header. Authorization: Bearer … becomes x-goog-api-key: … (or a ?key= query parameter — your choice in the tool).
  3. System prompt. Gemini has no in-array system role. Every role:"system" turn is pulled out of the messages array and concatenated into the top-level systemInstruction.parts[].text.
  4. messages → contents. Turns keep their order. role:"assistant" becomes role:"model"; user stays user. A string content becomes parts:[{text}].
  5. Sampling → generationConfig. max_tokens maxOutputTokens, top_ptopP, n candidateCount, stopstopSequences. temperature passes through — both APIs accept 0.0–2 on current models.
  6. JSON mode. response_format:{type:"json_object"} generationConfig.responseMimeType:"application/json"; a json_schema also fills generationConfig.responseSchema.
  7. tools & tool_choice. tools[].function.{name,description,parameters} is unwrapped into tools[].functionDeclarations[]. tool_choice maps to toolConfig.functionCallingConfig.mode: "auto"→AUTO, "required"→ANY, "none"→NONE, a named function → ANY plus allowedFunctionNames.
  8. No equivalent. logit_bias, user, store, metadata, service_tier, logprobs and top_logprobs have no Gemini 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 OpenAI → Gemini → OpenAI must recover the same system content, stop sequences and tool definitions. Two independent code paths agreeing is the guarantee that the rename rules are inverse. If you prefer a near drop-in migration, the tool also surfaces Gemini's OpenAI-compatible base URL (https://generativelanguage.googleapis.com/v1beta/openai/) with its trade-offs.

Worked examples

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

  1. In: {"model":"gpt-4o-mini","messages":[
  2. {"role":"system","content":"You are a terse assistant."},
  3. {"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 — function calling + JSON output (OpenAI → Gemini)

  1. In: tools:[{"type":"function","function":{
  2. "name":"get_weather","description":"Get weather",
  3. "parameters":{"type":"object",...}}}],
  4. tool_choice:"required", response_format:{"type":"json_object"}
  5. Out: tools:[{"functionDeclarations":[{"name":"get_weather",
  6. "description":"Get weather","parameters":{...}}]}] (wrapper unwrapped)
  7. toolConfig: {"functionCallingConfig":{"mode":"ANY"}} (required → ANY)
  8. generationConfig: {"responseMimeType":"application/json"}

C — reverse + edge cases (Gemini → OpenAI)

  1. In: systemInstruction {"parts":[{"text":"Be terse."}]},
  2. contents [{"role":"user","parts":[{"text":"Hi"}]}],
  3. generationConfig {"maxOutputTokens":256,"stopSequences":["\n\n"]}
  4. Out: messages:[{"role":"system","content":"Be terse."},
  5. {"role":"user","content":"Hi"}]
  6. maxOutputTokens 256 → max_tokens; stopSequences → stop
  7. Edge cases: empty messages → contents:[] + warning (no crash);
  8. temperature 2.0 → passes through; stop "STOP" → stopSequences:["STOP"].

Frequently asked questions

Sources & references

The mapping rules, the Gemini endpoint shape and the 2 temperature ceiling were last cross-checked against the official references on 2026-07-08. 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.