Gemini API

The Google Vertex AI / Gemini protocol is supported natively. Use the @google/genai SDK, the Vertex SDK, or any Gemini-compatible client — the request body is forwarded upstream unchanged.

Endpoints

POST https://api.eclogue.ai/v1/models/{model}:generateContent
POST https://api.eclogue.ai/v1/models/{model}:streamGenerateContent?alt=sse

Note that the model goes in the URL path, not the body. :generateContent is non-streaming; :streamGenerateContent?alt=sse streams over SSE.

Example request

{
  "contents": [
    {
      "role": "user",
      "parts": [{"text": "What is the capital of France?"}]
    }
  ],
  "generationConfig": {
    "maxOutputTokens": 100,
    "temperature": 0.7
  }
}

Required headers

HeaderValueDescription
AuthorizationBearer gw-your-keyYour gateway API key
Content-Typeapplication/jsonRequest body format

Request body fields

FieldTypeRequiredDescription
contentsarrayYesArray of conversation turns, each with a role and parts
generationConfigobjectNoGeneration settings: maxOutputTokens, temperature, topP, topK, …
systemInstructionobjectNoSystem instruction (a top-level field, not part of contents)
toolsarrayNoFunction-calling definitions
safetySettingsarrayNoSafety filter configuration

Example response

{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [{"text": "The capital of France is Paris."}]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 8,
    "candidatesTokenCount": 7,
    "thoughtsTokenCount": 0,
    "totalTokenCount": 15
  },
  "modelVersion": "gemini-2.5-flash"
}

usageMetadata.thoughtsTokenCount is the number of thinking tokens (for thinking-capable models). For billing, completion_tokens = candidatesTokenCount + thoughtsTokenCount.

With curl

curl -X POST "https://api.eclogue.ai/v1/models/gemini-2.5-pro:generateContent" \
  -H "Authorization: Bearer gw-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role":"user","parts":[{"text":"Hello!"}]}],
    "generationConfig": {"maxOutputTokens": 100}
  }'

Streaming

Change :generateContent in the URL to :streamGenerateContent?alt=sse and the response becomes an SSE event stream:

curl -X POST "https://api.eclogue.ai/v1/models/gemini-2.5-pro:streamGenerateContent?alt=sse" \
  -H "Authorization: Bearer gw-your-key" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"role":"user","parts":[{"text":"Tell me a story"}]}],
    "generationConfig": {"maxOutputTokens": 200}
  }'

With the @google/genai SDK

import { GoogleGenAI } from '@google/genai'

// point at the gateway and use your gateway key
const ai = new GoogleGenAI({
  apiKey: 'gw-your-key-here',
  httpOptions: {
    baseUrl: 'https://api.eclogue.ai',
  },
})

const response = await ai.models.generateContent({
  model: 'gemini-2.5-pro',
  contents: 'Hello!',
})

console.log(response.text)

System instructions

The Vertex protocol puts system instructions in a top-level systemInstruction field, rather than inside messages as OpenAI does:

{
  "systemInstruction": {
    "parts": [{"text": "You are a helpful assistant. Reply in Chinese."}]
  },
  "contents": [
    {"role": "user", "parts": [{"text": "What is 2+2?"}]}
  ],
  "generationConfig": {"maxOutputTokens": 100}
}

Supported models

Models currently available over the Vertex protocol:

  • gemini-2.5-pro
  • gemini-2.5-flash
  • gemini-2.5-flash-lite
  • gemini-2.5-flash-image
  • gemini-3.0-flash-preview
  • gemini-3.0-pro-image-preview
  • gemini-3.1-flash-image-preview
  • gemini-3.1-flash-lite-preview
  • gemini-3.1-pro-preview
  • gemini-3.5-flash

See the models page for the full list and pricing.

Comparing the three protocols

AspectOpenAI ChatAnthropic MessagesVertex / Gemini
Endpoint/v1/chat/completions/v1/messages/v1/models/{model}:generateContent
Where the model goesbody.modelbody.modelURL path
Enabling streamingstream: truestream: trueChange the URL to :streamGenerateContent?alt=sse
System instructionFirst item in messagesTop-level systemTop-level systemInstruction
Message root fieldmessages[]messages[]contents[] + parts[]
Token fieldsprompt_tokens / completion_tokensinput_tokens / output_tokenspromptTokenCount / candidatesTokenCount + thoughtsTokenCount

All three protocols share the same API key, balance and billing. Pick whichever matches the SDK you already use.

Notes

  • The request body is passed through unchanged. The gateway only reads usageMetadata from the response to extract token counts for billing.
  • Google's own aiplatform.googleapis.com endpoint is not supported yet (its GCP OAuth flow differs; it may be added later).
  • In streaming responses only the final chunk carries a complete usageMetadata — this is standard Vertex behaviour, so do not expect token counts from intermediate chunks.