> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://doc.pyramid-ai.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://doc.pyramid-ai.com/_mcp/server.

# Use the Agentic Chat

The agentic chat runs the agents enabled for your organization, with their skills and tools. It
lives under `/api/v2`; everything else in this API is under `/api/v1`.

## Before you begin

* You have an API key (`pai_test_*` or `pai_live_*`)
* Feature `api.agentic_chat` is enabled for your organization
* A turn runs as the user who created the API key, with the agents enabled for the organization

## Send a message

```bash
curl -X POST https://api-staging.pyramid-ai.com/api/v2/chat \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{ "role": "user", "content": "What is a means of escape?" }]
  }'
```

```json
{
  "success": true,
  "data": {
    "chat_id": "471a2149-5932-4a51-af79-12f71ce5668c",
    "status": "completed",
    "text": "A means of escape is ...",
    "card": null,
    "files": [],
    "protocol": "ui-message-stream-v1",
    "events": []
  },
  "request_id": "..."
}
```

* `text`, `card` and `files` are the fields to build on.
* `events` is the raw activity of the turn. Add `"include_events": false` to leave it out.
* The request waits up to 230 seconds. For long turns send `"stream": true` and read the event
  stream; the chat ID is in the `X-Chat-Id` header.

## Continue a chat

Send only the new message with the `chat_id`. The server keeps the history.

```bash
curl -X POST https://api-staging.pyramid-ai.com/api/v2/chat \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": "471a2149-5932-4a51-af79-12f71ce5668c",
    "messages": [{ "role": "user", "content": "Give me an example." }]
  }'
```

## Attach a file

#### Reserve the file

```bash
curl -X POST https://api-staging.pyramid-ai.com/api/v2/files \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{ "file_name": "level-3.pdf", "content_type": "application/pdf", "size_bytes": 482113 }'
```

The reply has a `file_id` and an `upload.url`. `size_bytes` must be the exact size of the file.

#### Send the bytes

```bash
curl -X PUT "UPLOAD_URL" \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE" \
  -H "Content-Type: application/pdf" \
  --data-binary @level-3.pdf
```

#### Name the file on a message

```bash
curl -X POST https://api-staging.pyramid-ai.com/api/v2/chat \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{ "role": "user", "content": "Check this drawing", "files": ["FILE_ID"] }]
  }'
```

PDF, PNG, JPEG, Markdown, XLSX and DOCX are accepted, up to 500 MB. An attached file is a chat
attachment. It does not enter your knowledge library; use [Documents](/howto/documents) for that.

## Choose an agent

By default the best agent is picked for each turn. To use a specific one, list the agents and pass
its `id`:

```bash
curl https://api-staging.pyramid-ai.com/api/v2/agents \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE"
```

```json
{ "messages": [{ "role": "user", "content": "..." }], "agent_id": "drawing-assistant" }
```

## Answer a card

Some skills stop and ask you to confirm inputs or choose an option. The reply then has
`"status": "awaiting_input"` and a `card`:

```json
"card": {
  "tool_call_id": "call_867a...",
  "name": "ask_user",
  "input": { "questions": [{ "id": "unit_system", "prompt": "Which unit system?", "options": [{ "id": "metric", "label": "Metric" }] }] }
}
```

Answer it in your next request:

```json
{
  "chat_id": "CHAT_ID",
  "card_response": {
    "tool_call_id": "call_867a...",
    "card": "ask_user",
    "action": "answer",
    "answers": [{ "questionId": "unit_system", "prompt": "Which unit system?", "selected": [{ "id": "metric", "label": "Metric" }] }]
  }
}
```

For a card that asks you to confirm inputs, use `"action": "confirm"` and send the card's rows back
in `values`.

## Download a generated file

Files the agent generates (a report, a marked-up drawing) are listed in `files`:

```bash
curl https://api-staging.pyramid-ai.com/api/v2/files/FILE_ID \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE"
```

The reply has a `download_url` that is valid for `expires_in` seconds (300 by default; set `ttl`
between 60 and 3600).

## Manage chats

```bash
# List, newest first
curl "https://api-staging.pyramid-ai.com/api/v2/chat?limit=20" \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE"

# Read one chat with its messages
curl https://api-staging.pyramid-ai.com/api/v2/chat/CHAT_ID \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE"

# Rename
curl -X PATCH https://api-staging.pyramid-ai.com/api/v2/chat/CHAT_ID \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE" \
  -H "Content-Type: application/json" \
  -d '{ "title": "Level 3 cooling check" }'

# Delete
curl -X DELETE https://api-staging.pyramid-ai.com/api/v2/chat/CHAT_ID \
  -H "Authorization: Bearer pai_test_YOUR_KEY_HERE"
```