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

# Send a message

> Run a turn through an agent template, stream or return its result, and continue the conversation.

Send a message or task to the agent on your instance. Omit `session_id` to start a conversation.

```bash curl wrap theme={null}
curl -X POST \
  https://ab12cd34ef.agent37.app/v1/responses \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "input": "Summarize the attached spreadsheet.",
    "files": [
      "/home/node/leads.csv"
    ],
    "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
    "stream": false,
    "model": "default",
    "provider": "custom:Agent37",
    "reasoning_effort": "medium",
    "metadata": {
      "user": "u_882"
    },
    "agent": "hermes",
    "profile": "default",
    "mode": "chat"
  }'
```

```python Python wrap theme={null}
import requests

response = requests.post(
    "https://ab12cd34ef.agent37.app/v1/responses",
    headers={
        "X-Agent37-Key": "sk_live_...",
        "Content-Type": "application/json"
    },
    json={
        "input": "Summarize the attached spreadsheet.",
        "files": [
            "/home/node/leads.csv"
        ],
        "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
        "stream": False,
        "model": "default",
        "provider": "custom:Agent37",
        "reasoning_effort": "medium",
        "metadata": {
            "user": "u_882"
        },
        "agent": "hermes",
        "profile": "default",
        "mode": "chat"
    },
)
response.raise_for_status()
print(response.json())
```

```javascript Node wrap theme={null}
const response = await fetch(
  "https://ab12cd34ef.agent37.app/v1/responses",
  {
    method: "POST",
    headers: {
      "X-Agent37-Key": "sk_live_...",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "input": "Summarize the attached spreadsheet.",
      "files": [
        "/home/node/leads.csv"
      ],
      "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
      "stream": false,
      "model": "default",
      "provider": "custom:Agent37",
      "reasoning_effort": "medium",
      "metadata": {
        "user": "u_882"
      },
      "agent": "hermes",
      "profile": "default",
      "mode": "chat"
    }),
  },
);
if (!response.ok) {
  throw new Error(await response.text());
}
console.log(await response.json());
```

```json 200 (excerpt) wrap theme={null}
{
  "id": "c91d2a7e84f04b6f9a3d5e1c0b87f4a2",
  "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
  "status": "completed",
  "output_text": "The spreadsheet lists your leads."
}
```

`POST /v1/responses` runs a turn on templates that include the Agent API. You make it against your instance, not against `api.agent37.com`: agent templates serve their chat API at `https://{instanceId}.agent37.app`, the `url` of the default port in the create response. This page uses `https://ab12cd34ef.agent37.app`. Authenticate with the same `sk_live_` key you use on the Sandbox API, sent as the `X-Agent37-Key` header.

The call is agentic by default: the agent can browse, run code, use a terminal, read and write files, call connected tools, and reason across many steps before answering.

## Request body

The example shows all request fields for Hermes. [Upload `leads.csv`](https://www.agent37.com/docs/agents-api/files#write-a-file) first, use a session id from a previous response to continue a conversation, and choose `model` and `provider` from [Models](https://www.agent37.com/docs/agents-api/models.md). Omit optional fields you do not need.

Request bodies are capped at 2 MB; anything larger returns `413 payload_too_large`.

**input** `string` *required*

The message or task, a plain string. There is no image field; to attach files, upload them first and list their paths in `files`. See [Sessions](https://www.agent37.com/docs/agents-api/sessions.md) for how history carries across turns.

**files** `string[]`

Paths of files on the instance to attach to this turn, typically the `path` returned by [`PUT /v1/files/content`](https://www.agent37.com/docs/agents-api/files). Each must name an existing file on the instance, or the call returns `400 validation_error`. The paths are appended to the input, and the agent reads them from disk.

**session\_id** `string`

Continue an existing conversation. Omit it to start a new one; the response returns the new session's id. The harness owns sessions and creates one on first use, so an id it has not seen simply starts a fresh thread under that id rather than erroring. The exception is a harness that issues its own session ids: `codex`, `grok`, `opencode` and `pi` reject a first turn on an id they did not issue with `400 validation_error` (`param: session_id`), so on those four always start a thread by omitting `session_id` and reuse the id the response returns.

**stream** `boolean` (default: false)

`true` returns a Server-Sent Events stream; `false` returns the finished response as one JSON body. See [Streaming](https://www.agent37.com/docs/agents-api/streaming.md).

**model** `string`

The LLM to run this turn on, an id from `GET /v1/models` (on OpenClaw the ids are `provider/model`). On Hermes it applies to this turn only: omit it and the turn runs on the instance's default model, whatever earlier turns chose. On OpenClaw a named model is written to the session and sticks for the turns that follow; a turn that omits it leaves the session's model as is. A `model` OpenClaw does not allow (an id outside `GET /v1/models`) never starts the turn: the response settles with `status: "failed"` and `error.code` `agent_error`, with OpenClaw's reason in `message`, and the session keeps its previous model. See [Models](https://www.agent37.com/docs/agents-api/models.md).

**provider** `string`

The model's provider, for example `anthropic`. Hermes only, and per turn like `model`: it tells Hermes which configured provider to run the named model on. OpenClaw ignores it (the response still echoes it); there the provider is the prefix of the `provider/model` id you pass as `model`.

**reasoning\_effort** `string`

How hard the model thinks: `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max`, or `ultra`. `max` is the strongest plain thinking level; `ultra` is the harness's own Ultra mode, top thinking plus its agentic orchestration (on OpenClaw it also turns on proactive subagent orchestration). It applies to this turn only on both harnesses. Omit it and Hermes uses the instance's configured effort, while OpenClaw uses the session's own thinking level. On OpenClaw the values map one to one onto its thinking levels, with `none` sent as `off`. `max` and `ultra` need gateway `0.10.0`: older instances reject them with `validation_error` until [updated](https://www.agent37.com/docs/agents-api/instances/update.md).

Codex and OpenCode advertise their levels per model, and a level a model does not accept is run at the nearest level below it rather than failing the turn. The response's `reasoning_effort` reports the level applied, so read that rather than assuming the request was honoured.

**metadata** `object`

Up to 16 key/value pairs, at most 64 KB serialized. Echoed back on the response object, never interpreted.

**agent** `string`

Which agent harness runs the turn, `hermes`, `openclaw`, `claude-code`, `codex`, `grok`, `opencode`, or `pi`. Omit it to use the instance's configured default (`hermes` on `agent37-hermes`, `openclaw` on `agent37-openclaw`, `claude-code` on `agent37-claude-code`, `codex` on `agent37-codex`, `grok` on `agent37-grok`, `opencode` on `agent37-opencode`, `pi` on `agent37-pi`). Routing is per request: the gateway keeps no session-to-agent binding, so if a session runs on a non-default harness, send `agent` on every turn of it. Targeting a harness the instance was not provisioned with does not reject the call: the turn settles with `status: "failed"` and `error.code` `agent_unavailable`.

**profile** `string`

A named setup inside the agent, with its own instructions, skills, memory, config, and sessions, so one instance can host several distinct agents (a support agent and a sales agent, say). Omit it, or send `default`, for the agent's own setup. Like `agent`, it is per request: send it on every turn of the session, and as `?profile=` on the [session reads](https://www.agent37.com/docs/agents-api/sessions.md#profiles). Supported on `hermes` today; `profile` with any other `agent` is `400 validation_error`. A name that is not lowercase letters, digits, `-` or `_` is `400 validation_error`, and a profile that does not exist on the instance is `404 profile_not_found`.

**mode** `string` (default: chat)

`chat` runs one turn and replies. `goal` is reserved: sending it returns `400 validation_error` today.

> [!NOTE]
>
> `instance_id` in the body is accepted and ignored. The URL names the instance: one gateway per instance, so there is nothing to route.

## Response

The example shows selected fields. The complete response fields are listed below.

The response object. Ids are 32-character hex strings; timestamps from the gateway are epoch milliseconds.

**id** `string`

The response id. Use it to reconnect or cancel the turn.

**session\_id** `string`

The conversation this turn belongs to. Reuse it on the next call to continue the thread.

**status** `string`

`in_progress`, then a terminal `completed`, `failed`, or `cancelled`.

**agent** `string`

The agent that ran the turn, `hermes`, `openclaw`, `claude-code`, `codex`, `grok`, `opencode`, or `pi`.

**profile** `string | null`

The profile the turn ran in, or `null` for the agent's own setup.

**model** `string | null`

The `model` you sent on this request, echoed back. `null` when you omitted it: the turn still ran on the harness's default or session model, but the gateway does not report which model the harness resolved.

**provider** `string | null`

The `provider` you sent on this request, echoed back; `null` when you omitted it.

**reasoning\_effort** `string | null`

The reasoning level applied to this turn, which is not always the one you asked for. Every harness takes the same eight levels and maps them onto its own: Hermes and OpenClaw run all eight, Claude Code runs `minimal` as `low`, grok and pi run `ultra` as `max`, and Codex and OpenCode go further and advertise which levels each individual model supports. Rather than reject a turn for a level a model cannot run, the gateway runs it at the nearest level below. Ask OpenCode for `ultra` and you get `max` or lower back. `null` when you sent no level and the harness used its own default: the turn still ran at some effort, but the gateway reports only what it applied.

This is the level sent to the harness, not a reading taken from the model. A harness that lowers it again on its own is not visible here: Pi clamps to the model's limits itself, and a non-reasoning Grok model ignores the setting outright. Read it as the ceiling the turn ran under. It also rides the terminal `response.completed` event when you [stream](https://www.agent37.com/docs/agents-api/streaming.md). Needs gateway `0.18.0`; older instances omit the field.

**output\_text** `string`

The agent's final answer. Always a string, empty if the turn produced none.

**usage** `object | null`

Token counts and cost for the turn: `{ input_tokens, output_tokens, cost_usd }`. `cost_usd` is absent or `null` when the provider did not report a cost.

**context** `object | null`

The session's context window as of this turn: `{ used_tokens, window_tokens }`, the tokens occupying the model's window against the window's size. `null` when the harness didn't report a measurement; a cancelled turn reports none on either harness. Hermes reports it on every completed turn. OpenClaw reports none, so the gateway derives it from the turn: `used_tokens` is the turn's token total (input, output, and cache tokens) and `window_tokens` is the model's context window from OpenClaw's model catalog, or `128000` (OpenClaw's own default budget) when the catalog lists no window for the model. On OpenClaw it is `null` when the turn reported no usage, no model, a zero token total, or a model that is not in the catalog.

**error** `object | null`

Set when the turn failed: `{ code, message, param?, hint? }`. See [Errors](https://www.agent37.com/docs/agents-api/errors.md).

**metadata** `object | null`

Your request metadata, echoed back verbatim.

**created** `number`

When the turn started, epoch milliseconds.

> [!NOTE]
>
> A failed turn does not reject the HTTP call. The POST still returns 200 with `status: "failed"` and `error` set. Branch on `status`, not on the HTTP code.

> [!NOTE]
>
> On a non-streaming call the gateway sends the `200` and headers as soon as the turn starts, then keeps the connection alive with a whitespace tick every 25 seconds while the agent works. There is no time limit on a turn; the connection stays open until the agent is done. The JSON body arrives when the turn finishes, prefixed by that whitespace. Leading whitespace is valid JSON, so standard parsers handle it unchanged. Don't treat the early headers as the response being ready. On a sleeping instance no headers arrive at all until the wake completes, so give the request a first-byte timeout of at least three minutes; past the edge's three-minute wake budget the request gets `503 wake_timeout` instead.

> [!TIP]
>
> Set `stream: true` to receive Server-Sent Events as the agent reasons, calls tools, and writes its answer. The terminal event carries the final `output_text`, `usage`, and `context`. See [Streaming](https://www.agent37.com/docs/agents-api/streaming.md).

## Complete response example

```json wrap theme={null}
{
  "id": "c91d2a7e84f04b6f9a3d5e1c0b87f4a2",
  "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
  "status": "completed",
  "agent": "hermes",
  "model": null,
  "provider": null,
  "reasoning_effort": "high",
  "output_text": "Hello!",
  "usage": { "input_tokens": 1840, "output_tokens": 920, "cost_usd": 0.0137 },
  "context": { "used_tokens": 22600, "window_tokens": 256000 },
  "error": null,
  "metadata": null,
  "created": 1781136000000
}
```

## Continue a conversation

The first message omits `session_id` and starts a session. The reply returns a `session_id`; pass it on the next message to continue the same thread. The session holds the full history, so you never resend a transcript: you send only the new input.

```bash curl wrap theme={null}
# 1. start a session: omit session_id
curl https://ab12cd34ef.agent37.app/v1/responses \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "input": "Research the top 3 EV makers, write a memo."
  }'
# -> { "id": "c91d2a7e84f04b6f9a3d5e1c0b87f4a2",
#      "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
#      "status": "completed", ... }

# 2. continue it: reuse the session_id, send only the new input
curl https://ab12cd34ef.agent37.app/v1/responses \
  -H "X-Agent37-Key: sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "session_id": "7f3e0b6c52a949d2b1c4a8e9d0f31726",
    "input": "Make it shorter, add a quote."
  }'
```

```python python wrap theme={null}
import requests

BASE = "https://ab12cd34ef.agent37.app"
H = {"X-Agent37-Key": "sk_live_...", "Content-Type": "application/json"}

# 1. start a session: omit session_id
first = requests.post(
    f"{BASE}/v1/responses",
    headers=H,
    json={"input": "Research the top 3 EV makers, write a memo."},
).json()

# 2. continue it: reuse the session_id, send only the new input
requests.post(
    f"{BASE}/v1/responses",
    headers=H,
    json={
        "session_id": first["session_id"],
        "input": "Make it shorter, add a quote.",
    },
)
```

```javascript node wrap theme={null}
const BASE = "https://ab12cd34ef.agent37.app";
const H = {
  "X-Agent37-Key": "sk_live_...",
  "Content-Type": "application/json",
};

// 1. start a session: omit session_id
const first = await (await fetch(`${BASE}/v1/responses`, {
  method: "POST",
  headers: H,
  body: JSON.stringify({
    input: "Research the top 3 EV makers, write a memo.",
  }),
})).json();

// 2. continue it: reuse the session_id, send only the new input
await fetch(`${BASE}/v1/responses`, {
  method: "POST",
  headers: H,
  body: JSON.stringify({
    session_id: first.session_id,
    input: "Make it shorter, add a quote.",
  }),
});
```

> [!NOTE]
>
> **One active turn per session.** A session runs one response at a time. Sending new input while one is in flight returns `409 session_busy`, normally with the running response's id in `error.response_id`. Use another session, reattach to the running turn, or cancel it first.

To list a user's threads, read a thread's history, or delete one, see [Sessions](https://www.agent37.com/docs/agents-api/sessions.md). To pick a model per turn, see [Models](https://www.agent37.com/docs/agents-api/models.md).

### When the agent needs a decision from you

The agent asks by ending its turn: the response comes back `completed` with the question (and the options, if any) as `output_text`, and the turn is over. Answer by sending the reply as the next `input` on the same `session_id`. There is no in-turn prompt to answer while a response is `in_progress`, so a chat client needs nothing special: render the question like any other reply, and send the user's answer like any other message.

### When the agent delegates to subagents

On Hermes, subagents run inside the turn: the response stays `in_progress` until they finish, and the agent's final answer, their results included, arrives in that same response. A delegation can run for minutes with nothing on the stream but `:keepalive` comments between the `delegate_task` tool call's `started` and `completed` events, so keep the connection open or [reattach](#follow-up-on-a-response). Cancelling the turn stops the subagents too. This needs gateway `0.15.1`: older instances end the turn as soon as the subagents are dispatched and hand their results to the agent at the start of your next message, until [updated](https://www.agent37.com/docs/agents-api/instances/update.md).

## Follow up on a response

Every response has an id you can use after the call returns.

| Method | Path | Returns |
| - | - | - |
| `GET` | `/v1/responses/{id}/stream` | `200` an SSE stream: replays all events, then attaches live |
| `POST` | `/v1/responses/{id}/cancel` | `200` the current response object |

`GET /v1/responses/{id}/stream` replays every event so far in order, then stays attached live, so a dropped connection never loses the answer, including after the turn has finished, while the response is still retained. See [Streaming](https://www.agent37.com/docs/agents-api/streaming.md) for the replay window. Lost the id (page reload, new device)? [`GET /v1/sessions/{id}`](https://www.agent37.com/docs/agents-api/sessions#retrieve-a-session-with-history) returns the running response as `active_response_id`.

`POST /v1/responses/{id}/cancel` takes no body and stops a running turn (on OpenClaw it aborts the run inside OpenClaw). It returns 200 with the current response object as soon as the stop is requested, not once the agent has actually stopped, so the body normally still reads `status: "in_progress"`; the response settles to `cancelled` when the turn unwinds. To see it end, read `GET /v1/responses/{id}/stream`: a cancelled turn still closes with `response.completed`, carrying the `output_text` accumulated so far. Cancelling a finished response is a no-op that returns its terminal state, still 200.

```bash curl wrap theme={null}
curl -X POST \
  https://ab12cd34ef.agent37.app/v1/responses/c91d2a7e84f04b6f9a3d5e1c0b87f4a2/cancel \
  -H "X-Agent37-Key: sk_live_..."
```

```python Python wrap theme={null}
import requests

response = requests.post(
    "https://ab12cd34ef.agent37.app/v1/responses/c91d2a7e84f04b6f9a3d5e1c0b87f4a2/cancel",
    headers={
        "X-Agent37-Key": "sk_live_..."
    },
)
response.raise_for_status()
print(response.json())
```

```javascript Node wrap theme={null}
const response = await fetch(
  "https://ab12cd34ef.agent37.app/v1/responses/c91d2a7e84f04b6f9a3d5e1c0b87f4a2/cancel",
  {
    method: "POST",
    headers: {
      "X-Agent37-Key": "sk_live_..."
    },
  },
);
if (!response.ok) {
  throw new Error(await response.text());
}
console.log(await response.json());
```

> [!WARNING]
>
> Cancel does not rewind. Whatever the agent has already done (files written, emails sent, tools called) is not undone. The response ends with `status: "cancelled"`.

## Status values

A response moves from `in_progress` to exactly one terminal status.

| Status | Meaning |
| - | - |
| `in_progress` | The turn is running. |
| `completed` | The turn finished and `output_text` holds the answer. |
| `failed` | The turn ended on an error; `error` says why. |
| `cancelled` | You stopped the turn with `cancel`, or (OpenClaw only) the input was one of OpenClaw's own stop commands such as `stop` or `exit`, so no run started. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.