Skip to content
SayGMDocs
Dashboard

Gemini compatibility

Gemini model IDs are encoded in the request path. SayGM supports generateContent and SSE streamGenerateContent.

import os
from google import genai
from google.genai import types
client = genai.Client(
api_key=os.environ["GM_API_KEY"],
http_options=types.HttpOptions(base_url="https://api.saygm.com"),
)
response = client.models.generate_content(
model="gemini-3.5-flash",
contents="Say hello.",
)
print(response.text)
Terminal window
curl "https://api.saygm.com/v1beta/models/gemini-3.5-flash:generateContent" \
-H "Authorization: Bearer $GM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contents": [{"role": "user", "parts": [{"text": "Say hello."}]}]
}'

For streaming, use :streamGenerateContent?alt=sse. SayGM requires alt=sse and does not support Gemini’s legacy JSON-array streaming format.

Every successful response carries settled cost inside usageMetadata, alongside the normal token counts, using Gemini’s camelCase convention:

{
"usageMetadata": {
"promptTokenCount": 12,
"candidatesTokenCount": 9,
"totalTokenCount": 21,
"cost": 0.000140000,
"costNanoUsd": 140000
}
}

cost is USD, rendered as a JSON number with exactly nine fractional digits — the amount actually settled against the account’s prepaid balance, not an estimate from /v1/models rates. costNanoUsd is the same amount as an integer in nano-USD (1 nUSD = 10⁻⁹ USD), matching GET /v1/credits. Error responses carry neither field. See per-request cost for how to use the figure.

The Google GenAI SDK discards fields it does not recognize, so response.usage_metadata does not expose the cost. Read the raw HTTP response when you need it.