query() starts the bundled qodercli locally by default. With the cloud agent option (TypeScript's options.experimentalCloudAgent, Python's options.experimental_cloud_agent), the SDK switches to the Qoder Cloud Agent runtime—agents and sessions run in Qoder Cloud containers while the local side only sends requests and consumes the SSE event stream.
Status: experimental / unstable. The API shape may change between minor versions; do not depend on unreleased fields in production code paths.
When to use
- You don't want to manage qodercli, the bundled binary, or a local runtime
- You need a long-lived agent reused across machines (the agent is persisted in the Cloud)
- You want session context to live in the Cloud so multiple processes / hosts can resume it
settings / hooks / plugins / local permissions / checkpointing—are unsupported on the Cloud runtime; passing them throws synchronously.
Prerequisites
- Personal Access Token (PAT): generate at qoder.com/account/integrations; see SDK Authentication. The Cloud runtime only accepts access-token auth (
accessToken()/accessTokenFromEnv(); Python:access_token()/access_token_from_env()); local login state or job tokens fail synchronously. - Cloud
environment_id: required when creating a session. Get it from the Qoder console or the management API.
First call: create agent + create session
The most common entry path — create a new Cloud Agent and immediately open a session for it to run a prompt:
session_id from the final result message—later turns can continue this session with it (see Multi-turn).
Built-in tool allowlist
tools[].enabled_tools currently supports: bash, write, glob, web_fetch, read, edit, grep, web_search. Omit tools to give the agent no tools.
Mounting files into a session
After uploading a file via the Files API, mount it into the session container with session.create.resources:
Reusing an existing agent
If you already have an agent.id (created via the console or a previous call), pass agent: { id } and skip create:
Multi-turn: resuming a session
Once you have a session_id from the first turn, the next call passes only session: { id } — do not include agent. The session already binds an agent, and combining the two throws synchronously.
session_id, you can resume.
Multi-turn conversation with QoderSDKClient (Python)
Python's QoderSDKClient offers higher-level Cloud session management—connect() creates/resolves the Cloud session, and later query() calls reuse it turn by turn with no manual session_id tracking:
Note: The Cloud runtime does not supportclient.set_model(),client.reload_plugins(), MCP OAuth, or other local-CLI control methods — calling them raisesValueError.
Consuming SSE events
The Cloud runtime pushes the session's event stream back over SSE. The SDK wraps each event as a cloud agent event message (TypeScript: cloud_agent_event; Python: CloudAgentEventMessage):
| Field | Description |
|---|---|
event | Cloud event name (e.g. user.message, agent.message, session.status_idle) |
id | Event ID in the SSE stream; usable as a replay anchor |
data | Cloud event payload (includes turn_id and other fields) |
uuid (Python) | SDK-generated unique ID for deduplication |
session_id | Cloud session ID this event belongs to |
History replay isolation
When reusing an existing session, SSE first replays past turns' events—the SDK isolates by turn_id: only the current turn's session.status_idle produces the terminal result; historical events won't end your query early.
SSE tuning
Compatibility: in Python,afterId/deltaFlushIntervalMs(camelCase) are also accepted and recognized at runtime.
Abnormal close
If SSE disconnects before the current turn reaches a terminal state, the SDK synthesizes an error result (subtype != 'success', is_error: true) for uniform upstream handling.
Terminal state: contents of the result
| Field | Description |
|---|---|
subtype | success or an error subtype |
is_error | Boolean; whether the turn ended abnormally |
session_id | Cloud session ID (backfilled by the SDK on the create branch) |
result | Agent's text reply for the turn (multiple text blocks are concatenated) |
usage / model usage / total_cost_usd | Backfilled from the current turn's span.model_request_end.usage |
Constraints at a glance
agentandsessioneach treatid/createas mutually exclusive (enforced by TypeScript union types).- When passing an existing
session.id, do not also passagent. session.createmust includeenvironment_idexplicitly.- The Cloud runtime doesn't support local CLI top-level options:
model,agent, MCP servers,settings,hooks,plugins, permission modes, etc. throw synchronously. - The Cloud runtime doesn't support model switching, plugin reloads, MCP OAuth, or other runtime control methods—only iterating messages and closing the session (TypeScript's
q.close(), Python'sclient.disconnect()).
Error codes
| TypeScript code / Python exception | Trigger |
|---|---|
cloud_agent_auth_requires_access_token / CloudAgentUnsupportedAuthError | Non-PAT auth such as local login state / job token |
cloud_agent_api_error / CloudAgentApiError | Cloud OpenAPI non-2xx, or SSE channel failure |
Related docs
- SDK Authentication — PAT acquisition and environment variables
- Input Modes — single-message and streaming input in the local SDK
- API References — full fields of the cloud agent option and event messages

