Upload documents
POST /documents accepts one file per request as the raw request body. It requires the documents:write scope.
POST /v1/documents?export=txt&export=json HTTP/1.1Host: api.sonicdocs.aiAuthorization: Bearer <api-key>Content-Type: application/pdfIdempotency-Key: upload-6f1c2d0e-5d6b-4c0e-9a51-1f6f3f1d2b7a
<PDF bytes>Supported files
Section titled “Supported files”| Media type | Notes |
|---|---|
application/pdf |
Pages are numbered from 1. Password-protected and corrupted PDFs are rejected. |
image/png, image/jpeg |
Each image is one page. |
The Content-Type header, the file’s bytes and a successful parse must all agree. A wrong media type returns 415 unsupported_media_type; an empty, corrupted, truncated or password-protected file returns 422 invalid_document. A file over the size, page or pixel limit returns 413 document_limit_exceeded. See limits for the values.
Query parameters
Section titled “Query parameters”| Parameter | Default | Meaning |
|---|---|---|
export |
txt |
Output format to publish. Repeat it to ask for several: txt, html, markdown, json. See output formats. |
chunk_pages |
400 |
Largest number of pages processed as one unit, from 1 to 400. It affects how progress is reported, not the outputs. |
profile |
your default | A named processing profile your tenant is authorized to use. Unknown or unauthorized profiles return 422 unsupported_profile. |
Options are resolved once, at upload. The receipt and status show the effective output_plan and chunk_pages.
The receipt
Section titled “The receipt”The service answers 202 Accepted only after the file and the processing job are stored durably. The Location header equals links.status.
{ "document_id": "a~d17", "trace_id": "86bc31a843374ae6b6a3def26d08a011", "state": "accepted", "chunk_pages": 400, "output_plan": { "formats": [ "txt" ], "transformations": [] }, "links": { "status": "https://docs.example/documents/a~d17", "history": "https://docs.example/documents/a~d17/events", "result": "https://docs.example/documents/a~d17/result", "event_tickets": "https://docs.example/documents/a~d17/event-tickets", "events": "wss://docs.example/documents/a~d17/events" }, "expires_at": "2026-12-07T20:00:00Z"}trace_id identifies the upload in diagnostics; upload errors include it too. expires_at is fixed at upload: the source, outputs and events are deleted seven days later.
Idempotency and retries
Section titled “Idempotency and retries”Idempotency-Key is required. It must be 16 to 128 characters of ASCII letters, digits, underscores or hyphens; otherwise the response is 400 invalid_idempotency_key. Generate a new key for each file, store it with the file before you send it, and reuse it if you retry.
A key is bound to your tenant and to the exact upload: the file’s bytes, its media type and the resolved options. Retrying with the same key:
| Situation | Response |
|---|---|
| Same bytes and options | 202 with the original receipt and Idempotency-Replayed: true, even if the document has finished since. The receipt is historical; read links.status for current state. |
| Different bytes or options | 409 idempotency_conflict |
| The first upload is still arriving | 409 admission_in_progress with Retry-After |
| The document was deleted or has expired | 410 document_gone |
The binding lasts at least 24 hours. A retry after that may create a new document. A replayed upload is not charged again.
This makes it safe to retry after a timeout or a dropped connection: if the first attempt was admitted, the retry returns its receipt instead of creating a duplicate.
Rate limits and capacity
Section titled “Rate limits and capacity”Tenant rate and queue limits return 429 quota_exceeded; a busy processing owner returns 503 owner_busy. Both carry Retry-After in seconds. Wait that long and retry with the same Idempotency-Key. The quickstart examples do this. The request body must arrive within 10 minutes.