Common Patterns
Create an orchestration, add entity agents with clear role descriptions, then use the streaming endpoint. The coordinator handles delegation. Keep entity role descriptions specific and non-overlapping so the coordinator can route cleanly.Which key. CRUD, entity and hook routes require the project’s service role key. Four conversation routes also accept a signed-in user’s access token, scoped to that user’s own sessions and runs:
POST /api/orchestrations/{id}/run/stream, GET /api/orchestrations/runs/{run_id}, GET /api/orchestrations/{id}/sessions and GET /api/orchestrations/{id}/sessions/{session_id}/messages. See Which key for which route.CRUD
POST /api/orchestrations
Create an orchestration.GET /api/orchestrations
List all orchestrations.GET /api/orchestrations/
Get orchestration with its entities.string
required
Orchestration ID
PUT /api/orchestrations/
Update orchestration config.string
required
Orchestration ID
DELETE /api/orchestrations/
Delete an orchestration.string
required
Orchestration ID
Entities
POST /api/orchestrations//entities
Add an agent as an entity.string
required
Orchestration ID
string
required
Use
"agent". The route accepts any string ≤50 chars, but the orchestrator’s execution path only invokes entities where entity_type === "agent"; other values are stored but silently skipped at run time.string
required
UUID of the agent to add.
string
Free-text role hint shown to the coordinator when delegating. Replaces the prior
role field used in older docs examples.object
Per-entity overrides; defaults to
{}.integer
Sort order in list responses; defaults to
0.The route returns 400 if either
entity_type or entity_ref_id is missing. List/PUT responses key off entity_ref_id and role_description, so any client trying to round-trip will see the same field names.GET /api/orchestrations//entities
List entities in the orchestration.string
required
Orchestration ID
PUT /api/orchestrations//entities/
Update an entity. Onlyrole_description, config, and position are writable; any other top-level keys are silently ignored. entity_type and entity_ref_id are not updatable; create a new entity instead.
string
required
Orchestration ID
string
required
Entity ID
string
Free-text role hint shown to the coordinator when delegating.
object
Per-entity overrides.
integer
Sort order in list responses.
DELETE /api/orchestrations//entities/
Remove an entity.string
required
Orchestration ID
string
required
Entity ID
Execution
POST /api/orchestrations//run/stream
Run orchestration with streaming SSE. Includes delegation events. Acceptsruntime_knowledge_bases — the same query-scoped KB references as the agent streaming endpoint, with the same entry shape, validation, and 10-entry cap. The references flow to every sub-agent in the orchestration: each sub-agent’s knowledge_search tool merges them with its own attached KBs for this request only (a sub-agent with no attached KBs gains the tool for the run). One caveat differs per sub-agent: an entry’s max_context_tokens is honored only for sub-agents whose search tool resolves to exactly one KB.
With an end user’s access token, the same run-body limits apply as for agent runs: runtime_knowledge_bases, knowledge_bases, context_handler_id and by-reference context_items answer 403, and a session_id must name an existing orchestration session of that user’s (omit it to start a new one). There is no route to create an orchestration session up front; the first run creates it and returns its id. See Rules for end-user runs.
string
required
Orchestration ID
GET /api/orchestrations/runs/
Get orchestration run result. An end user can read only runs in their own orchestration sessions; anything else answers404.
string
required
Run ID
Hooks
These endpoints register hooks against an orchestration using the sameai.hooks model as agent hooks: event, type, config, matcher, enabled, and position.
POST /api/orchestrations//hooks
Add a hook.string
required
Orchestration ID
string
required
Lifecycle event name. Stored verbatim; not validated.
string
required
Hook handler type:
http, rule, or approval (see the agent hook contract).object
required
Handler-specific configuration (for
http, includes url).string
Optional filter narrowing when the hook fires.
boolean
Defaults to
true.integer
Execution order within the event. Defaults to
0.GET /api/orchestrations//hooks
List hooks for the orchestration, ordered byposition.
string
required
Orchestration ID
DELETE /api/orchestrations//hooks/
Remove a hook.string
required
Orchestration ID
string
required
Hook ID
Sessions
Session-level reads on orchestrations. The streaming/run/stream endpoint returns a session_id you can use here to fetch history.
GET /api/orchestrations//sessions
List the most recent 100 sessions for an orchestration (with an end user’s token, only that user’s own sessions). Each entry includessession_id, run_count, first_message, last_activity_at, and created_at.
string
required
Orchestration ID
GET /api/orchestrations//sessions//messages
Assembled messages for a session. Each assistant message carries per-run reasoning replay metadata (reasoning_requested, reasoning_duration_ms, reasoning, events) so a chat UI can re-render the original “Thought for X.Xs” pill on refresh. Tool calls are attached per-message via tool_calls. The legacy top-level events field is preserved for older clients.
string
required
Orchestration ID
string
required
Session ID
Error Responses
Orchestration routes return{"error": "<message>"} (no structured error code field).