Skip to content
SayGMDocs
Dashboard

Create a chat completion

POST
/chat/completions
curl --request POST \
--url https://api.saygm.com/v1/chat/completions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'X-GM-Routing: default' \
--data '{ "model": "gpt-5.5", "messages": [ { "role": "example", "content": [ "example" ] } ], "stream": false, "temperature": 1, "max_tokens": 1 }'

OpenAI-compatible Chat Completions. Set stream: true for an incremental Server-Sent Events stream of chat.completion.chunk objects terminated by data: [DONE]; otherwise a single chat.completion object is returned.

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
object
model
required

Bare model id (no provider prefix); the gateway resolves the provider.

string
messages
required
Array<object>
>= 1 items

Message fields are forwarded unchanged, including provider-specific fields.

object
role
required

Message role, forwarded unchanged; includes roles such as system, developer, user, assistant, and tool.

string
content
required
Any of:
string
key
additional properties
any
stream

Stream the response as Server-Sent Events.

boolean
temperature
number
max_tokens
integer
key
additional properties
any

When stream is false, a single chat.completion JSON object. When stream is true, a Server-Sent Events stream (text/event-stream) of chat.completion.chunk objects terminated by data: [DONE].

object
id
string
object
string
Allowed value: chat.completion
created
integer
model
string
choices
Array<object>
object
index
integer
message

Message fields are forwarded unchanged, including provider-specific fields.

object
role
required

Message role, forwarded unchanged; includes roles such as system, developer, user, assistant, and tool.

string
content
required
Any of:
string
key
additional properties
any
finish_reason
string
usage
object
prompt_tokens
integer
completion_tokens
integer
total_tokens
integer
cost

USD settled against the account for this request — the gateway’s settlement figure, not a catalog estimate. Rendered with exactly nine fractional digits.

number
cost_nano_usd

The same settled amount in nano-USD (10^-9 USD), SayGM’s exact integer accounting unit.

integer
Example
{
"object": "chat.completion"
}

Invalid request or an upstream provider 400 response.

Media typeapplication/json

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"
}

Missing or invalid SayGM API key.

Media typeapplication/json

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"
}

Insufficient prepaid balance. 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

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
Examples

No available balance

{
"error": {
"message": "Your gm balance is empty. Add credits: https://saygm.com/topup",
"type": "insufficient_quota",
"code": "insufficient_quota",
"param": null
}
}

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"
}