# Sessions

> Create, list, fetch and delete stored sessions that keep a conversation on Antarya's side.

## Create a session

`POST https://antarya.ai/v1/sessions`

A session holds the turns of one conversation. Create it, then pass its id as `session_id` on [`/v1/chat`](https://antarya.ai/docs/api/chat.md). The [guide](https://antarya.ai/docs/guides/sessions.md) shows the whole path.

```bash
curl https://antarya.ai/v1/sessions \
  -H "Authorization: Bearer $ANTARYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"metadata": {"matter": "supply-agreement"}}'
```

```python
from antarya import Antarya

client = Antarya()

session = client.sessions.create(metadata={"matter": "supply-agreement"})
print(session.id)
```

```typescript
import Antarya from "antarya";

const client = new Antarya();

const session = await client.sessions.create({ metadata: { matter: "supply-agreement" } });
console.log(session.id);
```

Output:

```
{
  "id": "sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31",
  "object": "session",
  "created_at": "2026-11-27T09:30:00Z",
  "updated_at": "2026-11-27T09:30:00Z",
  "metadata": {"matter": "supply-agreement"}
}
```

- `metadata` (object, optional): Up to 16 key and value pairs of your own, such as a matter name. Keys are at most 64 characters and values at most 512.

## The session object

- `id` (text, required): The id to pass as session_id, such as sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31. It is `sess_` followed by 32 lowercase hex characters.
- `object` (text, required): Always "session".
- `created_at` (text, required): When the session was created, as an ISO 8601 time.
- `updated_at` (text, required): When a turn was last saved to it, as an ISO 8601 time.
- `metadata` (object, required): The pairs you set when you created it.
- `messages` (array, optional): The saved turns, oldest first. Only on a fetch of one session.

## List, fetch and delete

| Request | Does |
|---|---|
| `GET /v1/sessions` | Lists your sessions, newest first, in pages. |
| `GET /v1/sessions/{id}` | Returns one session object with its `messages`. |
| `DELETE /v1/sessions/{id}` | Deletes the session and the turns stored in it. |

```bash
curl "https://antarya.ai/v1/sessions?limit=20" \
  -H "Authorization: Bearer $ANTARYA_API_KEY"

# the id comes from the create reply
curl https://antarya.ai/v1/sessions/sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31 \
  -H "Authorization: Bearer $ANTARYA_API_KEY"

curl -X DELETE https://antarya.ai/v1/sessions/sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31 \
  -H "Authorization: Bearer $ANTARYA_API_KEY"
```

```python
sessions = client.sessions.list(limit=20)
for s in sessions.data:
    print(s.id)
if sessions.has_more:
    next_page = client.sessions.list(limit=20, after=sessions.data[-1].id)

session = client.sessions.get("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31")
print(session.messages)

client.sessions.delete("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31")
```

```typescript
const sessions = await client.sessions.list({ limit: 20 });
for (const s of sessions.data) console.log(s.id);
if (sessions.has_more) {
  const nextPage = await client.sessions.list({ limit: 20, after: sessions.data.at(-1)!.id });
}

const session = await client.sessions.get("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31");
console.log(session.messages);

await client.sessions.delete("sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31");
```

Output:

```
{
  "id": "sess_4f2a9c1e7b3d48a6915e0c2d8f7a6b31",
  "deleted": true
}
```

## Paging

A list returns at most `limit` sessions, newest first. The reply is `{"object": "list", "data": [...], "has_more": true}`. When `has_more` is true there is another page: pass the id of the last session you received as `after` to get it.

- `limit` (number, optional): How many sessions to return. The default is 20 and the most is 100.
- `after` (text, optional): A session id. The list continues with the sessions after it.

## Limits

| Limit | Value |
|---|---|
| Sessions an account | 1,000 |
| Who can use a session | Every key on the account |

- Creating a session past 1,000 is a 400 `invalid_request`: "An account can hold up to 1,000 sessions. Delete one to make room."
- A session of another account is a 403 `permission_error`. An unknown id is a 404 `not_found`. A bad `after` is a 400.
- On success, `/v1/chat` saves the new turns and the reply. A failed or refused request saves nothing.
- Management requests share the 60 a minute per key allowance in [rate limits](https://antarya.ai/docs/api/rate-limits.md).

## Next steps

- [Sessions guide](https://antarya.ai/docs/guides/sessions.md): Create a session and continue it turn by turn.
- [Chat](https://antarya.ai/docs/api/chat.md): Pass session_id on a chat request.
- [Errors](https://antarya.ai/docs/api/errors.md): Every status and what to do about it.
