Context window

Context window

Ask questions about a persisted document or across a knowledge space.

Context Window

Query a persisted document

Endpoint

POSThttps://claix.dev/document-context/{document_id}

This endpoint answers questions about a document already extracted with window_context enabled. The document_id is in the URL (returned by the extraction call) and the questions go in a simple JSON body.

Public URL: POST https://claix.dev/document-context/{document_id}. Never expose the raw Supabase URL.

Designed for server-to-server integrations. Requires a secret API key.

1. Authentication

Every request must include your API key.

Option A — Dedicated header (recommended):

x-api-key: <YOUR_API_KEY>

Option B — Standard Authorization header:

Authorization: Bearer <YOUR_API_KEY>

The system checks that the key exists and is active, and that the account is not suspended. Failures return 401.

2. Request format

HTTP method: POST · Content-Type: application/json

document_id (UUID) is part of the path. The body has a single field:

FieldTypeRequiredDescription
questionsarray of { question, format }YesTyped questions answered from the persisted markdown only. Max 5. question: string ≤400 chars. format: string | int | boolean | timestamp | array.
{
  "questions": [
    { "question": "What is the exact penalty for early cancellation?", "format": "string" },
    { "question": "Which company is listed as the tenant, and what is its tax ID?", "format": "string" }
  ]
}
  • At least 1 question; at most 5.
  • Each item must include question (non-empty) and format as one of: string, int, boolean, timestamp, array.
  • Each ia_response item matches that type (or null if missing or not safely typed).
  • The document must belong to the API key account and must not have expired.

3. Step-by-step request

  1. Extract a file with window_context: true and save the document_id from the response.
  2. Obtain your API key.
  3. POST to https://claix.dev/document-context/{document_id}.
  4. Send { "questions": [{ "question": "...", "format": "string" }] } as JSON.
  5. Check HTTP 200 and read ia_response.

4. Request examples

See the right-hand panel for cURL, JavaScript, Node.js, Python, PHP, and n8n examples.

5. Successful response

Status: 200 OK · Content-Type: application/json

{
  "user_ask": [
    { "question": "¿Cuál es la penalización exacta por cancelación anticipada?", "format": "string" },
    { "question": "¿Qué empresa figura como arrendataria y cuál es su CIF?", "format": "string" }
  ],
  "ia_response": [
    "El 15 % del importe restante del contrato.",
    "Inversiones Delta S.L., CIF B12345678"
  ],
  "log_id": "7c2e1a90-4b3d-4f8a-9e21-6d5c8b0a1f34"
}
FieldTypeDescription
user_askarray of { question, format }The questions you sent (with their format), in the same order.
ia_responsetyped arrayAnswers 1:1 with user_ask, typed by format (string, int, boolean, timestamp, array) or null. With source verification, each item is { value, source }.
log_idstring (UUID)UUID of this call’s usage_logs row. Present on success and on most authenticated errors.

The response includes log_id when the usage_logs row could be stored.

If source verification is enabled on document queries, each ia_response item is { "value": ..., "source": "..." }. source quotes the phrases or snippets from the persisted plain-text content that support the answer. If there is no evidence, source is requires_human_revision.

Example with source verification enabled:

{
  "user_ask": [
    { "question": "¿Cuál es la penalización exacta por cancelación anticipada?", "format": "string" }
  ],
  "ia_response": [
    {
      "value": "El 15 % del importe restante del contrato.",
      "source": "penalización del 15 % del importe restante en caso de cancelación anticipada"
    }
  ],
  "log_id": "7c2e1a90-4b3d-4f8a-9e21-6d5c8b0a1f34"
}

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 document_id, malformed JSON, missing questions, empty array, more than 5 items, a question longer than 400 characters, or a missing/invalid format (string | int | boolean | timestamp | array).

401 — Missing, invalid, or inactive API key, or suspended account.

404 — Document does not exist, does not belong to the account, or has expired.

502 — AI service failure. 405 — Method other than POST. 500 — Unexpected server error.

7. Error code summary

CodeCategoryRetry?
200Success—
400Client error (malformed document or data)No — fix the request first
401Authentication errorNo — fix credentials first
404Resource not foundNo — fix schema_id first
405Incorrect HTTP methodNo — fix the method first
413File or extracted text too largeNo — reduce size first
422No extractable dataNo — review document/schema first
500Internal server errorYes, with caution
502AI service failureYes, recommended with backoff

Request examples

curl -X POST "https://claix.dev/document-context/3c7a9f21-4b8e-4d1a-9c6f-2e0d8a5b7c4f" \
  -H "x-api-key: <TU_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "questions": [
      { "question": "¿Cuál es la penalización exacta por cancelación anticipada?", "format": "string" },
      { "question": "¿Qué empresa figura como arrendataria y cuál es su CIF?", "format": "string" }
    ]
  }'