Generate images
const url = 'https://api.saygm.com/v1/images/generations';const options = { method: 'POST', headers: { 'X-GM-Routing': 'default', Authorization: 'Bearer <token>', 'Content-Type': 'application/json' }, body: '{"model":"example","prompt":"example","n":1,"size":"1024x1024","response_format":"b64_json","seed":1}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://api.saygm.com/v1/images/generations \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --header 'X-GM-Routing: default' \ --data '{ "model": "example", "prompt": "example", "n": 1, "size": "1024x1024", "response_format": "b64_json", "seed": 1 }'Create one or more images with a model that supports image generation. The response contains base64 image data and the settled charge.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Header Parameters
Section titled “Header Parameters”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.
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.
Request Bodyrequired
Section titled “Request Bodyrequired”Responses
Section titled “Responses”The generated images.
object
object
Base64-encoded image bytes.
object
Settled buyer charge in USD.
The same charge in integer nano-USD.
Examplegenerated
{ "created": 1, "data": [ { "b64_json": "example" } ], "usage": { "cost": 1, "cost_nano_usd": 1 }}Invalid request or an upstream provider 400 response.
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}The API key is missing or invalid.
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
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.
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
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 }}Estimated maximum cost exceeds available balance
{ "error": { "message": "This request's estimated maximum cost of $1.01 exceeds your available balance of $0.51. Add credits: https://saygm.com/topup. Try shortening the conversation or attachments, or lowering max output tokens.", "type": "insufficient_quota", "code": "insufficient_quota", "param": null }}Guardrail block (guardrail_blocked).
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}Request body too large (request_too_large).
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}Upstream 422 response.
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}Account, model, or upstream request limit. OpenAI-shaped account-limit errors use rate_limit_exceeded.
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}Headers
Section titled “Headers”Seconds before retrying, when a delay is available.
Gateway internal error (internal_error).
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}Upstream connection failure (upstream_connect_failed).
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}The credit service, guardrail policy, or model serving is unavailable.
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}Headers
Section titled “Headers”Seconds before retrying, when a delay is available.
Upstream timeout (upstream_timeout) or idle stream timeout (upstream_stream_idle_timeout).
OpenAI-shaped gateway error. Image errors after dispatch may also include billing fields at the top level.
object
object
Machine-readable error code. Account request limits use rate_limit_exceeded.
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
object
object
Gateway request identifier.
Gemini-shaped gateway error. Billing fields are included after dispatch.
object
object
Gateway request identifier.
Settled charge in nano-dollars; present when billing_status is settled.
Example
{ "billing_status": "settled"}