Chat · Google Gemini

Chat Completions

Generate conversational responses using Gemini models through the same unified chat completions endpoint you use for every other provider.

POST/v1/chat/completions
Same endpoint, no translation needed
Send an OpenAI-style request body with a Gemini model name. The gateway converts it to Gemini's generateContent format, maps the assistant role to model, moves your system message into system_instruction, and converts the response back to OpenAI shape.

Supported Models

ModelProvider
gemini-2.5-proGoogle
gemini-2.5-flashGoogle
gemini-2.5-flash-liteGoogle
gemini-2.0-flashGoogle

Call GET /v1/models for the list your key can actually reach, including preview models.

Request

Body Parameters

modelstringrequired

Model ID — e.g. "gemini-2.5-flash"

messagesarrayrequired

Array of message objects with role and content. A system message becomes Gemini system_instruction; assistant becomes model.

temperaturenumber

Sampling temperature

max_tokensinteger

Maps to Gemini max_output_tokens

top_pnumber

Nucleus sampling parameter

streamboolean

Enable server-sent events streaming

Default: false

toolsarray

OpenAI-format function tools, converted to Gemini function_declarations

tool_choicestring | object

Passed through as Gemini tool_config

Options: auto, none, required

cURL
curl https://api.metriqual.com/v1/chat/completions \
  -H "Authorization: Bearer mql_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "What is quantum computing?"}
    ],
    "temperature": 0.7,
    "max_tokens": 500
  }'
TypeScript SDK
const response = await mql.chat.create({
  model: 'gemini-2.5-flash',
  messages: [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: 'What is quantum computing?' }
  ],
  temperature: 0.7,
  max_tokens: 500
});

console.log(response.choices[0].message.content);
Python SDK
response = mql.chat.create(
    model="gemini-2.5-flash",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "What is quantum computing?"},
    ],
    temperature=0.7,
    max_tokens=500,
)
print(response["choices"][0]["message"]["content"])
Text messages only
The Gemini adapter sends each message as a single text part. Content arrays with image_url objects are not converted, so send images to an OpenAI or MiniMax model instead. Only the parameters in the table above reach Gemini; anything else in the body, including stop, is dropped.

Response

Response Fields

idstring

Unique completion ID

objectstring

Always "chat.completion"

createdinteger

Unix timestamp

modelstring

Model used for completion

choicesarray

Array of completion choices

usageobject

Token usage statistics

200
{
  "id": "chatcmpl-gemini-abc123",
  "object": "chat.completion",
  "created": 1705320000,
  "model": "gemini-2.5-flash",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Quantum computing is a type of computation..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 25,
    "completion_tokens": 150,
    "total_tokens": 175
  }
}

Streaming

Set stream: true to receive incremental responses via Server-Sent Events. Gemini's native stream is normalized into OpenAI chunks before it reaches you, so the same reader works across providers.

TypeScript SDK Streaming
for await (const chunk of mql.chat.stream({
  model: 'gemini-2.5-flash',
  messages: [{ role: 'user', content: 'Tell me a story' }]
})) {
  process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
Python SDK Streaming
for chunk in mql.chat.stream(
    model="gemini-2.5-flash",
    messages=[{"role": "user", "content": "Tell me a story"}],
):
    print(chunk["choices"][0]["delta"].get("content", ""), end="")