---
title: "Create an agent."
method: POST
path: "/v1/agents"
tags: ["agents"]
---

# Create an agent.

`POST /v1/agents`

## Request

- Base URL: `https://api.smolmachines.com`
- URL: `https://api.smolmachines.com/v1/agents`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/smolmachines/apis/smolfleet-api/docs/v1/agents/post.ts> (a function with typed inputs; its response is checked against the schema)

Creates a managed agent and the machine it runs in. Requires the `machine:create` scope.

## Request body

- CreateAgentRequest: Start a managed agent session: a harness (Claude Code, Codex, OpenCode, or any program) in its own machine, driven as a sequence of turns.
  - `allowHosts` string[]: Hosts the agent may reach beyond its model provider and package registry. The `command` harness has neither, so callers must name hosts or explicitly opt into unrestricted outbound access.
  - `arch` string, nullable: `amd64` or `arm64`. A session with checkpoints runs on amd64 unless pinned here.
  - `checkpoints` boolean, nullable: Checkpoint after every turn so the session can be rewound or branched (default true).
  - `cpus` integer, nullable: vCPUs (default 2).
  - `credential` string, nullable: A stored credential holding the model API key. The session's machine then never holds the key: the agent sees a placeholder and the node substitutes the key on requests to the provider, so turns need no key in their `env`. Its variable must be the one the harness reads (e.g. `ANTHROPIC_API_KEY`) and its hosts must include the provider's.
  - `harness` string, nullable: `claude-code` (default), `codex`, `opencode`, or `command`.
  - `image` string, nullable: Image for the `command` harness.
  - `memoryMb` integer, nullable: Memory in MiB (default 2048).
  - `model` string, nullable: Model: optional for `codex`, required as `provider/model` for `opencode`.
  - `name` string, required: Session name, unique within the account.
  - `openNetwork` boolean: Allow all outbound traffic instead of the host allow-list.
  - `program` string[]: Program for the `command` harness; the prompt is appended.

## Response `202`

Session created; its machine and harness are set up in the background (status `starting`, then `ready` or `failed`)

- AgentInfo: A managed agent session.
  - `createdAt` string, required
  - `error` string, nullable
  - `harness` string, required
  - `machineId` string, nullable: The machine the session currently runs on (it changes on rewind).
  - `model` string, nullable
  - `name` string, required
  - `runningTurn` integer, nullable: The turn in progress, if any.
  - `status` string, required: `starting` during setup, `turning` during a turn, `cancelling`, `rewinding`, `forking`, `pausing`, `resuming`, `ready`, `deleting`, or `failed`; stale work may read as `interrupted`.
  - `turns` AgentTurnInfo[], required
    - `checkpointed` boolean, required: Whether the session can be rewound or branched to this turn.
    - `costUsd` number, double, nullable: What the turn cost at the model provider, when the harness reports it.
    - `finishedAt` string, nullable
    - `index` integer, required
    - `isError` boolean, required
    - `prompt` string, required
    - `result` string, nullable: The agent's final answer, or why the turn failed.
    - `startedAt` string, required
    - `status` string, required: `preparing`, `running`, `cancelling`, `cancelled`, `done`, `failed`, or `interrupted`.

## Other responses

- `401`: Missing or invalid API key
- `403`: Key lacks the required scope
- `409`: A session with that name exists
- `429`: Rate limited; retry after the Retry-After header
- `500`: Internal error

## Changes

- **2026-10-16** `bc31fc04a568`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/smolmachines/apis/smolfleet-api/changes/v1/agents/post.md)

---

[API](https://skmtc.dev/smolmachines/apis/smolfleet-api.md) - [All operations](https://skmtc.dev/smolmachines/apis/smolfleet-api/llms.txt) - [OpenAPI document](https://skmtc.dev/smolmachines/apis/smolfleet-api/revisions/bc31fc04a568?raw)
