Skip to main content

Cloud Agents API

The Cloud Agents API launches managed coding agents on isolated virtual machines in your Fluence account, sends them messages, streams their progress, and manages presets, environments, and AI profiles. For concepts, turns, idle stop, and pricing, see Cloud agents concepts.

The Cloud Agents endpoints use snake_case JSON fields, return bare JSON arrays for lists with the total count in the X-Total-Count response header (paged with limit and offset), and return errors as {"error": "..."}. See Errors.

Authentication and permissions​

Send an API key in the X-API-KEY header, or an access token in Authorization: Bearer. Send one of them, not both. See Authentication.

ToScope
Check identity, setup, models, VM sizes, defaults, environments, AI profiles, presets, instances, and read agents, events, messages, transcripts, logs, and contextagents:read
Everything agents:read allows, plus run launch preflight checks, launch agents from existing presets, send messages, interrupt turns, and stop agentsagents:run
Everything agents:run allows, plus create, edit, and delete presets, environments, secret declarations, AI profiles, keys, custom providers, subscriptions, cloud credentials, and provision or retire machinesagents:write

Before calling /v3/agents/..., connect Cloud agents to your account in the Fluence Console. See Launch your first cloud agent.

The examples read your API key from the FLUENCE_API_KEY environment variable:

export FLUENCE_API_KEY=<YOUR_API_KEY>

Discovery and setup status​

MethodPathWhat it does
GET/v3/agents/whoamiReturns the resolved identity (role, sub, tenant) without modifying anything
GET/v3/agents/setupLists ordered setup steps with ready and each step's state (done, todo, waits_for_human, rejected)
GET/v3/agents/modelsLists models available across your live agent machines (one row per model per machine)
GET/v3/agents/vm-sizesLists published VM size classes sold in a cluster with cores, memory_mb, disk_gb, default, and hourly price
GET/v3/agents/agent-defaultsReturns the deployment defaults and bounds for budget_seconds, stall_timeout_seconds, on_stall, idle_timeout, and token limits

Check your credentials and setup readiness before launching your first agent:

curl https://api.fluence.dev/v3/agents/whoami \
-H "X-API-KEY: $FLUENCE_API_KEY"
curl https://api.fluence.dev/v3/agents/setup \
-H "X-API-KEY: $FLUENCE_API_KEY"

GET /v3/agents/setup never returns secret values. When ready is true, your account has the credentials, providers, and preset needed to run POST /v3/agents/agents/check and launch an agent.

Presets and subagents​

Every agent launches from a preset and freezes a copy of that preset, its environment version, and its AI profile at launch. Editing or deleting a preset never affects agents already launched from it. See Create and edit presets.

MethodPathWhat it does
GET/v3/agents/presetsLists your live presets, oldest first (limit, offset, X-Total-Count)
POST/v3/agents/presetsCreates a preset and validates all fields, secrets, and models
GET/v3/agents/presets/{id}Returns one live preset
PATCH/v3/agents/presets/{id}Updates named fields (null clears optional fields; omitted fields stay as stored)
DELETE/v3/agents/presets/{id}Soft-deletes a preset and frees its name (does not affect running agents or the environment)

POST /v3/agents/presets requires name (unique among your live presets) and environment (environment ID or name). Optional fields:

  • ai_profile: AI profile ID or name (absent or null resolves to your account's default profile at launch).
  • default_model: default provider/model when a launch request omits model.
  • repo_url: default https:// repository URL without credentials.
  • prompt: default first task text (non-blank when present).
  • preamble: fixed instructions prepended before the first prompt of every launch (non-blank when present; does not replace prompt).
  • config: VM settings, including vm_size, cluster, idle_timeout (seconds or "disabled"), skills_repos, mcp_servers (each with name, url, optional secret_ref, and secret_header: bearer or x-api-key), and web_search (boolean, default true).
  • plugins: up to 100 OpenCode plugin declarations.
  • subagents: map of up to 16 named helper roles (role to { model, description?, prompt? }).

Create a preset with a subagent:

curl -X POST https://api.fluence.dev/v3/agents/presets \
-H "X-API-KEY: $FLUENCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "backend-review",
"environment": "<environment_id_or_name>",
"default_model": "openai/gpt-5.4",
"config": {
"vm_size": "medium",
"idle_timeout": 3600
},
"subagents": {
"reviewer": {
"model": "zai/glm-5.4",
"description": "Reviews diffs for edge cases and missing tests.",
"prompt": "Focus on correctness, error handling, and test coverage."
}
}
}'

Subagent rules​

  • At most 16 subagents per preset.
  • Each role name must match ^[a-z0-9][a-z0-9_-]{0,63}$.
  • Five role names are reserved for the coding agent itself and refused with 422: build, plan, general, explore, and default.
  • model is required, non-blank, and formatted as provider/model. It must be available under the preset's AI profile through an API key or custom provider. Models reached through a subscription (such as ChatGPT or Claude subscriptions) are refused with 422 for subagents. An unavailable model returns 422 with model_not_available naming subagents.<role>.
  • description is optional, non-blank when present, and up to 512 characters.
  • prompt is optional, non-blank when present, and up to 16 KiB (16,384 bytes of UTF-8).

Update or clear subagents with PATCH /v3/agents/presets/{id}:

  • Omit subagents to leave existing subagents unchanged.
  • Send a new subagents object to replace the entire map.
  • Send "subagents": null to remove all subagents.
curl -X PATCH https://api.fluence.dev/v3/agents/presets/<preset_id> \
-H "X-API-KEY: $FLUENCE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"subagents": null}'

Both GET /v3/agents/presets and GET /v3/agents/presets/{id} return the full subagents map (model, description, and prompt), and omit subagents when the preset has none.

Run and control an agent​

MethodPathWhat it does
POST/v3/agents/agents/checkPreflight check for a launch body; returns findings without creating a machine
POST/v3/agents/agentsLaunches an agent (requires Idempotency-Key; returns 202)
GET/v3/agents/agentsLists your agents, newest first (limit, offset, instance_id, label=key=value)
GET/v3/agents/agents/{agent_id}Returns one agent with full launch details
GET/v3/agents/agents/{agent_id}/eventsReads turn events as paged JSON or streams them over SSE (Accept: text/event-stream)
GET/v3/agents/agents/{agent_id}/messagesLists message receipts for the agent in sequence order
POST/v3/agents/agents/{agent_id}/messagesSends a message with steer or queue delivery (requires Idempotency-Key; returns 202)
GET/v3/agents/agents/{agent_id}/messages/{message_id}Returns one message receipt
GET/v3/agents/agents/{agent_id}/transcriptReturns the plain-text transcript snapshot
GET/v3/agents/agents/{agent_id}/logReturns the technical phase log (provision, register, outcome)
GET/v3/agents/agents/{agent_id}/contextReturns token measurements from the last completed model request
POST/v3/agents/agents/{agent_id}/interruptStops the running turn and leaves the agent idle for the next message
POST/v3/agents/agents/{agent_id}/stopStops the agent, cancels unrun messages, and releases its machine

Preflight check​

Call POST /v3/agents/agents/check with the same JSON body you plan to send to POST /v3/agents/agents. It returns 200 with {"findings": [...]} without launching or reserving a machine. An empty list means no blockers were found. Finding codes include repo_credentials_missing, repo_access_denied, repo_not_found, forge_unreachable, size_not_sold, and size_unknown.

Launch an agent​

POST /v3/agents/agents requires an Idempotency-Key header and a JSON body with preset (preset ID or name). Repeating the same key with the same body returns the same agent; sending a different body with the same key returns 409.

Key optional body fields:

  • prompt: first task message. Required unless the preset defines prompt.
  • model: provider/model. Required unless the preset defines default_model.
  • repo_url: HTTPS repository URL without credentials. Omit to use the preset's repo_url, or pass without_repo: true to start in an empty working directory (cannot be combined with repo_url).
  • name: up to 128 UTF-8 bytes on one line, immutable after launch.
  • labels: up to 16 key/value pairs (keys a-z, 0-9, ., _, -; values also allow A-Z; 1 to 63 characters each), filterable with GET /v3/agents/agents?label=key=value.
  • budget_seconds: per-turn time limit in seconds (within GET /v3/agents/agent-defaults bounds) or "unlimited".
  • stall_timeout_seconds: silence cutoff in seconds or "disabled".
  • on_stall: "interrupt" (default, cuts the turn and leaves the agent idle) or "stop" (stops the agent and its machine).
  • max_turn_tokens and max_total_tokens: per-turn and lifetime token caps, or "unlimited".
curl -X POST https://api.fluence.dev/v3/agents/agents \
-H "X-API-KEY: $FLUENCE_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: launch-pr-audit-1" \
-d '{
"preset": "backend-review",
"name": "audit-pr-42",
"repo_url": "https://github.com/owner/repo",
"prompt": "Review PR #42 for regressions and run the test suite.",
"labels": {
"repo": "owner-repo",
"kind": "review"
},
"budget_seconds": 3600
}'

The API answers 202 with agent_id and state.

Agent states and reading an agent​

Poll GET /v3/agents/agents/{agent_id} to track state, last_turn, failure, price, and launch. An agent moves through these states:

StateMeaning
pendingAccepted and waiting to start
preparingProvisioning or initializing the machine, repository, and extensions
activeRunning a turn
idleWaiting for the next message (stops automatically after idle_timeout)
stoppingStopping the agent and releasing its machine
endedStopped cleanly (terminal)
failedLaunch or runtime failed; failure.code and failure.detail explain why (terminal)

GET /v3/agents/agents omits launch.prompt, launch.preamble, and each subagent's description and prompt (returning only model under launch.subagents). Call GET /v3/agents/agents/{agent_id} to read the full launch fields.

Read events, transcript, logs, and context​

GET /v3/agents/agents/{agent_id}/events returns turn events in ascending number order (starting at 1):

  • JSON polling (default): pass after=<number> (start with 0), optional limit, and optional comma-separated kinds (turn_started, agent_text, tool_called, tool_returned, turn_continued, turn_ended, ci_loop_exhausted). Pass the last returned number back as after for the next page.
  • SSE streaming: send Accept: text/event-stream. Each persisted event carries its number as the SSE id; reconnect with Last-Event-ID to resume. While a turn runs, the stream also emits transient text_delta events (without an id) as the agent writes text.
curl "https://api.fluence.dev/v3/agents/agents/<agent_id>/events?after=0&kinds=agent_text,turn_ended" \
-H "X-API-KEY: $FLUENCE_API_KEY"

Additional inspection endpoints:

  • GET /v3/agents/agents/{agent_id}/transcript: downloads the full plain-text transcript snapshot.
  • GET /v3/agents/agents/{agent_id}/log: reads technical lifecycle phase entries (provision, register, outcome) with status (started, ok, error).
  • GET /v3/agents/agents/{agent_id}/context: reads the last completed model request's input_tokens, context_limit_tokens, and compaction_threshold_tokens.

Send a message​

POST /v3/agents/agents/{agent_id}/messages requires an Idempotency-Key header and a JSON body with text, optional delivery, and optional numeric budget_seconds. It answers 202 with message_id and delivery_state.

How delivery interacts with a running turn:

  • steer (default when omitted or null): enters the running turn at its next step boundary and keeps that turn's budget. If the running turn is cut (interrupted, or past its budget or silence limit) before the steer message runs, the message is recorded failed with code not_executed.
  • queue: leaves the running turn alone and runs as its own turn after it, in acceptance order, with its own budget_seconds and last_turn. The agent reads a queue message only after the running turn ends, so a delivered state under queue means waiting for its turn, not yet read. If the running turn is cut, queue messages are kept and run next.

To an idle agent, both steer and queue start a new turn immediately. When an agent is stopped, no unrun message runs.

curl -X POST https://api.fluence.dev/v3/agents/agents/<agent_id>/messages \
-H "X-API-KEY: $FLUENCE_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: msg-2" \
-d '{
"text": "Also add unit tests for the empty input case.",
"delivery": "queue",
"budget_seconds": 1800
}'

Track delivery status with GET /v3/agents/agents/{agent_id}/messages or GET /v3/agents/agents/{agent_id}/messages/{message_id}.

Interrupt or stop an agent​

  • Interrupt a turn (POST /v3/agents/agents/{agent_id}/interrupt): stops the active turn and keeps the agent and its machine idle on the same conversation. Answers 202 (outcome: "interrupting") when stopping a turn, or 200 (outcome: "nothing_to_interrupt") when idle. Any unrun steer messages are marked failed with not_executed; queue messages stay and run next.
  • Stop an agent (POST /v3/agents/agents/{agent_id}/stop): stops the agent, cancels all unrun messages, and releases its machine. Answers 202 while stopping, or 200 if already terminal (ended or failed).
curl -X POST https://api.fluence.dev/v3/agents/agents/<agent_id>/stop \
-H "X-API-KEY: $FLUENCE_API_KEY"

Tenant configuration endpoints​

Beyond presets and agents, /v3/agents exposes endpoints to automate your account setup (all paths under https://api.fluence.dev/v3/agents, documented in full in the OpenAPI document):

ResourceMethods and pathsWhat it manages
AI providers catalogGET /ai-providersLists known API-key and subscription providers
AI profilesGET, POST /ai-profiles, GET, PATCH, DELETE /ai-profiles/{id}, POST /ai-profiles/{id}/copy, GET /ai-profiles/{id}/modelsManage AI profiles, clone keys and custom providers, and list models a profile can run
Provider API keysPUT, DELETE /ai-profiles/{id}/keys/{provider}Set or remove keys for known providers (openai, zai, openrouter, fluence)
Custom AI providersGET, POST /ai-profiles/{id}/providers, GET, PATCH, DELETE /ai-profiles/{id}/providers/{provider_id}, POST /ai-profiles/{id}/provider-declarationsAdd, update, remove, or declare OpenAI-compatible or Anthropic-compatible custom endpoints (custom-<name>)
AI subscriptionsGET, POST /ai-profiles/{id}/subscriptions, PATCH, DELETE /ai-profiles/{id}/subscriptions/{subscription_id}Start device login, select an active subscription, or remove a subscription
EnvironmentsGET, POST /environments, GET, PATCH, DELETE /environments/{id}, GET /environments/{id}/versionsManage versioned secret sets for GitHub tokens and named secrets (values are write-only)
Secret declarationsPOST /environment-declarations, GET /environments/{id}/secret-declarations, PUT, DELETE /environments/{id}/secret-declarations/{name}Declare environments and required secret names without sending secret values over the API
Cloud credentialsGET /cloud-credentials, PUT, DELETE /cloud-credentials/{provider}, GET /cloud-credentials/{provider}/clustersManage stored cloud credentials and list available clusters
Instances and provisioningGET /instances, GET, DELETE /instances/{id}, POST /provision, GET /provisions/{id}Inspect agent VMs, start provisioning jobs, or retire a billed VM (DELETE answers 202; poll GET /instances/{id} until retired)

Errors​

Cloud Agents endpoints return a JSON object with an error message:

{"error": "missing credential: X-API-KEY or Authorization: Bearer"}

Common HTTP statuses:

StatusMeaning
400Malformed request or invalid query parameter (such as a negative after or limit below 1)
401Credentials are missing, invalid, or expired
403Credentials lack the needed scope (agents:read, agents:run, or agents:write)
404The preset, agent, environment, AI profile, or instance does not exist in your account
409State or idempotency conflict: reused Idempotency-Key with a different body, duplicate preset or profile name, concurrent preset edit, agent not accepting messages, or a preset whose environment, AI profile, secret, subscription, or subagent model no longer holds at launch
422Validation failure: invalid field, unknown field, without_repo sent with repo_url, missing secret, invalid subagent role or limit, subscription model used on a subagent, or model_not_available (for a subagent, the message begins with model_not_available: subagents.<role>:)
429Admission limit reached (too many concurrent agents or event streams)
502Upstream secret store or cloud provider failed to answer. Retry later.
503Temporary unavailability (for example, machine catalog, transcript, or controller busy; check Retry-After when present)