induwara.lk
induwara.lkDeveloper · AI

Gemini to OpenAI API Converter

Paste a Google Gemini generateContent request or response and get the equivalent OpenAI Chat Completions JSON — systemInstruction, functionCall, finishReason and usageMetadata mapped field by field. Runs entirely in your browser: no key, no upload, no signup.

By Induwara AshinsanaUpdated Jul 12, 2026
Convert a Gemini requestto OpenAI Chat Completions
Payload type

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

OpenAI token-limit field

Newer OpenAI models (o-series, GPT-4.1+) require max_completion_tokens.

Output format
Messages
4
Fields mapped
4
Tool calls
1
Notes / warnings
0
Converted OpenAI Chat Completions request
{
  "messages": [
    {
      "role": "system",
      "content": "You are terse."
    },
    {
      "role": "user",
      "content": "Weather in Colombo?"
    },
    {
      "role": "assistant",
      "tool_calls": [
        {
          "id": "call_0",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"city\":\"Colombo\"}"
          }
        }
      ]
    },
    {
      "role": "tool",
      "tool_call_id": "call_0",
      "content": "{\"tempC\":31}"
    }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get weather",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ],
  "max_tokens": 1024
}

Field-by-field mapping

GeminiOpenAIStatusDetail
systemInstructionmessages[0] (role:"system")HoistedFolded into a leading system message.
contentsmessagesRenamedrole:"model" → "assistant"; text parts → content; functionCall → tool_calls; functionResponse → role:"tool".
tools[].functionDeclarations[]tools[].functionRenamedEach declaration wrapped as {type:"function",function:{…}}.
generationConfig.maxOutputTokens: 1024max_tokens: 1024RenamedClassic OpenAI field name.

Mapping follows the official Google Gemini generateContent and OpenAI Chat Completions references — sources are listed below the tool. The converted request targets https://api.openai.com/v1/chat/completions or any OpenAI-compatible gateway.

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 OpenAI API references, and emits the equivalent OpenAI Chat Completions JSON. Every rule is a static mapping, so the same input always produces the same output, and two 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 a leading {role:"system"} message — OpenAI has no separate instruction field.
  2. contents → messages. Order is preserved. role:"model" becomes assistant; user stays user. Text parts become a content string, or a {type:"text"}/{type:"image_url"} content-part array when an inlineData part is present (encoded as a data: URL).
  3. functionCall → tool_calls. A model functionCall{name,args} becomes an assistant tool_calls entry. The args object is JSON-stringified into arguments. Gemini calls carry no id, so a stable call_0, call_1… is synthesized in order.
  4. functionResponse → tool message. A user-turn functionResponse{name,response} becomes a separate {role:"tool",tool_call_id,content} message, linked back to the matching synthesized call id by name and order.
  5. tools & toolConfig. tools[].functionDeclarations[] is unwrapped into tools[].function (upper-case Type enums like STRING are lower-cased to JSON Schema). functionCallingConfig.mode: AUTO→"auto", ANY→"required" (or a named function), NONE→"none".
  6. generationConfig. maxOutputTokens max_tokens (or max_completion_tokens per the toggle), topPtop_p, stopSequencesstop, candidateCountn (flagged), and responseMimeType/responseSchemaresponse_format.

Responses wrap candidates[] into a chat.completion object: each candidate becomes a choice{index,message,finish_reason}, part text becomes message.content, and finishReason maps to finish_reason (STOP→stop, MAX_TOKENS→length, SAFETY/RECITATION→content_filter; forced tool_calls when calls are present). usageMetadata maps to usage promptTokenCount→prompt_tokens, candidatesTokenCount→completion_tokens, totalTokenCount→total_tokens. Fields with no clean target — topK, safetySettings, thinking parts, extra candidates — 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}
  6. Out: messages:[{"role":"system","content":"You are terse."},
  7. {"role":"user","content":"Weather in Colombo?"},
  8. {"role":"assistant","tool_calls":[{"id":"call_0","type":"function",
  9. "function":{"name":"get_weather","arguments":"{\"city\":\"Colombo\"}"}}]},
  10. {"role":"tool","tool_call_id":"call_0","content":"{\"tempC\":31}"}]
  11. tools:[{"type":"function","function":{"name":"get_weather",...}}]
  12. max_tokens: 1024
  13. Check: args object → arguments JSON string; call_0 links result to call.

2 — response mapping (MAX_TOKENS → length)

  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: {"object":"chat.completion","model":"gemini-2.5-flash",
  7. "choices":[{"index":0,"message":{"role":"assistant",
  8. "content":"It is 31°C in Colombo."},"finish_reason":"length"}],
  9. "usage":{"prompt_tokens":18,"completion_tokens":9,"total_tokens":27}}
  10. Check: MAX_TOKENS → length; token counts renamed; modelVersion → model.

3 — edge cases (handled deliberately, no crash)

  1. Non-object input (array / "hi" / null) → a friendly, specific error, no output.
  2. Empty contents / candidates → empty messages/choices + a warning note.
  3. functionResponse with no preceding functionCall → a fresh call_N id + a flag.
  4. Uppercase parameter Type enums (STRING, OBJECT) → lower-cased JSON Schema + a flag.
  5. candidateCount 3 → three choices, flagged (OpenAI n bills and behaves differently).
  6. finishReason RECITATION → content_filter (flagged approximate); OTHER → stop.

Frequently asked questions

Sources & references

The mapping rules were last cross-checked against the official Gemini and OpenAI 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.