Documents
Uploading Documents
POST /v1/documents creates a document and supports two upload modes based on whether the content field is provided.
Sync Upload
Include the file as a base64 data-URI in content. The API decodes the buffer, uploads to GCS immediately, and returns the document with upload_status: "completed". A single API call completes the upload.
The MIME type is extracted from the data-URI prefix — no separate mime_type field is needed.
Best for: Files already in memory as base64, small-to-medium sizes, or when you prefer a single round-trip.
Async Upload
Omit content and provide mime_type instead. The API creates a requested DB record and returns a signed GCS PUT URL. The client PUTs the file bytes directly to GCS — the API server never proxies the bytes.
Best for: Large files, browser-based uploads, or when you want to stream bytes directly to GCS.
Upload Status
The upload_status field tracks the state of the upload.
Verification behavior
When POST /v1/documents/:id is called on a requested document, the API does a GCS HEAD check:
- File is present →
upload_statustransitions to"completed".file.sizeandfile.mime_typeare populated from GCS metadata. - File not yet present →
422 "File not yet available in storage". The internalcounterincrements. - Counter reaches 5 →
upload_statustransitions to"failed"and422 "Upload window expired. Create a new document."is returned. A new document must be created.
Request Fields
Linking Resources at Creation
Pass a resources object to create links atomically with the document:
The resource type is inferred from the ID prefix. See Links for all accepted prefixes and the add/remove/set pattern.