# Messages API

> List and upload the messages of a trace.

| Method and path | Scope | Purpose |
| --- | --- | --- |
| `GET /v1/traces/{externalId}/messages` | `traces:read` | List messages; `limit`, `cursor`, `includeParts`, `filter=highlights` |
| `PUT /v1/traces/{externalId}/messages/{messageId}` | `traces:write` | Upsert one message |
| `POST /v1/traces/{externalId}/messages/batch` | `traces:write` | Upsert up to 1000 messages, at most 8 MiB per request |

## Message body

`role` is required: `user`, `assistant` or `system`. Optional: `externalId`, `idScheme` (`v1` or `v2`), `sourceKey`, `textContent`, `model`, `order`, `timestamp`, `tokenUsage`, and `parts`.

Each part has `type` (`text`, `thinking`, `tool_call`, `tool_result`, `error`, `system_event`), `content` (an object) and `order`.

```bash
curl -X POST https://adtraces.adfactory.app/v1/traces/my-session-1/messages/batch \
  -H "Authorization: Bearer $TRACES_API_KEY" -H "Content-Type: application/json" \
  -d '{"messages":[{"externalId":"m1","role":"user","textContent":"Fix the redirect","order":0}]}'
```

Pagination: pass the `nextCursor` of a response as `cursor` in the next call.
