---
title: "Start an agent run in a space"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Start an agent run in a space

Path: CloudRaker Paperwork API › Spaces

`POST /v1/spaces/{spaceId}/agents`

Starts an agent inside this space: the run and its input files live there, so anything the agent files stays after the run ends.

Same body, same wait semantics and same run object as `POST /v1/agent-runs` — read the run back at `GET /v1/spaces/{spaceId}/agents/{runId}`, and steer, approve or cancel it on the ordinary `/v1/agent-runs/{id}` routes.

**Learn more:** [Spaces](https://docs.cloudraker.com/paperwork/developers/spaces)

## Authentication

- `bearerAuth`, http, header `Authorization`

## Path parameters

- `spaceId` (`spaceCreateAgentRun.path.spaceId`; string, required)

## Query parameters

- `wait` (`spaceCreateAgentRun.query.wait`; integer, optional) — How many seconds to hold the request open. Releases early the moment the run finishes **or** blocks on a person. Maximum 120; `0` returns immediately.
  - min 0; max 120; default `60`

## Request body

_Required._

- `agent` (`spaceCreateAgentRun.agent`; string, required) — The agent to run, by id.
  - minLength 1
- `files` (`spaceCreateAgentRun.files`; array<any of>, required) — The files the agent works on, up to 200.
  - any of:
    - `object`
      - `url` (`spaceCreateAgentRun.files.1.url`; string, required)
        - format `uri`
      - `name` (`spaceCreateAgentRun.files.1.name`; string, optional)
        - minLength 1
      - `processing` (`spaceCreateAgentRun.files.1.processing`; string, optional)
        - one of `"auto"`, `"ocr"`, `"simple"`, `"transcribe"`, `"transcribe_diarize"`
    - `object`
      - `id` (`spaceCreateAgentRun.files.2.id`; string, required)
        - minLength 1
- `metadata` (`spaceCreateAgentRun.metadata`; map<unknown>, optional) — Arbitrary JSON you attach to the run and get back on every read of it. Use it to carry your own identifiers — an order number, a customer id — so a webhook or a polled run reconciles without a lookup table. Capped at 10 KB serialized.
- `webhook` (`spaceCreateAgentRun.webhook`; any of, optional) — Where to deliver this run's events, given one of two ways. - `{ "url": "…" }` — a one-off https endpoint for this run only. - `{ "id": "whe_…" }` — a saved endpoint from `POST /v1/webhooks`. Runs hold the reference, so pausing or re-pointing that endpoint applies to this run too. Deliveries are at-least-once and signed — dedupe on `eventId` and verify against `GET /v1/webhooks/jwks.json`.
  - any of:
    - `object`
      - `url` (`spaceCreateAgentRun.webhook.1.url`; string, required)
        - format `uri`
    - `object`
      - `id` (`spaceCreateAgentRun.webhook.2.id`; string, required)
        - minLength 1

## Example request

```json
{
  "agent": "string",
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "processing": "auto"
    }
  ],
  "metadata": {
    "property1": null,
    "property2": null
  },
  "webhook": {
    "url": "http://example.com"
  }
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://api.cloudraker.com/v1/spaces/<spaceId>/agents' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "agent": "string",
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "processing": "auto"
    }
  ],
  "metadata": {
    "property1": null,
    "property2": null
  },
  "webhook": {
    "url": "http://example.com"
  }
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/v1/spaces/<spaceId>/agents';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    agent: 'string',
    files: [{url: 'http://example.com', name: 'string', processing: 'auto'}],
    metadata: {property1: null, property2: null},
    webhook: {url: 'http://example.com'}
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/v1/spaces/<spaceId>/agents"

payload = {
    "agent": "string",
    "files": [
        {
            "url": "http://example.com",
            "name": "string",
            "processing": "auto"
        }
    ],
    "metadata": {
        "property1": None,
        "property2": None
    },
    "webhook": { "url": "http://example.com" }
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The finished run.

#### Example

```json
{
  "object": "agent_run",
  "id": "agr_01JQ8ZKMRT4V6WXYZ0ABCDEFGH",
  "agent": {
    "id": "string",
    "name": "string",
    "version": 0
  },
  "input": {
    "files": [
      {
        "id": "string"
      }
    ]
  },
  "status": "queued",
  "waiting": {
    "approvals": 0,
    "tasks": 0,
    "summary": "string"
  },
  "paused": {
    "reason": "model_error"
  },
  "progress": {
    "tasks": {
      "total": 0,
      "completed": 0
    }
  },
  "tasks": [
    {
      "id": "string",
      "title": "string",
      "executor": "agent",
      "status": "pending",
      "summary": "string",
      "note": "string",
      "completedAt": "string"
    }
  ],
  "approvals": [
    {
      "id": "string",
      "kind": "before",
      "action": "string",
      "requestedAt": "string",
      "rationale": "string",
      "files": [
        {
          "id": "string",
          "name": "string"
        }
      ],
      "params": {
        "property1": null,
        "property2": null
      }
    }
  ],
  "incomplete": true,
  "result": "string",
  "output": {
    "files": [
      {
        "id": "string",
        "name": "string",
        "url": "string"
      }
    ]
  },
  "error": {
    "code": "string",
    "message": "string"
  },
  "statusUrl": "string",
  "metadata": {
    "property1": null,
    "property2": null
  },
  "createdAt": "string",
  "expiresAt": "string",
  "finishedAt": "string"
}
```

- `object` (`spaceCreateAgentRun.response.200.object`; string, required)
- `id` (`spaceCreateAgentRun.response.200.id`; string, required)
  - example `"agr_01JQ8ZKMRT4V6WXYZ0ABCDEFGH"`
- `agent` (`spaceCreateAgentRun.response.200.agent`; object, required)
  - `id` (`spaceCreateAgentRun.response.200.agent.id`; string, required)
  - `name` (`spaceCreateAgentRun.response.200.agent.name`; string, required)
  - `version` (`spaceCreateAgentRun.response.200.agent.version`; number, required)
- `input` (`spaceCreateAgentRun.response.200.input`; object, required)
  - `files` (`spaceCreateAgentRun.response.200.input.files`; array<object>, required) — The immutable input file ids. Reuse these with `agent.id` to start a successor after a terminal run.
    - `id` (`spaceCreateAgentRun.response.200.input.files.id`; string, required)
- `status` (`spaceCreateAgentRun.response.200.status`; string, required) — Where the agent run is in its life. | Status | Meaning | | --- | --- | | `queued` | Accepted; its files are still being prepared | | `processing` | The agent is working | | `waiting` | Blocked on a person — see `waiting`, `approvals` and `tasks[]` | | `paused` | Stopped short of finishing and resumable; not a failure | | `completed` | Finished; `result` and `output` are populated | | `failed` | Finished without producing a result | | `cancelled` | Stopped on request | | `expired` | Reached its `expiresAt` without finishing | `completed`, `failed`, `cancelled` and `expired` are terminal. A `completed` run that still had outstanding work also carries `incomplete: true`.
  - one of `"queued"`, `"processing"`, `"waiting"`, `"paused"`, `"completed"`, `"failed"`, `"cancelled"`, `"expired"`
- `progress` (`spaceCreateAgentRun.response.200.progress`; object, required)
  - `tasks` (`spaceCreateAgentRun.response.200.progress.tasks`; object, required)
    - `total` (`spaceCreateAgentRun.response.200.progress.tasks.total`; number, required)
    - `completed` (`spaceCreateAgentRun.response.200.progress.tasks.completed`; number, required)
- `tasks` (`spaceCreateAgentRun.response.200.tasks`; array<object>, required)
  - `id` (`spaceCreateAgentRun.response.200.tasks.id`; string, required)
  - `title` (`spaceCreateAgentRun.response.200.tasks.title`; string, required)
  - `executor` (`spaceCreateAgentRun.response.200.tasks.executor`; string, required) — Who performs the step: `agent` runs by itself, `human` waits for a person to complete it.
    - one of `"agent"`, `"human"`
  - `status` (`spaceCreateAgentRun.response.200.tasks.status`; string, required) — Where this step stands. `pending` is blocked on its dependencies, `ready` is claimable, `skipped` satisfies anything waiting on it.
    - one of `"pending"`, `"ready"`, `"in_progress"`, `"completed"`, `"skipped"`
  - `summary` (`spaceCreateAgentRun.response.200.tasks.summary`; string | null, required)
  - `completedAt` (`spaceCreateAgentRun.response.200.tasks.completedAt`; string | null, required)
  - `note` (`spaceCreateAgentRun.response.200.tasks.note`; string, optional)
- `statusUrl` (`spaceCreateAgentRun.response.200.statusUrl`; string, required)
- `createdAt` (`spaceCreateAgentRun.response.200.createdAt`; string, required)
- `expiresAt` (`spaceCreateAgentRun.response.200.expiresAt`; string | null, required) — The run’s deadline: about seven days after it starts, an unfinished run parks itself for good and its `status` becomes `expired`. `null` once the run is finished. Files and anything the run already filed are never taken back.
- `finishedAt` (`spaceCreateAgentRun.response.200.finishedAt`; string | null, required)
- `waiting` (`spaceCreateAgentRun.response.200.waiting`; object, optional) — What is blocking the run. Present while `status` is `waiting`.
  - `approvals` (`spaceCreateAgentRun.response.200.waiting.approvals`; number, required)
  - `tasks` (`spaceCreateAgentRun.response.200.waiting.tasks`; number, required)
  - `summary` (`spaceCreateAgentRun.response.200.waiting.summary`; string, required)
- `paused` (`spaceCreateAgentRun.response.200.paused`; object, optional) — Why the run parked. Present while `status` is `paused`. A paused run keeps everything it produced and can be started again.
  - `reason` (`spaceCreateAgentRun.response.200.paused.reason`; string, required)
    - one of `"model_error"`, `"system_error"`
- `approvals` (`spaceCreateAgentRun.response.200.approvals`; array<object>, optional) — Sign-offs the run is waiting on, oldest first.
  - `id` (`spaceCreateAgentRun.response.200.approvals.id`; string, required)
  - `kind` (`spaceCreateAgentRun.response.200.approvals.kind`; string, required)
    - one of `"before"`, `"output"`
  - `action` (`spaceCreateAgentRun.response.200.approvals.action`; string, required)
  - `requestedAt` (`spaceCreateAgentRun.response.200.approvals.requestedAt`; string, required)
  - `files` (`spaceCreateAgentRun.response.200.approvals.files`; array<object>, required)
    - `id` (`spaceCreateAgentRun.response.200.approvals.files.id`; string, required)
    - `name` (`spaceCreateAgentRun.response.200.approvals.files.name`; string, required)
  - `rationale` (`spaceCreateAgentRun.response.200.approvals.rationale`; string | null, optional)
  - `params` (`spaceCreateAgentRun.response.200.approvals.params`; map<unknown>, optional) — The inputs proposed for the step, for a `before` approval.
- `incomplete` (`spaceCreateAgentRun.response.200.incomplete`; boolean, optional) — Present and `true` on a `completed` run that still had outstanding work — read `tasks[]` to see what.
- `result` (`spaceCreateAgentRun.response.200.result`; string, optional) — The agent's closing summary.
- `output` (`spaceCreateAgentRun.response.200.output`; object, optional) — Files attached to the run while its steps were completed, each with a signed download link valid for about an hour.
  - `files` (`spaceCreateAgentRun.response.200.output.files`; array<object>, required)
    - `id` (`spaceCreateAgentRun.response.200.output.files.id`; string, required)
    - `name` (`spaceCreateAgentRun.response.200.output.files.name`; string, required)
    - `url` (`spaceCreateAgentRun.response.200.output.files.url`; string, optional)
- `error` (`spaceCreateAgentRun.response.200.error`; object, optional) — Why the run failed. Present whenever `status` is `failed`.
  - `code` (`spaceCreateAgentRun.response.200.error.code`; string, required)
  - `message` (`spaceCreateAgentRun.response.200.error.message`; string, required)
- `metadata` (`spaceCreateAgentRun.response.200.metadata`; map<unknown>, optional)

### 202

Accepted — queued, still working, or blocked on a person.

#### Example

```json
{
  "object": "agent_run",
  "id": "string",
  "status": "queued",
  "statusUrl": "string"
}
```

- `object` (`spaceCreateAgentRun.response.202.object`; string, required)
- `id` (`spaceCreateAgentRun.response.202.id`; string, required)
- `status` (`spaceCreateAgentRun.response.202.status`; string, required) — Where the agent run is in its life. | Status | Meaning | | --- | --- | | `queued` | Accepted; its files are still being prepared | | `processing` | The agent is working | | `waiting` | Blocked on a person — see `waiting`, `approvals` and `tasks[]` | | `paused` | Stopped short of finishing and resumable; not a failure | | `completed` | Finished; `result` and `output` are populated | | `failed` | Finished without producing a result | | `cancelled` | Stopped on request | | `expired` | Reached its `expiresAt` without finishing | `completed`, `failed`, `cancelled` and `expired` are terminal. A `completed` run that still had outstanding work also carries `incomplete: true`.
  - one of `"queued"`, `"processing"`, `"waiting"`, `"paused"`, `"completed"`, `"failed"`, `"cancelled"`, `"expired"`
- `statusUrl` (`spaceCreateAgentRun.response.202.statusUrl`; string, required)

### 400

Validation Error

#### Example

```json
{
  "success": false,
  "error": [
    null
  ],
  "data": null
}
```

- `success` (`spaceCreateAgentRun.response.400.success`; boolean, required)
  - one of `false`
- `error` (`spaceCreateAgentRun.response.400.error`; array<unknown>, required)
- `data` (`spaceCreateAgentRun.response.400.data`; unknown, required)

### 404

Unknown agent, space, archived or expired space.

### 422

The agent cannot start, or an input file is unusable.

### 429

Rate limited. The `/v1` API allows at least **67 requests per minute per organization** (about 1,000 requests per 15 minutes) — a guaranteed floor, enforced per edge location, so a geographically spread caller may get more. Wait for the `Retry-After` interval and retry — the error is `retryable`.

#### Example

```json
{
  "code": "rate_limited",
  "message": "string",
  "retryable": true,
  "requestId": "string",
  "docUrl": "string"
}
```

- `code` (`spaceCreateAgentRun.response.429.code`; string, required)
  - one of `"rate_limited"`
- `message` (`spaceCreateAgentRun.response.429.message`; string, required)
- `retryable` (`spaceCreateAgentRun.response.429.retryable`; boolean, required)
  - one of `true`
- `requestId` (`spaceCreateAgentRun.response.429.requestId`; string, required)
- `docUrl` (`spaceCreateAgentRun.response.429.docUrl`; string, optional)


Source: https://docs.cloudraker.com/paperwork/api/spaces/space-create-agent-run/index.md
