---
title: "Send the next turn"
---

> 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.

# Send the next turn

Path: cloudraker.run API

`POST /_run/{id}`

Next turn of a turns run: 202 with the run object, or SSE.

## Authentication

- `bearer`, http, header `Authorization`

## Path parameters

- `id` (`postRunById.path.id`; string, required)

## Header parameters

- `Idempotency-Key` (`postRunById.header.Idempotency-Key`; string, optional) — Kept 24 h per org.
  - minLength 1; maxLength 255
- `Accept` (`postRunById.header.Accept`; string, optional) — `text/event-stream` streams the run.
  - one of `"application/json"`, `"text/event-stream"`

## Request body

_Required._

- `input` (`postRunById.input`; unknown, optional) — Text or JSON.
- `answer` (`postRunById.answer`; object, optional) — The answer to the open `question` event.
  - `question_id` (`postRunById.answer.question_id`; string, required)
  - `value` (`postRunById.answer.value`; unknown, required)
- `files` (`postRunById.files`; array<FileInput>, optional)
  - one of:
    - `By URL`
      - `url` (`postRunById.files.1.url`; string, required) — HTTPS only. Max 25 MB.
        - format `uri`
      - `name` (`postRunById.files.1.name`; string, optional)
      - `content_type` (`postRunById.files.1.content_type`; string, optional)
    - `Inline`
      - `content_base64` (`postRunById.files.2.content_base64`; string, required) — Max 5 MB decoded.
      - `name` (`postRunById.files.2.name`; string, required)
      - `content_type` (`postRunById.files.2.content_type`; string, required)
    - `By file id`
      - `file_id` (`postRunById.files.3.file_id`; string, required) — An existing tenant file, for example a file artifact of another run.
- `secrets` (`postRunById.secrets`; map<string>, optional) — Override values for secrets marked `overridable: true`. They live for this turn only. Min 8 bytes per value. A `public` agent refuses this field.

## Example request

```json
{
  "input": null,
  "answer": {
    "question_id": "string",
    "value": null
  },
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "content_type": "string"
    }
  ],
  "secrets": {
    "property1": "string",
    "property2": "string"
  }
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url 'https://your-org.cloudraker.run/_run/<id>' \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "input": null,
  "answer": {
    "question_id": "string",
    "value": null
  },
  "files": [
    {
      "url": "http://example.com",
      "name": "string",
      "content_type": "string"
    }
  ],
  "secrets": {
    "property1": "string",
    "property2": "string"
  }
}
'
```

### TypeScript

```typescript
const url = 'https://your-org.cloudraker.run/_run/<id>';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    input: null,
    answer: {question_id: 'string', value: null},
    files: [{url: 'http://example.com', name: 'string', content_type: 'string'}],
    secrets: {property1: 'string', property2: 'string'}
  })
};

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

### Python

```python
import requests

url = "https://your-org.cloudraker.run/_run/<id>"

payload = {
    "input": None,
    "answer": {
        "question_id": "string",
        "value": None
    },
    "files": [
        {
            "url": "http://example.com",
            "name": "string",
            "content_type": "string"
        }
    ],
    "secrets": {
        "property1": "string",
        "property2": "string"
    }
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

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

print(response.text)
```

## Responses

### 202

The run object, or the event stream of the turn.

#### Body (application/json)

- `id` (`postRunById.response.202.id`; string, required)
  - example `"run_01K7Q3V9X2M4N6P8R0S2T4V6W8"`
- `agent` (`postRunById.response.202.agent`; string, required)
  - example `"hello"`
- `mode` (`postRunById.response.202.mode`; string, required)
  - one of `"zeroshot"`, `"turns"`, `"machine"`
- `status` (`postRunById.response.202.status`; string, required)
  - one of `"queued"`, `"running"`, `"waiting"`, `"completed"`, `"failed"`, `"cancelled"`, `"expired"`
- `turn` (`postRunById.response.202.turn`; integer, required)
- `deployment` (`postRunById.response.202.deployment`; object, required)
  - `sha` (`postRunById.response.202.deployment.sha`; string, optional)
  - `deployed_at` (`postRunById.response.202.deployment.deployed_at`; string, optional)
    - format `date-time`
- `created_at` (`postRunById.response.202.created_at`; string, required)
  - format `date-time`
- `updated_at` (`postRunById.response.202.updated_at`; string, required)
  - format `date-time`
- `last_seq` (`postRunById.response.202.last_seq`; integer, required)
- `metadata` (`postRunById.response.202.metadata`; map<string>, required) — Max 20 keys, string values, 1 KB in total. Echoed on every event and webhook. `end_user` scopes data store records.
- `stream_url` (`postRunById.response.202.stream_url`; string, required)
  - format `uri`
- `expires_at` (`postRunById.response.202.expires_at`; string | null, optional) — Set while a `turns` or `machine` run is `waiting`.
  - format `date-time`
- `read_token` (`postRunById.response.202.read_token`; string, optional) — `rrt_` token. Reads this run only. Present on the start answer.
- `result` (`postRunById.response.202.result`; unknown, optional) — The `done` payload after `run.completed`.
- `error` (`postRunById.response.202.error`; object | null, optional)
  - `code` (`postRunById.response.202.error.code`; string, optional)
  - `message` (`postRunById.response.202.error.message`; string, optional)
- `usage` (`postRunById.response.202.usage`; object, optional)
  - `input_tokens` (`postRunById.response.202.usage.input_tokens`; integer, optional)
  - `cached_input_tokens` (`postRunById.response.202.usage.cached_input_tokens`; integer, optional)
  - `output_tokens` (`postRunById.response.202.usage.output_tokens`; integer, optional)
  - `reasoning_tokens` (`postRunById.response.202.usage.reasoning_tokens`; integer, optional)
  - `model_steps` (`postRunById.response.202.usage.model_steps`; integer, optional)
  - `code_calls` (`postRunById.response.202.usage.code_calls`; integer, optional)
  - `code_cpu_ms` (`postRunById.response.202.usage.code_cpu_ms`; integer, optional)
  - `egress_requests` (`postRunById.response.202.usage.egress_requests`; integer, optional)
  - `egress_bytes` (`postRunById.response.202.usage.egress_bytes`; integer, optional)
  - `duration_ms` (`postRunById.response.202.usage.duration_ms`; integer, optional)
  - `credits` (`postRunById.response.202.usage.credits`; integer, optional)
  - `dynamic_worker_ids` (`postRunById.response.202.usage.dynamic_worker_ids`; integer, optional)
  - `inference` (`postRunById.response.202.usage.inference`; string, optional)
    - one of `"cloudraker"`, `"byok"`, `"gateway"`
  - `model_cost_usd` (`postRunById.response.202.usage.model_cost_usd`; number | null, optional) — Raw model cost in USD from the AI Gateway logs of CloudRaker inference. Null until a cost is known. Not credits.
  - `model_cost_complete` (`postRunById.response.202.usage.model_cost_complete`; boolean, optional) — False while a step cost is not known yet, or when a step has no reported cost (byok, custom gateway).
- `parent_run_id` (`postRunById.response.202.parent_run_id`; string, optional) — A child run only: the run that delegated the task.
- `root_run_id` (`postRunById.response.202.root_run_id`; string, optional) — A child run only: the first run of the run tree.
- `depth` (`postRunById.response.202.depth`; integer, optional) — A child run only: 1 for a child of the root run.
  - min 1
- `waiting_for` (`postRunById.response.202.waiting_for`; string, optional) — Set while the run waits for the reports of its child runs.
  - one of `"children"`
- `tree_credits` (`postRunById.response.202.tree_credits`; number, optional) — A run with child runs only: the credits of the run and of all its child runs.

##### Example

```json
{
  "id": "run_01K7Q3V9X2M4N6P8R0S2T4V6W8",
  "agent": "hello",
  "mode": "zeroshot",
  "status": "queued",
  "turn": 0,
  "deployment": {
    "sha": "string",
    "deployed_at": "2019-08-24T14:15:22Z"
  },
  "created_at": "2019-08-24T14:15:22Z",
  "updated_at": "2019-08-24T14:15:22Z",
  "expires_at": "2019-08-24T14:15:22Z",
  "last_seq": 0,
  "metadata": {
    "property1": "string",
    "property2": "string"
  },
  "read_token": "string",
  "stream_url": "http://example.com",
  "result": null,
  "error": {
    "code": "string",
    "message": "string"
  },
  "usage": {
    "input_tokens": 0,
    "cached_input_tokens": 0,
    "output_tokens": 0,
    "reasoning_tokens": 0,
    "model_steps": 0,
    "code_calls": 0,
    "code_cpu_ms": 0,
    "egress_requests": 0,
    "egress_bytes": 0,
    "duration_ms": 0,
    "credits": 0,
    "dynamic_worker_ids": 0,
    "inference": "cloudraker",
    "model_cost_usd": 0,
    "model_cost_complete": true
  },
  "parent_run_id": "string",
  "root_run_id": "string",
  "depth": 1,
  "waiting_for": "children",
  "tree_credits": 0
}
```

#### Body (text/event-stream)

##### Example

```text
string
```

### 4XX

Error. See the `code` table in the guides.

#### Example

```json
{
  "error": {
    "code": "run_busy",
    "message": "string",
    "run_id": "string",
    "details": null
  }
}
```

- `error` (`postRunById.response.4XX.error`; object, required)
  - `code` (`postRunById.response.4XX.error.code`; string, required)
    - example `"run_busy"`
  - `message` (`postRunById.response.4XX.error.message`; string, required)
  - `run_id` (`postRunById.response.4XX.error.run_id`; string, optional)
  - `details` (`postRunById.response.4XX.error.details`; unknown, optional)


Source: https://docs.cloudraker.com/run/api/post-run-by-id/index.md
