Context window

Context window

Ask questions about a persisted document after extraction with window_context enabled.

Context Window · Replace document

Replace a document's content

Endpoint

POSThttps://claix.dev/replace-document

Replaces 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

FieldTypeRequiredDescription
document_idstring (uuid)YesTarget document whose content is replaced. Keeps its id.
new_content_document_idstring (uuid)YesSource 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

  1. Extract the new document and keep its document_id as the source.
  2. Send POST with the stable target document_id and new_content_document_id (source).
  3. Keep using the same document_id in later queries; version will 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."
}
FieldTypeDescription
successbooleanAlways true in a 200 response.
swap_idstring (uuid)Identifier of the swap operation.
document_idstring (uuid)Target document (stable id).
source_document_idstring (uuid)Source document that was deleted.
file_namestringTarget document file name.
versionnumberVersion incremented after the swap.
swaps_countnumberCumulative number of replacements.
messagestringHuman-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

CodeCategoryRetry?
200Success — content replaced—
400Client error (invalid body or IDs)No — fix the request first
401Authentication errorNo — fix credentials first
404Target or source document not foundNo — fix the IDs first
405Incorrect HTTP methodNo — use POST
500Internal server errorYes, 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_id no longer exists — do not reuse it.
  • Always use the public claix.dev domain, not the direct Supabase URL.
  • Never ship your API key in frontend code or public repositories.

Request examples

curl -X POST "https://claix.dev/replace-document" \
  -H "x-api-key: <TU_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"document_id":"d4a1e9d2-8b1c-4f3e-9a02-8b1e9f3c7a4b","new_content_document_id":"a8c3f1e0-2d4b-4a9e-8c71-5f0e2b9d6a3c"}'