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

# Create Session

> Start a new agent session and post the first user message.

```http theme={null}
POST /rest/v1/sessions
```

Creates a new session for the authenticated workspace, posts the initial user message, and dispatches it to the agent. The response includes a pre-built `_links.final_message.href` URL — poll it to receive the assistant's reply.

## Request

```javascript JavaScript theme={null}
const res = await fetch("https://api.blocks.team/rest/v1/sessions", {
  method: "POST",
  headers: {
    Authorization: `ApiKey ${process.env.BLOCKS_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    agent_name: "claude",
    message: "Say hello and tell me a one-sentence fun fact about octopuses.",
  }),
});
const session = await res.json();
```

```python Python theme={null}
import os, requests

session = requests.post(
    "https://api.blocks.team/rest/v1/sessions",
    headers={
        "Authorization": f"ApiKey {os.environ['BLOCKS_API_KEY']}",
        "Content-Type": "application/json",
    },
    json={
        "agent_name": "claude",
        "message": "Say hello and tell me a one-sentence fun fact about octopuses.",
    },
).json()
```

```bash cURL theme={null}
curl -X POST https://api.blocks.team/rest/v1/sessions \
  -H "Authorization: ApiKey $BLOCKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "agent_name": "claude",
    "message": "Say hello and tell me a one-sentence fun fact about octopuses."
  }'
```

```java Java theme={null}
import java.net.URI;
import java.net.http.*;

HttpResponse<String> res = HttpClient.newHttpClient().send(
    HttpRequest.newBuilder(URI.create("https://api.blocks.team/rest/v1/sessions"))
        .header("Authorization", "ApiKey " + System.getenv("BLOCKS_API_KEY"))
        .header("Content-Type", "application/json")
        .POST(HttpRequest.BodyPublishers.ofString(
            "{\"agent_name\":\"claude\",\"message\":\"Say hello and tell me a one-sentence fun fact about octopuses.\"}"))
        .build(),
    HttpResponse.BodyHandlers.ofString());
```

```ruby Ruby theme={null}
require "net/http"
require "json"

session = JSON.parse(Net::HTTP.post(
  URI("https://api.blocks.team/rest/v1/sessions"),
  JSON.generate({
    agent_name: "claude",
    message: "Say hello and tell me a one-sentence fun fact about octopuses.",
  }),
  {
    "Authorization" => "ApiKey #{ENV['BLOCKS_API_KEY']}",
    "Content-Type" => "application/json",
  },
).body)
```

```go Go theme={null}
body, _ := json.Marshal(map[string]string{
    "agent_name": "claude",
    "message":    "Say hello and tell me a one-sentence fun fact about octopuses.",
})
req, _ := http.NewRequest("POST", "https://api.blocks.team/rest/v1/sessions", bytes.NewReader(body))
req.Header.Set("Authorization", "ApiKey "+os.Getenv("BLOCKS_API_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
```

### Body

> [!NOTE]
>
> Exactly one of `agent_id`, `agent_name`, or `profile` must be provided. Sending none returns `422 VALIDATION`.

**message** `string` *required*

The first user message in the session.

**agent\_name** `string`

Name of a built-in core agent. One of `claude`, `codex`, `gemini`, `opencode`, `cursor`, `kimi`. Returns `422 VALIDATION` if the name is unknown.

**agent\_id** `string (uuid)`

ID of a specific agent in your workspace. Use this to target a custom agent.

**profile** `object`

Reference to a profile or an inline profile to apply to this session.

**properties**

**id** `string (uuid)`

ID of an existing profile.

**config\_values** `object`

Runtime config overrides for the agent.

**mcp\_servers** `array`

MCP servers to attach to the session.

**config\_merge\_strategy** `string`

How `config_values` are merged with the agent's defaults.

**is\_private** `boolean` (default: false)

When `true`, the session is hidden from other workspace members.

**artifact\_ids** `string[] (uuid[])`

Existing artifacts to attach to the initial message.

## Response

```json theme={null}
{
  "id": "a196cec6-49cb-4c48-8e4c-2707fb5d6709",
  "title": "Octopus fun fact",
  "pull_requests": [],
  "source_url": null,
  "is_archived": false,
  "is_private": false,
  "created_at": "2026-04-30T18:21:00.000Z",
  "updated_at": "2026-04-30T18:21:00.000Z",
  "thread_id": "71562cd0-1f63-41b2-8382-10f2fdb1ac8b",
  "session_group_id": null,
  "plan_artifact_ids": [],
  "session_html_url": "https://blocks.team/app/3f2c1d9e-7b4a-4c8e-9d1f-2a6b5c4d3e2f/sessions/a196cec6-49cb-4c48-8e4c-2707fb5d6709",
  "_links": {
    "self": { "href": "https://api.blocks.team/rest/v1/sessions/a196cec6-49cb-4c48-8e4c-2707fb5d6709" },
    "messages": { "href": "https://api.blocks.team/rest/v1/sessions/a196cec6-49cb-4c48-8e4c-2707fb5d6709/messages" },
    "thread": { "href": "https://api.blocks.team/rest/v1/sessions/a196cec6-49cb-4c48-8e4c-2707fb5d6709/threads/71562cd0-1f63-41b2-8382-10f2fdb1ac8b/messages" },
    "final_message": { "href": "https://api.blocks.team/rest/v1/sessions/a196cec6-49cb-4c48-8e4c-2707fb5d6709/threads/71562cd0-1f63-41b2-8382-10f2fdb1ac8b/messages?type=final_message&role=assistant" }
  }
}
```

**id** `string (uuid)`

Unique identifier for the session.

**title** `string`

Auto-generated title for the session.

**pull\_requests** `string[]`

IDs of pull requests opened by the agent in this session.

**source\_url** `string | null`

External URL the session was started from, if any (e.g. a Slack message).

**is\_archived** `boolean`

Whether the session has been archived.

**is\_private** `boolean`

Whether the session is hidden from other workspace members.

**created\_at** `string (ISO 8601)`

When the session was created.

**updated\_at** `string (ISO 8601)`

When the session was last updated.

**thread\_id** `string (uuid) | null`

The ID of the first thread on the session. Used to build the polling URL for the assistant's reply.

**session\_group\_id** `string (uuid) | null`

The session group this session belongs to, if any.

**plan\_artifact\_ids** `string[] (uuid[])`

Latest artifact ID for each plan the agent produced, oldest plan first. Download them with [Fetch Plans & Files](https://docs.blocks.team/rest-api/sessions/artifacts.md). Empty for a new session.

**session\_html\_url** `string`

Web URL where the session can be viewed in the Blocks dashboard.

**\_links** `object`

HATEOAS links for the session.

**properties**

**self** `object`

Link to this session.

**messages** `object`

Link to the session's messages list.

**thread** `object | null`

Link to the first thread's messages.

**final\_message** `object | null`

Pre-built polling URL for the assistant's final message — already filtered to `type=final_message&role=assistant` on the first thread.

## Errors

| Status | Code | Reason |
| - | - | - |
| `422` | `VALIDATION` | None of `agent_id`, `agent_name`, or `profile` was provided. |
| `422` | `VALIDATION` | `agent_name` is not one of the supported core agents. |
| `422` | `VALIDATION` | The request body failed validation (for example a missing `message`, or a non-UUID `agent_id` / `session_group_id` / `artifact_ids` entry). |


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