Examples
Every example on this page is self-contained: it includes imports, environment setup, and error handling so you can copy a single block and run it. Set these first:
All requests use model: "auto" �?there is no model environment variable. Base URLs come from Environments.
Chat Completions
TypeScript
Go
Responses
TypeScript
Go
Anthropic Messages
TypeScript
Go
Streaming
Streaming works for Chat Completions, Responses, and Anthropic Messages. The examples below stream Chat Completions.
TypeScript
Go
Orchestration
A model: "auto" request may be routed into orchestration (multi-task planning) mode. The gateway splits the request into subtasks, runs them, and aggregates the result. The SDK returns the raw gateway shape, so you branch on it:
choices[0].message.contentis a JSON-encoded array of per-task outputs ({ "title", "content" }), not a plain string �?parse it before rendering. The top-levelplanfield confirms orchestration mode.metadatais an array with one entry per task, including the reserved__planner__(task_seq: 0) and__final__(task_seq: 4) entries. Sumbilling.credits_usedacross entries for the total cost.- When streaming, a planning event arrives first (a chunk whose
orchestration.phaseisplanning, carrying the orderedplan), followed by the__planner__metadata event. Then each task’s full content arrives as a chunk that carries anorchestrationfield (task_id,task_seq,task_status,title), each followed by one standalone metadata event (a single object, not an array), before[DONE].
See Routing for the full field reference.
TypeScript
Go
Model list
TypeScript
Go
Use { locale: "zh" } for Chinese descriptions; omitting locale defaults to English. Catalog entries live in models.data.models.
Error handling
TypeScript
Go
Run the example project
TypeScript
Go
The live example and Client SDK requests always use model: "auto"; there is no model environment variable.
