Skip to content
SayGMDocs
Dashboard

Generate content, stream content, or count tokens

POST
/v1beta/models/{modelAndAction}
curl --request POST \
--url 'https://api.saygm.com/v1beta/models/gemini-3.6-flash%3AgenerateContent?alt=sse' \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-GM-Routing: default' \
--data '{ "contents": [ { "role": "user", "parts": [ { "text": "example", "inlineData": {}, "functionCall": {}, "functionResponse": {} } ] } ], "generationConfig": { "maxOutputTokens": 1, "candidateCount": 1, "temperature": 1, "topP": 1, "topK": 1 }, "systemInstruction": { "role": "user", "parts": [ { "text": "example", "inlineData": {}, "functionCall": {}, "functionResponse": {} } ] }, "safetySettings": [ {} ], "tools": [ {} ], "toolConfig": {} }'

Gemini-compatible model action endpoint. modelAndAction joins a model id and action with :. Supported actions are countTokens, generateContent, and streamGenerateContent; streaming requires alt=sse. Authenticate with a SayGM API key using x-goog-api-key, Authorization: Bearer, or the key query parameter. X-GM-Routing and X-GM-Providers apply to the generation actions.

modelAndAction
required
string
/^[^:]+:(countTokens|generateContent|streamGenerateContent)$/

Model id and supported action joined by :.

Examples

Non-streaming generation

gemini-3.6-flash:generateContent
alt
string
Allowed values: sse

Must be sse when modelAndAction uses streamGenerateContent; the gateway rejects other or missing values for that action.

Example
sse
X-GM-Routing
string
default: default
Allowed values: default cheapest fastest

Per-request routing mode. default (or omitting the header) follows GM’s configured routing; cheapest ranks eligible routes by predicted final charge, preferring routes with at least 95% recent reliability; fastest ranks them by measured time to first token and output speed. Predictions are not a price cap or latency guarantee. A conversation stays on its current healthy route regardless of mode. Send the header at most once. Fusion, multi-model cascade, and some multimodal requests reject cheapest and fastest with 400.

X-GM-Providers
string
>= 1 characters

Comma-separated allowlist of provider identifiers that may serve the request. Use 1 to 16 distinct case-insensitive names, each 1 to 64 letters, digits, underscores, or hyphens, starting with a letter or digit. The restriction applies under every supported routing mode and on every retry. Invalid values return 400 with code invalid_provider_restriction; a model with no route on a listed provider returns 400 with code no_allowed_provider; listed providers that cannot serve now return 503. Fusion and multi-model cascade requests reject this header with 400.

Media typeapplication/json
Any of:

The provider-facing fields required by Gemini GenerateContent. Additional provider fields are forwarded unchanged.

object
contents
required
Array<object>
>= 1 items
object
role
string
Allowed values: user model
parts
required
Array<object>
>= 1 items
object
text
string
inlineData
object
functionCall
object
functionResponse
object
key
additional properties
any
key
additional properties
any
generationConfig
object
maxOutputTokens
integer
>= 1
candidateCount
integer
>= 1
temperature
number
topP
number
<= 1
topK
integer
key
additional properties
any
systemInstruction
object
role
string
Allowed values: user model
parts
required
Array<object>
>= 1 items
object
text
string
inlineData
object
functionCall
object
functionResponse
object
key
additional properties
any
key
additional properties
any
safetySettings
Array<object>
object
tools
Array<object>
object
toolConfig
object
key
additional properties
any

A JSON response for countTokens or generateContent, or an SSE stream for streamGenerateContent.

Any of:
object
totalTokens
required
integer
key
additional properties
any
Example
{
"candidates": [
{
"content": {
"role": "user"
}
}
]
}

Invalid request, unsupported action, or an upstream provider 400 response.

Media typeapplication/json

Gemini-shaped gateway error. Billing fields are included after dispatch.

object
error
required
object
code
required
integer
message
required
string
status
required
string
requestId

Gateway request identifier.

string
key
additional properties
any
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
key
additional properties
any
Example
{
"billing_status": "settled"
}

The API key is missing or invalid.

Media typeapplication/json

Gemini-shaped gateway error. Billing fields are included after dispatch.

object
error
required
object
code
required
integer
message
required
string
status
required
string
requestId

Gateway request identifier.

string
key
additional properties
any
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
key
additional properties
any
Example
{
"billing_status": "settled"
}

Insufficient prepaid balance on generateContent and streamGenerateContent actions. The error message links to the funding page; when the available balance is nonzero it also reports estimated maximum cost and request-sizing guidance.

Media typeapplication/json

Gemini-shaped gateway error. Billing fields are included after dispatch.

object
error
required
object
code
required
integer
message
required
string
status
required
string
requestId

Gateway request identifier.

string
key
additional properties
any
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
key
additional properties
any
Examples

No available balance

{
"error": {
"code": 402,
"message": "Your gm balance is empty. Add credits: https://saygm.com/topup",
"status": "PERMISSION_DENIED"
}
}

Guardrail block (guardrail_blocked).

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}

Request body too large (request_too_large).

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}

Upstream 422 response.

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}

Account, model, or upstream request limit. OpenAI-shaped account-limit errors use rate_limit_exceeded.

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}
Retry-After
integer
>= 1

Seconds before retrying, when a delay is available.

Gateway internal error (internal_error).

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}

Upstream connection failure (upstream_connect_failed).

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}

The credit service, guardrail policy, or model serving is unavailable.

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}
Retry-After
integer
>= 1

Seconds before retrying, when a delay is available.

Upstream timeout (upstream_timeout) or idle stream timeout (upstream_stream_idle_timeout).

Media typeapplication/json
Any of:

OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.

object
error
required
object
message
required
string
type
required
string
code
required

Machine-readable error code. Account request limits use rate_limit_exceeded.

string
param
required
string | null
request_id

Gateway request identifier.

string
charged
boolean
billing_status
string
Allowed values: settled unbilled unknown
potentially_charged
boolean
cost_ndollars

Settled charge in nano-dollars; present when billing_status is settled.

integer
Example
{
"billing_status": "settled"
}