# Ingestion API

`POST /api/ingest` validates normalized JSON traces, stores the raw payload, queues an ingest job, and returns immediately.

The generated reference page for this flow is [Queue trace ingestion](/api-reference/selltraces-ingest/post-api-ingest).

## Authentication

`POST /api/ingest` accepts either:

- a bearer token from the CLI
- a signed-in browser session

## Contributor Terms

The account must have accepted the current
[Sell Traces Contributor Terms](https://app.rebates.ai/legal/sell-traces) before
it can upload. Until then the endpoint stores nothing and returns `403` with
`error: "terms_required"` and an `acceptUrl` for the dashboard acceptance page.
The `selltraces` CLI prints that URL, opens it in an interactive terminal, and
exits non-zero; run the upload again after accepting.

## JSON trace upload

```http
POST /api/ingest
Authorization: Bearer <token>
Content-Type: application/json

{
  "traces": [
    {
      "source": "codex_jsonl",
      "sourceId": "session-123",
      "model": "gpt-5",
      "createdAt": "2026-06-04T12:00:00.000Z",
      "messages": [
        {
          "position": 0,
          "role": "user",
          "content": "Build a trace uploader.",
          "tokenCount": 6,
          "createdAt": "2026-06-04T12:00:00.000Z"
        }
      ]
    }
  ]
}
```

JSON uploads can include up to 1,000 traces per request. Long traces are accepted; the server does not reject a trace because of its token count, message count, or per-message content length.

The server recounts message tokens and ignores client-supplied token counts for payout-sensitive accounting.

## Queued response

```json
{
  "ok": true,
  "jobId": "019e...",
  "status": "queued"
}
```

The HTTP status is `202`.

## Server processing

The background worker loads the raw JSON upload blob, then calls the ingest pipeline. The pipeline normalizes, scrubs, rejects high-risk PII, scores, deduplicates, inserts trace/message rows, and writes raw plus derived blobs.
