Developer API

Large files and chunked uploads

Per-plan file size limits and the resumable chunked upload for documents above 100 MiB: create, upload parts in any order, complete, poll and abort.

Per-file limits by plan

Website, API and SDK uploads share one per-file limit for your plan: Free, Plus, Pro, Developer D1 and Developer D2 100 MB; Developer D3 200 MB. It applies to the single-request upload and the chunked upload alike. Sizes are in MiB: 1 MiB = 1,048,576 bytes.

A file above your limit is refused with 413 UPLOAD_TOO_LARGE_FOR_PLAN; error.details.limitBytes is the limit that applied and error.details.plan is your plan.

PlanPer-file limitBytes
FREE100 MiB104,857,600
D1100 MiB104,857,600
D2100 MiB104,857,600
D3200 MiB209,715,200

When to use the chunked upload

  • POST /api/v2/documents takes the whole file in one request of at most 100 MiB. Above that it answers 413 DOCUMENT_SIZE_INVALID with details.uploadsUrl /api/v2/uploads.
  • Use the chunked upload for any file above 100 MiB, and for large files on unreliable connections: parts can be sent in parallel and resent after a failure.
  • Parts are stored as they arrive, so complete returns quickly. Free plans upload at up to 13 MB/s per account across all parts; paid plans are not limited.
  • The chunked upload costs one request unit, like POST /api/v2/documents. Parts, status reads, complete and abort are not metered.
  • Every call needs a key with the documents.write scope.

The flow

Steps

  1. Create the upload with POST /api/v2/uploads: filename, contentType, sizeBytes, an optional title, and the SHA-256 of the whole file (sha256, required above 50 MiB), with an Idempotency-Key header.

    • The answer is 201 with uploadId, partSizeBytes (8 MiB), partCount and expiresAt (24 hours). Repeating the call with the same Idempotency-Key returns the same upload.
    • If your workspace already stores a file with the same sha256 and size, the upload is created with status completed and a documentId: skip the parts and call complete to receive the new document. Nothing is uploaded or stored again.
  2. Send every part with PUT /api/v2/uploads/{uploadId}/parts/{index}, index 0 to partCount - 1, as raw bytes.

    • Each part is exactly partSizeBytes long except the last, which holds the rest of the file.
    • Send X-Part-SHA256 with the part's SHA-256 to have it verified on arrival.
    • Send parts in ascending order, several in parallel (the SDKs start with 8). A part may run up to 16 parts ahead of the lowest part not yet received; further ahead it is answered 503 UPLOAD_PART_AHEAD_OF_WINDOW with Retry-After.
    • Resending an identical part is accepted (alreadyReceived: true); different bytes at a received index return 409 UPLOAD_PART_CONFLICT.
  3. To resume after an interruption, GET /api/v2/uploads/{uploadId} and send only the indexes missing from receivedParts.

  4. Complete with POST /api/v2/uploads/{uploadId}/complete.

    • The file is checked against sizeBytes and sha256 and, for application/pdf, for a PDF header and trailer. The answer is 201 with the same {document, created} shape as POST /api/v2/documents.
    • If the request is interrupted, the answer may be 202 with the upload in status processing. Poll GET /api/v2/uploads/{uploadId} until status is completed (documentId and versionId are set) or failed.
  5. Abort an upload you no longer need with DELETE /api/v2/uploads/{uploadId}; its parts are deleted. Unfinished uploads expire after 24 hours.

Chunked upload with curl (8 MiB parts)
FILE=report.pdf; SIZE=$(stat -c %s "$FILE"); SHA=$(sha256sum "$FILE" | cut -d" " -f1)
UPLOAD=$(curl -sS https://wellfriend.dev/api/v2/uploads -H "Authorization: Bearer $WELLFRIEND_API_KEY" \
  -H "Content-Type: application/json" -H "Idempotency-Key: upload-$SHA" \
  -d "{\"filename\":\"$FILE\",\"contentType\":\"application/pdf\",\"sizeBytes\":$SIZE,\"sha256\":\"$SHA\"}")
ID=$(echo "$UPLOAD" | jq -r .uploadId); COUNT=$(echo "$UPLOAD" | jq -r .partCount)
for i in $(seq 0 $((COUNT - 1))); do
  dd if="$FILE" bs=8388608 skip=$i count=1 status=none | curl -sS -X PUT --data-binary @- \
    -H "Authorization: Bearer $WELLFRIEND_API_KEY" -H "Content-Type: application/octet-stream" \
    "https://wellfriend.dev/api/v2/uploads/$ID/parts/$i"
done
curl -sS -X POST "https://wellfriend.dev/api/v2/uploads/$ID/complete" -H "Authorization: Bearer $WELLFRIEND_API_KEY" \
  -H "Content-Type: application/json" -d "{}"

SDK helpers

  • Every SDK streams a file from disk: one request for a small file, the chunked upload above it (the SHA-256 computed while reading, each part retried on its own), never holding the whole file in memory. Every tool method uploads its input the same way.
  • TypeScript: wf.documents.upload(path) returns the stored Document. Python: wf.documents.create(path). Go: wf.Documents.Upload(ctx, wellfriend.File(path), nil). Rust: wf.documents().create(path).
  • MCP: document_upload_url issues one single-use URL for files up to 100 MiB. For larger files, upload with the API or an SDK and pass the documentId to the MCP tools.

Upload errors

CodeStatusMeaning
UPLOAD_TOO_LARGE_FOR_PLAN413The file is above your plan's per-file limit (details.limitBytes, details.plan).
UPLOAD_CHECKSUM_REQUIRED400sha256 is required for files above 50 MiB.
UPLOAD_ADMISSION_INVALID400A field or the Idempotency-Key is missing or invalid.
UPLOAD_PART_INDEX_INVALID400The index is outside 0 to partCount - 1.
UPLOAD_PART_SIZE_MISMATCH400The part is not exactly partSizeBytes (or the remainder for the last part).
UPLOAD_PART_CHECKSUM_MISMATCH422The part does not match X-Part-SHA256.
UPLOAD_PART_CONFLICT409Different bytes were already received at this index.
UPLOAD_PART_AHEAD_OF_WINDOW503The part is more than 16 parts ahead of the lowest part not yet received. Send earlier parts first; retry after Retry-After.
UPLOAD_CONTENT_INVALID422A file declared as application/pdf has no PDF header or trailer (for example, a truncated file). Start a new upload.
UPLOAD_INCOMPLETE409complete was called before every part arrived (details.missingParts).
UPLOAD_CHECKSUM_MISMATCH422The assembled file does not match sizeBytes and sha256. Start a new upload.
UPLOAD_NOT_WRITABLE409The upload is completed, processing or cancelled.
UPLOAD_EXPIRED410The upload expired after 24 hours. Start a new upload.
UPLOAD_NOT_FOUND404No upload with this id exists for the key's workspace and environment.
UPLOAD_SESSION_LIMIT_REACHED429Ten uploads are unfinished. Complete or abort one first.
UPLOAD_STORAGE_UNAVAILABLE503Retry with backoff; parts already received are kept.
PLATFORM_TEMPORARILY_UNAVAILABLE503The platform is busy. Retry after Retry-After; a part, complete and the status read are all safe to repeat.