Skip to content

Gemini via the OpenAI format

Call Gemini models through the OpenAI Chat Completions endpoint (/v1/chat/completions) — model names with -thinking and -nothinking suffixes, how thinking parameters, images, audio, video and tool calling are converted, and the Gemini features you can't use this way.

If you already use the OpenAI SDK, or a tool only supports the OpenAI format, change model to a Gemini model name and call Gemini through the Chat Completions endpoint. The gateway converts the request to Gemini's generateContent format for the upstream, then converts the response back to the OpenAI format. It serves the Gemini models in Model Square that are also marked with the OpenAI endpoint type; the key's group decides which of them you can use (see Groups).

POST https://codaapi.com/v1/chat/completions

Use https://codaapi.com/v1 as the Base URL. The OpenAI-compatible address in Google's documentation (…/v1beta/openai/) only has the model list on the gateway; chat requests sent there return 404. When you need features specific to Gemini (see Gemini features you can't use), use the generateContent API instead.

Request headers

Name Required Description
Authorization Yes Bearer sk-…. This endpoint doesn't read x-goog-api-key or ?key=
Content-Type Yes application/json

Request body

The request is written as for OpenAI's Chat Completions. The table shows what the common parameters become on the Gemini side. Parameters not in the table (for example n, logprobs, frequency_penalty and presence_penalty) aren't sent upstream.

Parameter Type Required Becomes on the Gemini side
model string Yes Gemini model name, for example gemini-2.5-flash. For names with a suffix, see Model name suffixes
messages array Yes system and developer messages are merged into systemInstruction; assistant becomes model; tool_calls become functionCall; tool messages become functionResponse
max_completion_tokens or max_tokens integer No generationConfig.maxOutputTokens
temperature, top_p, seed number No temperature, topP and seed in generationConfig
stop string or array No generationConfig.stopSequences, at most 5; extras are dropped
stream boolean No Streaming; see Streaming
response_format object No json_object and json_schema become responseMimeType: "application/json", and the structure in json_schema is sent upstream as the output schema (when the model doesn't support full JSON Schema, the gateway removes the keywords it doesn't support)
reasoning_effort, reasoning — No generationConfig.thinkingConfig; see Thinking parameters
extra_body.google.thinking_config object No Gemini's thinking settings written directly; see Thinking parameters
extra_body.google.image_config object No imageConfig for image models, written as aspect_ratio and image_size; see Nano Banana
tools, tool_choice — No functionDeclarations and toolConfig; see Tool calling

Model name suffixes

Model Square lists some Gemini model names with a suffix. This is a form the gateway provides, not an official Google model name: the gateway strips the suffix, sends the base model name upstream, and rewrites the thinking settings according to the suffix. It works on both the native API and the OpenAI format.

Suffix Example Meaning
-thinking gemini-3-pro-preview-thinking Turns thinking on and returns thought summaries. For the Gemini 2.5 series with max_tokens set, the thinking budget is a share of it
-nothinking gemini-2.5-flash-nothinking, gemini-3-flash-preview-nothinking Turns thinking off. Models that can turn thinking off (for example Gemini 2.5 Flash) get thinkingBudget: 0; models that can't turn it off completely (Gemini 2.5 Pro, the Gemini 3 series) use their lowest setting instead
-thinking- plus a number A row in Model Square whose name ends in -thinking-* means any number can follow, for example -thinking-8192 after gemini-2.5-pro Sets the thinking budget to that many tokens. The Gemini 2.5 series uses it as thinkingBudget, adjusted into the model's allowed range; the Gemini 3 series converts it to the nearest thinkingLevel

If a suffix conflicts with thinking parameters in the request, the model name wins. Which suffixed names you can use, and their prices, are as listed in Model Square.

Thinking parameters

Without a suffix, you can set thinking in the request:

Form Effect
"reasoning_effort": "low" (or minimal, low, medium, high, xhigh, max) The Gemini 3 series converts it to thinkingLevel (a level the model doesn't have is replaced with the nearest one); the Gemini 2.5 series converts the level to a thinkingBudget
"reasoning_effort": "none" or "reasoning": {"enabled": false} Turns thinking off; models that can't turn it off use their lowest setting
"reasoning": {"max_tokens": 4096} Sets a thinking budget; the Gemini 3 series converts it to the nearest thinkingLevel
"extra_body": {"google": {"thinking_config": {…}}} Gemini's thinking settings written directly: thinking_budget, thinking_level, include_thoughts

A reasoning_effort value other than those above returns 400. If both thinking_config and reasoning_effort are set, thinking_config wins. Fields in extra_body must be snake_case (thinking_config, thinking_budget); camelCase (thinkingConfig) returns an error that names the correct form.

When you only set a strength, Gemini doesn't return its thinking. To see thought summaries in the response, use the -thinking suffix or set "include_thoughts": true in thinking_config. Thought summaries are in choices[0].message.reasoning_content (in delta.reasoning_content when streaming). This isn't a standard OpenAI field, and some clients don't show it.

With the OpenAI Python SDK, the contents of the extra_body argument are merged into the top level of the request body, so wrap it once more:

response = client.chat.completions.create(
    model="gemini-2.5-flash",
    messages=[{"role": "user", "content": "Which is larger, 9.11 or 9.9?"}],
    extra_body={"extra_body": {"google": {"thinking_config": {"thinking_budget": 1024, "include_thoughts": True}}}},
)

Images

Put images in the content array as in OpenAI's format:

{
  "role": "user",
  "content": [
    {"type": "text", "text": "What's in this image?"},
    {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
  ]
}

url can be an address reachable from the public internet or a data:image/png;base64,… URL. For an address, the gateway downloads the image first and sends it to Gemini as inlineData, so the address must be publicly reachable. File types Gemini doesn't support return an error.

Images generated by image models appear in the OpenAI-format response as a Markdown image (![image](data:image/png;base64,…)) in content; see Nano Banana.

Tool calling

Functions in tools become Gemini functionDeclarations, and the gateway cleans JSON Schema keywords Gemini doesn't support out of parameters. tool_choice becomes toolConfig.

When the model wants to call a tool, finish_reason is tool_calls and the calls are in message.tool_calls. After running the tool, add the result to messages as a role: "tool" message with the matching tool_call_id, and send the request again.

Request examples

curl

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{"role": "user", "content": "What is an API gateway?"}]
  }'

Python (pip install openai)

from openai import OpenAI

client = OpenAI(
    base_url="https://codaapi.com/v1",
    api_key="sk-your-key",  # better to read it from the OPENAI_API_KEY environment variable
)

response = client.chat.completions.create(
    model="gemini-2.5-pro",
    messages=[{"role": "user", "content": "What is an API gateway?"}],
)
print(response.choices[0].message.content)

Node.js (npm install openai)

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://codaapi.com/v1',
  apiKey: process.env.OPENAI_API_KEY,
});

const completion = await client.chat.completions.create({
  model: 'gemini-2.5-pro',
  messages: [{ role: 'user', content: 'What is an API gateway?' }],
});
console.log(completion.choices[0].message.content);

Forcing thinking

Without thinking parameters, Gemini thinks the way the model does by default, and the response carries no thinking. To force thinking and get thought summaries back, switch to the model name with the -thinking suffix:

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-3-pro-preview-thinking",
    "messages": [{"role": "user", "content": "Who are you?"}]
  }'
response = client.chat.completions.create(
    model="gemini-3-pro-preview-thinking",
    messages=[{"role": "user", "content": "Who are you?"}],
)
message = response.choices[0].message
print(message.content)
# Thought summaries aren't a standard OpenAI field, so read them with getattr
print(getattr(message, "reasoning_content", None))

In the returned message, the answer is in content and the thought summary is in reasoning_content:

{
  "role": "assistant",
  "content": "I'm Gemini, a large language model trained by Google.",
  "reasoning_content": "The user is asking who I am…"
}

To force thinking off, use the -nothinking suffix, for example gemini-2.5-flash-nothinking or gemini-3-flash-preview-nothinking. For what each suffix means, see Model name suffixes; to control thinking with parameters instead of changing the model name, see Thinking parameters.

Image understanding

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
      ]
    }]
  }'

For the requirements on image addresses and base64, see Images above.

Audio understanding

Audio, PDFs and other files can also be written as image_url content parts, several in one message:

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "I sent you a recording and a PDF. Summarize each of them."},
        {"type": "image_url", "image_url": {"url": "https://example.com/meeting.mp3"}},
        {"type": "image_url", "image_url": {"url": "https://example.com/report.pdf"}}
      ]
    }]
  }'

The gateway downloads these addresses first and sends the files to Gemini by the file type it gets, so the addresses must be directly downloadable from the internet; file types Gemini doesn't support return an error. url can also be a data URL such as data:audio/mp3;base64,….

Video understanding

curl https://codaapi.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-pro",
    "messages": [{
      "role": "user",
      "content": [
        {"type": "text", "text": "Summarize this video in three sentences"},
        {"type": "image_url", "image_url": {"url": "https://example.com/clip.mp4"}}
      ]
    }]
  }'

url must be the address of the video file itself: the gateway downloads the address before sending it to Gemini, and the address of a video page such as YouTube downloads the web page, not the video. Video counts as input tokens for both frames and sound, and a video a few minutes long can come to tens of thousands of tokens.

Response

The response is in the OpenAI Chat Completions format:

{
  "object": "chat.completion",
  "model": "gemini-2.5-pro",
  "choices": [
    {
      "index": 0,
      "message": {"role": "assistant", "content": "An API gateway is…"},
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 20,
    "completion_tokens": 260,
    "total_tokens": 280,
    "completion_tokens_details": {"reasoning_tokens": 230}
  }
}
Field Description
choices[0].message.content The answer text (images from image models are here too; see above)
choices[0].message.reasoning_content Thought summaries (only when requested; see Forcing thinking)
choices[0].message.tool_calls Tools to call
choices[0].finish_reason Converted from Gemini's finishReason: STOP → stop, MAX_TOKENS → length, SAFETY and other blocks → content_filter, and tool_calls when calling a tool
usage.completion_tokens Output tokens, including thinking tokens
usage.completion_tokens_details.reasoning_tokens The thinking tokens among them

Streaming

With "stream": true the response comes in OpenAI's SSE format: one data: {…} line per chunk, text in choices[0].delta.content, thought summaries in choices[0].delta.reasoning_content, and a final data: [DONE] line.

Gemini features you can't use

After conversion from the OpenAI format, the following aren't available. If you need them, use the generateContent API:

  • Safety settings: safetySettings can't be expressed in the OpenAI format; the site's defaults apply.
  • Some generationConfig fields: top_k isn't passed to Gemini, and the candidate count (candidateCount) and speech output (speechConfig) can't be expressed in the OpenAI format, so speech synthesis models (names containing tts) only work through the native API; see Speech generation.
  • Gemini-specific tools: tools in the OpenAI format can only describe functions; Gemini's built-in tools such as code execution can't be expressed.
  • Referencing files by address: images and files in the OpenAI format are always downloaded by the gateway and sent as inlineData; there's no equivalent of the native API's fileData, which passes only an address.

Errors

Errors come back in the OpenAI format ({"error": {"message": …, "type": …, "code": …}}), with the request id at the end of message. See Error formats; for what to do about each status code, see Troubleshooting.

Billing

Same price as calling the same model through the native API, based on the usage the upstream returns, with thinking tokens counted as output. For the rules, see Pricing and multipliers; for each group's prices, see the price list.

Updated