# Traces API

> List, read, create, update and delete traces.

Traces are addressed by their external ID, the ID the CLI generates from the agent session.

| Method and path | Scope | Purpose |
| --- | --- | --- |
| `GET /v1/traces` | `traces:read` | Traces of the active namespace; `limit`, `gitRemoteUrl` |
| `GET /v1/traces/{externalId}` | `traces:read` | One trace |
| `HEAD /v1/traces/{externalId}` | `traces:read` | Existence check; returns a `Traces-Published-At` header |
| `PUT /v1/traces/{externalId}` | `traces:write` | Upsert metadata |
| `PATCH /v1/traces/{externalId}` | `traces:write` | Change metadata or visibility |
| `DELETE /v1/traces/{externalId}` | `traces:write` | Delete |
| `POST /v1/traces/{externalId}/transfer` | `traces:write` | Move to another namespace: `{"targetNamespaceId": "..."}` |
| `GET /api/v1/traces/{id}/download` | `traces:read` | Export as `jsonl` or `markdown` with `?format=` |

## Upsert body

All fields are optional: `agentId`, `title`, `projectPath`, `projectName`, `model`, `tokenUsage`, `visibility` (`public`, `direct`, `private`), `gitRemoteUrl`, `gitBranch`, `gitRef`, `relatedTo`, `relationshipType` (`subagent` or `resume`), `sourceCreatedAt` (epoch milliseconds).

```bash
curl -X PUT https://adtraces.adfactory.app/v1/traces/my-session-1 \
  -H "Authorization: Bearer $TRACES_API_KEY" -H "Content-Type: application/json" \
  -d '{"agentId":"claude-code","title":"Fix login redirect","visibility":"private"}'
```

Then upload the messages, see [Messages](/docs/api/messages).
