One request
POST https://wellfriend.dev/api/v2/documents with the raw file as the request body (scope documents.write). The response contains the document and its first version. One request carries at most 100 MiB; for a larger file, or a resumable upload on an unreliable connection, use the chunked upload (POST /api/v2/uploads) described on /docs/developer-api/uploads. Either way, the file must fit your plan's per-file limit.
Request headers
| Header | Required | Rule |
|---|---|---|
| Authorization | Yes | Bearer <v2 key> |
| Content-Type | Yes | The document's media type, for example application/pdf |
| Content-Length | Yes | The exact byte length; at most 100 MiB in one request (details.maximumBytes and details.uploadsUrl on 413 DOCUMENT_SIZE_INVALID) |
| X-Wellfriend-Filename | Yes | 1 to 255 characters |
| X-Wellfriend-Title | No | Up to 500 characters; defaults to the filename |
| X-Content-SHA256 | No | 64 hexadecimal characters; if the received bytes do not match, nothing is stored |
| Idempotency-Key | Yes | 8–200 letters, digits, period, underscore, colon or hyphen |
Responses
- 201 with { document, created: true } when a new document was stored.
- 200 with created false when the same idempotency key repeats an earlier upload; nothing new is stored or charged.
- 400
DOCUMENT_ADMISSION_INVALIDwhen a header is missing or malformed. - 413
DOCUMENT_SIZE_INVALIDwhen Content-Length is missing or over the single-request limit; use POST/api/v2/uploadsinstead. - 413
UPLOAD_TOO_LARGE_FOR_PLANwhen the file is above your plan's per-file limit (details.limitBytes, details.plan).
Recovering from failures
| Situation | What to do |
|---|---|
| Dropped connection or timeout | Repeat the identical request with the same idempotency key |
500 DOCUMENT_CREATE_FAILED | Retry with the same idempotency key; it is retryable |
| Repeated 500 with X-Content-SHA256 set | A checksum mismatch also fails as DOCUMENT_CREATE_FAILED: recompute the SHA-256 of the exact bytes you send, then retry |
| Wrong file or metadata | Upload the correct file as a new request with a new idempotency key |
Security
- Check that your user may send the file before you read or forward it.
- Never expose the API key to the browser.
- Sanitize filenames before you display them, and treat the declared content type as a claim, not a fact.
- Do not write document bytes to logs or error reports.