Gemini format

Call Gemini through Google's native generateContent protocol.

POST/v1/models/{model}:generateContent

Google native contents / parts request. The model id is part of the URL.

Use :streamGenerateContent for streaming responses.

Authentication

Send one platform API key. These sources are accepted:

SourceExample
AuthorizationAuthorization: Bearer sk-YOUR_KEY
x-api-keyx-api-key: sk-YOUR_KEY
x-goog-api-keyx-goog-api-key: sk-YOUR_KEY
query parameter key?key=sk-YOUR_KEY

x-goog-api-key and ?key= are the Google native credentials. Authorization: Bearer and x-api-key are the platform credentials. These four sources apply to the Gemini native endpoints and GET /v1/models. Other endpoints still accept only Authorization and x-api-key. If more than one source is present and the values differ, the gateway returns 401 with error.code conflicting_keys and does not call the upstream. A source that is present but empty is also a conflict when another source has a key; it is not replaced by that key. No source, or only empty sources, returns missing_key. An unknown or disabled key returns invalid_key.

The caller key is not forwarded upstream. Prefer a header. A key in the query string can be copied by proxies and access logs outside this gateway. Every other query parameter, and every field in the request body, is forwarded upstream as sent.

A Google REST example has to change three things before it reaches this gateway:

  • service address: https://hopsapi.com
  • API version path: /v1/models/{model}:generateContent, not Google's /v1beta/...
  • model ID: a platform ID from the current key's GET /v1/models, such as gemini-3.5-flash
curl "https://hopsapi.com/v1/models/gemini-3.5-flash:generateContent?key=sk-YOUR_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"contents":[{"role":"user","parts":[{"text":"Introduce yourself in one sentence."}]}],
       "generationConfig":{"maxOutputTokens":1500}}'

Streaming keeps the same credentials. alt=sse only selects the SSE framing:

curl "https://hopsapi.com/v1/models/gemini-3.5-flash:streamGenerateContent?alt=sse" \
  -H "x-goog-api-key: sk-YOUR_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"contents":[{"role":"user","parts":[{"text":"Introduce yourself in one sentence."}]}]}'

?alt=sse&key=sk-YOUR_KEY is also accepted.

Request

curl "https://hopsapi.com/v1/models/gemini-3.5-flash:generateContent" \
  -H "Authorization: Bearer sk-YOUR_KEY" \
  -H "content-type: application/json" \
  -d '{"contents":[{"role":"user","parts":[{"text":"Introduce yourself in one sentence."}]}],
       "generationConfig":{"maxOutputTokens":1500}}'

Response

{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [{ "text": "I'm Gemini, a multimodal AI assistant built by Google." }]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": { "promptTokenCount": 6, "candidatesTokenCount": 17, "totalTokenCount": 23 }
}

Gemini thinking models spend thinking tokens first — too small a maxOutputTokens may yield only thinking and no text; use ≥ 1500. The SDK base_url is the bare domain https://hopsapi.com, and api_version / apiVersion must be v1. The Google Gen AI SDK otherwise calls /v1beta/models/... and sends x-goog-api-key, which does not match this gateway's /v1/models/{model}:generateContent entry.

gemini-3.5-flash can also use OpenAI Chat Completions. See OpenAI format when you need the OpenAI SDK, reasoning_effort, or OpenAI SSE framing. The native generateContent request, response, and streaming behavior on this page remains unchanged.

Gemini image models published as media models use POST /v1/router/task/create. The body is { "task": "Txt2Img" | "Img2Img", "model", "input": { "prompt", "aspect_ratio", "resolution", "images"? } }. Img2Img requires HTTPS URLs in images. You can also pass callback_url; see Media task callbacks. The aspect ratio and resolution must be values that model allows. A successful GET /v1/router/tasks/{task_id} returns status: 2, results[].urls, and cost. Billing uses three meters: input tokens, text plus thinking tokens, and image tokens. When the output cannot be split, the whole output is billed at the image output price. Aspect ratios and resolutions are on Gemini image.

Text models that show an image output price on the price page still use generateContent on this page. When generationConfig.responseModalities includes IMAGE, the image is inlineData on candidates[0].content.parts, and the same three meters apply. Models without an image output price bill all output at the output price. A folded per-image price is only a quote; the charge follows the returned token counts.

On this page

On this page