# Create sessions

URL: https://docs.hanzo.ai/docs/openapi/agent/post-agent-sessions

> Opens a live agent session in the caller's org — the row every surface (the CLI's outer agent, hanzo.bot, the console, chat) hangs its activity off.

`POST /v1/agent/sessions`

> [Agent →](https://docs.hanzo.ai/docs/openapi/agent) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                          |
| ------------- | ---------------------------------------- |
| **Address**   | `https://api.hanzo.ai/v1/agent/sessions` |
| **Method**    | `POST`                                   |
| **Operation** | `post_agent_sessions`                    |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`   |

Opens a live agent session in the caller's org — the row every
surface (the CLI's outer agent, hanzo.bot, the console, chat) hangs its
activity off. A session with a parentSessionId becomes a subagent of that
session and inherits its root, so one flow is one tree; without one it is
itself a root. Registering with a terminal status records a session that has
already finished.

## Request

18 fields, body `application/json` (required).

| Field              | In   | Type            | Required | Description                                                                                                            |
| ------------------ | ---- | --------------- | -------- | ---------------------------------------------------------------------------------------------------------------------- |
| `account`          | body | string          | —        | Account is which subscription or API account under that provider served the run, up to 256 characters.                 |
| `actor`            | body | string          | —        | Actor is the "org/sub" identity to record the session under, up to 256 characters.                                     |
| `agent`            | body | string          | —        | Agent is the label the surface opening this session calls itself by ("hanzo-dev").                                     |
| `budget_micro_usd` | body | integer (int64) | —        | BudgetMicroUSD caps what this session may spend, integer micro-USD.                                                    |
| `cwd`              | body | string          | —        | Cwd is the directory the session starts in, up to 1024 characters.                                                     |
| `host`             | body | string          | —        | Execution context — where this session runs (all optional).                                                            |
| `parentSessionId`  | body | string          | —        | ParentSessionID makes this a subagent of that session: it inherits the parent's root, so one flow stays one tree.      |
| `project`          | body | string          | —        | The readable build (provenance.go): which product this session builds, and whether its story may be read by the world. |
| `provider`         | body | string          | —        | Account tag — the linked AI account this session ran under (login manager).                                            |
| `published`        | body | boolean         | —        | Published opens this session's story to the public build route.                                                        |
| `repo`             | body | string          | —        | Repo is the code being worked on, up to 512 characters.                                                                |
| `room`             | body | string          | —        | Room is the collaborative room this run was started in (HIP-0523), so a space view can list the sessions of one room.  |
| `status`           | body | string          | —        | Status opens the session in one of running, paused, done or error.                                                     |
| `target`           | body | string          | —        | Target names a run-target the org has registered.                                                                      |
| `taskRunId`        | body | string          | —        | TaskRunID is that workflow's particular run, same bound.                                                               |
| `taskWorkflowId`   | body | string          | —        | TaskWorkflowID links this session to the hanzoai/tasks workflow that executes it, up to 256 characters.                |
| `terminal`         | body | string          | —        | Terminal is the URL this session's live terminal is published at, so the console can watch it.                         |
| `title`            | body | string          | —        | Title is the human line a card shows, up to 512 characters.                                                            |

## Response

| Status    | Body              | Meaning |
| --------- | ----------------- | ------- |
| `201`     | agent.sessionView | created |
| `default` | problem-details   | refused |

`201` body — 45 fields.

| Field                | In   | Type                  | Always | Description                                                                                                                                                                                                               |
| -------------------- | ---- | --------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `account`            | body | string                | —      | Account is which subscription or API account under that provider served it.                                                                                                                                               |
| `actor`              | body | string                | —      | Actor is WHO this session belongs to, as "org/sub" — the same identity a run is billed under.                                                                                                                             |
| `agent`              | body | string                | —      | Agent is the label the surface running this session calls itself by ("hanzo-dev"), up to 128 characters.                                                                                                                  |
| `base`               | body | string                | —      | Base is the branch the run started from.                                                                                                                                                                                  |
| `branch`             | body | string                | —      | Branch is the branch the run pushes its work to, and the only one it may write.                                                                                                                                           |
| `children`           | body | integer (int64)       | —      | Children is the DIRECT fan-out — how many sessions name this one as parent — and not the size of the subtree.                                                                                                             |
| `createdAt`          | body | string                | —      | CreatedAt is when the row was written, same format.                                                                                                                                                                       |
| `cwd`                | body | string                | —      | Cwd is the directory the session is working in NOW, not the one it started in: a linked shell moves around, and a card showing where `hanzo link` was run answers "which work is this" with something that was true once. |
| `endedAt`            | body | string                | —      | EndedAt is when it reached done or error, same format.                                                                                                                                                                    |
| `environment`        | body | string                | —      | Environment is where the run executes: "sandbox" for a Hanzo sandbox, or the id of the org's machine it was routed to (the same id Target carries).                                                                       |
| `events`             | body | integer (int64)       | —      | Events is how many turns the session's log holds, counted at read time.                                                                                                                                                   |
| `host`               | body | string                | —      | Execution context (mission-control): the machine/repo/cwd a card shows and the run-target a session is dispatched to.                                                                                                     |
| `id`                 | body | string                | —      | ID is the session's handle, minted here as "sess\_" + 32 hex characters.                                                                                                                                                  |
| `kind`               | body | string                | —      | Kind is what sort of run this session is the view of — "coding" for a coding run.                                                                                                                                         |
| `lastEvent`          | body | agent.lastEventView   | —      |                                                                                                                                                                                                                           |
| `lastEvent.actor`    | body | string                | —      | Actor is who produced the turn, defaulted to the calling principal when the writer named nobody.                                                                                                                          |
| `lastEvent.at`       | body | string                | —      | At is when the turn was recorded, RFC 3339 in UTC to the second.                                                                                                                                                          |
| `lastEvent.kind`     | body | string                | —      | Kind is what the turn was, from the log's closed six: message, tool-call, spawn, log, status, control.                                                                                                                    |
| `lastEvent.preview`  | body | string                | —      | Preview is the first 240 bytes of the event's payload, cut without regard for the JSON inside it — it is a string to SHOW, never a value to parse.                                                                        |
| `lastEvent.seq`      | body | integer (int64)       | —      | Seq is that event's position in the session's log — monotonic from 1, per session.                                                                                                                                        |
| `mode`               | body | string                | —      | Mode is what the run may do to its repository: "build" edits, commits and pushes its branch; "plan" reads and answers with a plan, writing nothing.                                                                       |
| `org`                | body | string                | —      | Org is the caller's OWN tenant, echoed so a client can build the public build URL (/builds/:org/:project) without a second call or a guess.                                                                               |
| `parentSessionId`    | body | string                | —      | ParentSessionID is the session that spawned this one, making this a subagent of it.                                                                                                                                       |
| `pr`                 | body | string                | —      | PR is the address of the pull request the run proposed.                                                                                                                                                                   |
| `progress`           | body | agent.sessionProgress | —      |                                                                                                                                                                                                                           |
| `progress.activity`  | body | string                | —      | Activity is the one line saying what the run is doing right now ("running the reaper's tests"), up to 120 characters, in the model's words.                                                                               |
| `progress.at`        | body | string                | —      | At is when this was determined, RFC 3339 in UTC to the second.                                                                                                                                                            |
| `progress.estimated` | body | boolean               | —      | Estimated says a MODEL produced this, from the run's transcript, and it may be wrong.                                                                                                                                     |
| `progress.pct`       | body | integer (int64)       | —      | Pct is how much of the run is done, 0 to 100.                                                                                                                                                                             |
| `progress.phase`     | body | string                | —      | Phase is what shape the run is in: running, blocked, done, error, or unknown when nothing has estimated it yet.                                                                                                           |
| `project`            | body | string                | —      | The readable build: the product this session built and whether its story is public (provenance.go).                                                                                                                       |
| `provider`           | body | string                | —      | Provider is the linked AI account's provider (claude \| codex \| hanzo \| …) that served this run.                                                                                                                        |
| `published`          | body | boolean               | —      | Published is the author's decision to let anyone read this session's story at the public build route.                                                                                                                     |
| `repo`               | body | string                | —      | Repo is the code the session is working on, as the surface reported it.                                                                                                                                                   |
| `room`               | body | string                | —      | Room is the collaborative room this run was started in (HIP-0523), empty when it came from anywhere else — a CLI, a schedule, an API call.                                                                                |
| `rootSessionId`      | body | string                | —      | RootSessionID is the top of this session's tree, inherited from the parent and shared by every node in one flow.                                                                                                          |
| `sandbox`            | body | string                | —      | Sandbox is the id of the sandbox the run works in ("m\_" and 24 hex), the handle its terminal and its screen are opened with (/v1/sandbox/{id}/terminal, /screen).                                                        |
| `startedAt`          | body | string                | —      | StartedAt is when the session opened, RFC 3339 in UTC to the second.                                                                                                                                                      |
| `status`             | body | string                | —      | Status is one of exactly four: running, paused, done, error.                                                                                                                                                              |
| `target`             | body | string                | —      | Target is the registered run-target this session is dispatched to — a machine the org claimed, resolved same-org when it was set, so it can never point at another tenant's computer.                                     |
| `taskRunId`          | body | string                | —      | TaskRunID is that workflow's particular run.                                                                                                                                                                              |
| `taskWorkflowId`     | body | string                | —      | TaskWorkflowID is the hanzoai/tasks durable workflow that actually EXECUTES this session — this registry is the view, control and stream layer over it.                                                                   |
| `terminal`           | body | string                | —      | Terminal is where this session can be WATCHED — the URL the machine published for its live terminal.                                                                                                                      |
| `title`              | body | string                | —      | Title is the human line a card shows ("ship the landing page"), up to 512 characters.                                                                                                                                     |
| `updatedAt`          | body | string                | —      | UpdatedAt is the session's last-activity clock, same format.                                                                                                                                                              |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo agent sessions create
```

**SDK**

**.ts**

```ts
import { Configuration, AgentApi } from 'hanzoai';

const api = new AgentApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.postAgentSessions({ account: "<account>", actor: "<actor>" });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import AgentApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = AgentApi(client).post_agent_sessions(account="<account>", actor="<actor>")
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.AgentAPI.PostAgentSessions(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, agent_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = agent_api::post_agent_sessions(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.AgentApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new AgentApi(client).postAgentSessions();
```

**HTTP**

```bash
curl -X POST https://api.hanzo.ai/v1/agent/sessions \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "account": "<account>",
       "actor": "<actor>"
     }'
```

**MCP**

MCP reaches **agent** through the `agent` tool, which names its 38 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_agents"
         }
       }
     }'
```

---

[Agent API](https://docs.hanzo.ai/docs/openapi/agent) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
