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.
- Base URL:
https://api.fluence.dev. Every path on this page starts with/v3/agents. - API reference: api.fluence.dev/scalar
- OpenAPI document: api.fluence.dev/v3/agents/openapi.json
- MCP tools: Connect an AI client through MCP
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.
| To | Scope |
|---|---|
| Check identity, setup, models, VM sizes, defaults, environments, AI profiles, presets, instances, and read agents, events, messages, transcripts, logs, and context | agents:read |
Everything agents:read allows, plus run launch preflight checks, launch agents from existing presets, send messages, interrupt turns, and stop agents | agents: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 machines | agents: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
| Method | Path | What it does |
|---|---|---|
GET | /v3/agents/whoami | Returns the resolved identity (role, sub, tenant) without modifying anything |
GET | /v3/agents/setup | Lists ordered setup steps with ready and each step's state (done, todo, waits_for_human, rejected) |
GET | /v3/agents/models | Lists models available across your live agent machines (one row per model per machine) |
GET | /v3/agents/vm-sizes | Lists published VM size classes sold in a cluster with cores, memory_mb, disk_gb, default, and hourly price |
GET | /v3/agents/agent-defaults | Returns 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.
| Method | Path | What it does |
|---|---|---|
GET | /v3/agents/presets | Lists your live presets, oldest first (limit, offset, X-Total-Count) |
POST | /v3/agents/presets | Creates 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 ornullresolves to your account's default profile at launch).default_model: defaultprovider/modelwhen a launch request omitsmodel.repo_url: defaulthttps://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 replaceprompt).config: VM settings, includingvm_size,cluster,idle_timeout(seconds or"disabled"),skills_repos,mcp_servers(each withname,url, optionalsecret_ref, andsecret_header:bearerorx-api-key), andweb_search(boolean, defaulttrue).plugins: up to 100 OpenCode plugin declarations.subagents: map of up to 16 named helper roles (roleto{ 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": "openai/gpt-5-mini",
"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, anddefault. modelis required, non-blank, and formatted asprovider/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 with422for subagents. An unavailable model returns422withmodel_not_availablenamingsubagents.<role>.descriptionis optional, non-blank when present, and up to 512 characters.promptis 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
subagentsto leave existing subagents unchanged. - Send a new
subagentsobject to replace the entire map. - Send
"subagents": nullto 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
| Method | Path | What it does |
|---|---|---|
POST | /v3/agents/agents/check | Preflight check for a launch body; returns findings without creating a machine |
POST | /v3/agents/agents | Launches an agent (requires Idempotency-Key; returns 202) |
GET | /v3/agents/agents | Lists 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}/events | Reads turn events as paged JSON or streams them over SSE (Accept: text/event-stream) |
GET | /v3/agents/agents/{agent_id}/messages | Lists message receipts for the agent in sequence order |
POST | /v3/agents/agents/{agent_id}/messages | Sends 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}/transcript | Returns the plain-text transcript snapshot |
GET | /v3/agents/agents/{agent_id}/log | Returns the technical phase log (provision, register, outcome) |
GET | /v3/agents/agents/{agent_id}/context | Returns token measurements from the last completed model request |
POST | /v3/agents/agents/{agent_id}/interrupt | Stops the running turn and leaves the agent idle for the next message |
POST | /v3/agents/agents/{agent_id}/stop | Stops 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 definesprompt.model:provider/model. Required unless the preset definesdefault_model.repo_url: HTTPS repository URL without credentials. Omit to use the preset'srepo_url, or passwithout_repo: trueto start in an empty working directory (cannot be combined withrepo_url).name: up to 128 UTF-8 bytes on one line, immutable after launch.labels: up to 16 key/value pairs (keysa-z,0-9,.,_,-; values also allowA-Z; 1 to 63 characters each), filterable withGET /v3/agents/agents?label=key=value.budget_seconds: per-turn time limit in seconds (withinGET /v3/agents/agent-defaultsbounds) or"unlimited".stall_timeout_seconds: silence cutoff in seconds or"disabled".on_stall:"interrupt"(default, cuts the turn and leaves the agentidle) or"stop"(stops the agent and its machine).max_turn_tokensandmax_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:
| State | Meaning |
|---|---|
pending | Accepted and waiting to start |
preparing | Provisioning or initializing the machine, repository, and extensions |
active | Running a turn |
idle | Waiting for the next message (stops automatically after idle_timeout) |
stopping | Stopping the agent and releasing its machine |
ended | Stopped cleanly (terminal) |
failed | Launch 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 with0), optionallimit, and optional comma-separatedkinds(turn_started,agent_text,tool_called,tool_returned,turn_continued,turn_ended,ci_loop_exhausted). Pass the last returnednumberback asafterfor the next page. - SSE streaming: send
Accept: text/event-stream. Each persisted event carries itsnumberas the SSEid; reconnect withLast-Event-IDto resume. While a turn runs, the stream also emits transienttext_deltaevents (without anid) 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) withstatus(started,ok,error).GET /v3/agents/agents/{agent_id}/context: reads the last completed model request'sinput_tokens,context_limit_tokens, andcompaction_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 ornull): 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 thesteermessage runs, the message is recordedfailedwith codenot_executed.queue: leaves the running turn alone and runs as its own turn after it, in acceptance order, with its ownbudget_secondsandlast_turn. The agent reads aqueuemessage only after the running turn ends, so adeliveredstate underqueuemeans waiting for its turn, not yet read. If the running turn is cut,queuemessages 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 machineidleon the same conversation. Answers202(outcome: "interrupting") when stopping a turn, or200(outcome: "nothing_to_interrupt") when idle. Any unrunsteermessages are markedfailedwithnot_executed;queuemessages 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. Answers202while stopping, or200if already terminal (endedorfailed).
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):
| Resource | Methods and paths | What it manages |
|---|---|---|
| AI providers catalog | GET /ai-providers | Lists known API-key and subscription providers |
| AI profiles | GET, POST /ai-profiles, GET, PATCH, DELETE /ai-profiles/{id}, POST /ai-profiles/{id}/copy, GET /ai-profiles/{id}/models | Manage AI profiles, clone keys and custom providers, and list models a profile can run |
| Provider API keys | PUT, DELETE /ai-profiles/{id}/keys/{provider} | Set or remove keys for known providers (openai, zai, openrouter, fluence) |
| Custom AI providers | GET, POST /ai-profiles/{id}/providers, GET, PATCH, DELETE /ai-profiles/{id}/providers/{provider_id}, POST /ai-profiles/{id}/provider-declarations | Add, update, remove, or declare OpenAI-compatible or Anthropic-compatible custom endpoints (custom-<name>) |
| AI subscriptions | GET, POST /ai-profiles/{id}/subscriptions, PATCH, DELETE /ai-profiles/{id}/subscriptions/{subscription_id} | Start device login, select an active subscription, or remove a subscription |
| Environments | GET, POST /environments, GET, PATCH, DELETE /environments/{id}, GET /environments/{id}/versions | Manage versioned secret sets for GitHub tokens and named secrets (values are write-only) |
| Secret declarations | POST /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 credentials | GET /cloud-credentials, PUT, DELETE /cloud-credentials/{provider}, GET /cloud-credentials/{provider}/clusters | Manage stored cloud credentials and list available clusters |
| Instances and provisioning | GET /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:
| Status | Meaning |
|---|---|
400 | Malformed request or invalid query parameter (such as a negative after or limit below 1) |
401 | Credentials are missing, invalid, or expired |
403 | Credentials lack the needed scope (agents:read, agents:run, or agents:write) |
404 | The preset, agent, environment, AI profile, or instance does not exist in your account |
409 | State 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 |
422 | Validation 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>:) |
429 | Admission limit reached (too many concurrent agents or event streams) |
502 | Upstream secret store or cloud provider failed to answer. Retry later. |
503 | Temporary unavailability (for example, machine catalog, transcript, or controller busy; check Retry-After when present) |