DocsAPI referenceGemini API

Gemini API

Google Gemini-compatible endpoints — generateContent, streamGenerateContent, countTokens.

POST/v1beta/models/{model}:generateContent

A chat endpoint compatible with the Google Gemini API request body. The model name and action live in the path ({model}:generateContent); authenticate with the x-goog-api-key header.

Google's official ?key= query parameter is not supported — the key must be in the x-goog-api-key header (the Google GenAI SDK uses that header by default).

Request body

FieldTypeRequiredDescription
contentsarrayYesConversation content: each item has a role (user/model) and parts (text or inline media).
systemInstructionobjectNoSystem prompt ({ "parts": [{ "text": … }] }).
generationConfigobjectNoGeneration parameters: temperature, maxOutputTokens, etc.
request.sh
curl "https://api.soleapi.com/v1beta/models/gemini-2.5-pro:generateContent" \
  -H "x-goog-api-key: $SOLEAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "Write a haiku about the sea"}]}]
  }'

Response

response.json
{
  "candidates": [
    {
      "content": {
        "parts": [{ "text": "Waves fold into foam..." }],
        "role": "model"
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 14,
    "candidatesTokenCount": 23,
    "totalTokenCount": 37
  }
}

Streaming generation

POST/v1beta/models/{model}:streamGenerateContent

Append ?alt=sse to stream incrementally over SSE — each data: line is a response fragment; without alt=sse you get one complete JSON array. See Streaming.

Count tokens

POST/v1beta/models/{model}:countTokens
count_tokens.sh
curl "https://api.soleapi.com/v1beta/models/gemini-2.5-pro:countTokens" \
  -H "x-goog-api-key: $SOLEAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [{"parts": [{"text": "Write a haiku about the sea"}]}]
  }'

# => { "totalTokens": 14 }