Skip to main content
By default, query() launches the bundled qodercli locally. Pass options.experimental_cloud_agent and the SDK switches to the Qoder Cloud Agent runtime instead — the agent and session run in a Qoder Cloud container, while the local process 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
Local-CLI-only capabilities — mcp_servers / settings / hooks / plugins / local permissions / checkpoint — are not available under the Cloud runtime; passing any of them throws synchronously.

Prerequisites

  • Personal Access Token (PAT): generated at qoder.com/account/integrations; see SDK Authentication. The Cloud runtime accepts only access_token() / access_token_from_env(). Passing qodercli_auth() / job_token() throws 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:
When the turn finishes, read session_id from the final ResultMessage — later turns use it to resume the same session (see Multi-turn: resuming a session).

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 context lives in the Cloud, so the script can restart or move between machines between turns — as long as you have the session_id, you can resume.

Using QoderSDKClient for multi-turn conversations

QoderSDKClient provides a higher-level Cloud session management — connect() creates/resolves the Cloud session, subsequent query() calls reuse it per turn, without needing to manually track session_id:
Note: The Cloud runtime does not support client.set_model(), client.reload_plugins(), MCP OAuth, or other local-CLI control methods — calling them raises ValueError.

Consuming SSE events

The Cloud runtime streams session events back over SSE. The SDK wraps each event as a CloudAgentEventMessage message:
Event shape (CloudAgentEventMessage fields):

History replay isolation

When resuming an existing session, the SSE stream first replays history events. The SDK isolates by turn_id: only the current turn’s session.status_idle triggers the ResultMessage terminal — historical events will not end your query early.

SSE tuning

Compatibility: afterId / deltaFlushIntervalMs (camelCase) are also accepted at runtime.

Abnormal close

If SSE disconnects before the current turn reaches a terminal event, the SDK synthesizes an error ResultMessage (subtype != 'success', is_error=True) so callers can handle it uniformly.

The ResultMessage terminal

Constraints at a glance

  • agent and session each have their own id / create — they are mutually exclusive.
  • When passing an existing session["id"], do not also pass agent.
  • session["create"] must include environment_id explicitly.
  • The Cloud runtime rejects local-CLI-only top-level options: model, agent, mcp_servers, settings, hooks, plugins, permission_mode, etc. Passing any of them throws synchronously.
  • The Cloud runtime does not support QoderSDKClient.set_model(), reload_plugins(), MCP OAuth, etc. Only async for consumption and close() are guaranteed.

Error codes