Context Window · Replace document
Replace a document's content
Endpoint
https://claix.dev/replace-documentReplaces the content of document_id with the content of new_content_document_idvia an RPC. The source document is deleted. The target document's version is incremented.
Keeps the same document_id (and its space, if any) while you refresh the content from a new extraction.
Public URL: POST https://claix.dev/replace-document. Never expose the direct Supabase URL.
This call is free: it is not billed and does not consume your extraction or context-window quota.
1. Authentication
Every request must include your API key. It is a personal server-side credential, different from any user session token.
Option A — Dedicated header (recommended):
x-api-key: <YOUR_API_KEY>
Option B — Standard Authorization header:
Authorization: Bearer <YOUR_API_KEY>
Either one is enough. If you send both, x-api-key wins.
Claix checks that the key exists and is active. Otherwise it returns 401. Both documents must belong to your account.
2. Request format
Method: POST · Content-Type: application/json
| Field | Type | Required | Description |
|---|---|---|---|
| document_id | string (uuid) | Yes | Target document whose content is replaced. Keeps its id. |
| new_content_document_id | string (uuid) | Yes | Source document whose content is copied. Deleted after the swap. |
Example body:
{
"document_id": "d4a1e9d2-8b1c-4f3e-9a02-8b1e9f3c7a4b",
"new_content_document_id": "a8c3f1e0-2d4b-4a9e-8c71-5f0e2b9d6a3c"
}3. Building the call
- Extract the new document and keep its
document_idas the source. - Send
POSTwith the stable targetdocument_idandnew_content_document_id(source). - Keep using the same
document_idin later queries;versionwill have increased.
4. Request examples
Use the code panel on the right to copy examples in cURL, JavaScript, Python, and more.
5. Success response format
HTTP 200 — Content replaced; the source document has been deleted.
{
"success": true,
"swap_id": "c1e7a4b2-9f0d-4e8a-b3c5-1d2e3f4a5b6c",
"document_id": "d4a1e9d2-8b1c-4f3e-9a02-8b1e9f3c7a4b",
"source_document_id": "a8c3f1e0-2d4b-4a9e-8c71-5f0e2b9d6a3c",
"file_name": "factura.pdf",
"version": 2,
"swaps_count": 1,
"message": "Contenido sustituido. El documento fuente ha sido eliminado."
}| Field | Type | Description |
|---|---|---|
| success | boolean | Always true in a 200 response. |
| swap_id | string (uuid) | Identifier of the swap operation. |
| document_id | string (uuid) | Target document (stable id). |
| source_document_id | string (uuid) | Source document that was deleted. |
| file_name | string | Target document file name. |
| version | number | Version incremented after the swap. |
| swaps_count | number | Cumulative number of replacements. |
| message | string | Human-readable confirmation. |
6. Error codes
{
"error": "Descripción legible del problema.",
"detalle": "Información técnica adicional (solo presente en algunos casos).",
"log_id": "7c2e1a90-4b3d-4f8a-9e21-6d5c8b0a1f34"
}400 — Invalid body, malformed UUIDs, or the operation is not valid (for example, identical ids).
401 — Authentication failed: key missing, unknown, disabled, or account not active.
404 — Either document does not exist or does not belong to your account.
405 — Method other than POST. · 500 — Internal error.
7. Code summary
| Code | Category | Retry? |
|---|---|---|
| 200 | Success — content replaced | — |
| 400 | Client error (invalid body or IDs) | No — fix the request first |
| 401 | Authentication error | No — fix credentials first |
| 404 | Target or source document not found | No — fix the IDs first |
| 405 | Incorrect HTTP method | No — use POST |
| 500 | Internal server error | Yes, with caution |
8. Best practices
- Keep a stable business
document_id; use temporary extractions only as the swap source. - After the swap,
new_content_document_idno longer exists — do not reuse it. - Always use the public
claix.devdomain, not the direct Supabase URL. - Never ship your API key in frontend code or public repositories.