---
title: "POST /harness/sessions/{sessionId}/execute"
description: Execute a turn
full: true
---

**Auth:** required. Send an `ivy_` API key (`Authorization: Bearer ivy_…` or `X-Ivy-Api-Key`), a Clerk session JWT (`Authorization: Bearer …`) or the Clerk `__session` cookie (browser sessions). See [Authentication](/docs/api/authentication).

Submit a user message and receive the agent's response.

**Streaming mode** (`stream: true`, default): response is a Server-Sent Events stream.
Each line is `data: ` where the JSON is a `HarnessStreamEvent`. The stream
terminates with a `sync.completed` event.

**Batch mode** (`stream: false`): response is a JSON object with `events` (array of
all `HarnessStreamEvent`s) and the final `state`.

## Request

#### Path parameters

- `sessionId` (string (uuid)) —
Session UUID (UUIDv7 — time-ordered)

#### Request body

- `content` (string) —
User message text

- `clientId` (string) —
Client identifier for version vector tracking

- `stream` (boolean) —
Stream response via SSE (true, default) or collect into a JSON batch (false)

## Responses

### `200` OK

Turn executed — SSE stream or JSON batch

Response shape:

- `success` (boolean) —

- `events` (object[]) —

- `state` (object) —
Full session state snapshot persisted in Supabase

#### state properties

- `id` (string (uuid)) —

- `version` (integer) —

- `schemaVersion` (integer) —

- `userId` (string) —

- `organizationId` (string) —

- `messages` (object[]) —

- `pendingToolCalls` (object[]) —

- `completedToolCalls` (object[]) —

- `pendingJobs` (object[]) —

- `completedJobs` (object[]) —

- `artifacts` (object[]) —

- `versionVector` (object) —
Map of clientId → logical clock counter. Used for conflict detection in multi-client sync.

- `createdAt` (string (date-time)) —

- `updatedAt` (string (date-time)) —

- `lastActiveAt` (string (date-time)) —

### `400` Bad Request

Invalid request

Response shape: `object`

### `401` Unauthorized

Authentication required

Response shape: `object`

### `404` Not Found

Resource not found

Response shape: `object`

**curl**

```bash
curl -X POST 'https://ivybiosciences.com/api/harness/sessions/{sessionId}/execute' \
  -H "Authorization: Bearer $IVY_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "content": ""
}'
```

**JavaScript**

```js
const res = await fetch('https://ivybiosciences.com/api/harness/sessions/{sessionId}/execute', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.IVY_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
  "content": ""
}),
});
const data = await res.json();
```

**Python**

```python
import os, requests

res = requests.post(
    "https://ivybiosciences.com/api/harness/sessions/{sessionId}/execute",
    headers={"Authorization": f"Bearer {os.environ['IVY_API_KEY']}"},
    json={
  "content": ""
},
)
data = res.json()
```
