Agent mode API

Agent mode endpoints

Structured extraction plus semantic reasoning with agent_definition parameters.

Doc-to-JSON · Agent mode

Document to JSON with Agent mode

Endpoint

POSThttps://www.claix.dev/agent/doc-json

Agent mode active

This endpoint runs structured extraction from the main schema first, then a reasoning phase with agent_definition. The response includes data[] (extraction) and agent_data (typed inference). The schema must have is_agent_mode enabled.

This endpoint accepts a text document file (.docx, .txt, .md, or .rtf) and returns a single JSON object with the extracted data, following exactly the structure you define in advance via a schema.

Document text is extracted deterministically before any AI model is invoked: .docx is unpacked, .txt/.md is decoded as UTF-8, or .rtf is stripped of control codes. Only the resulting plain text is analyzed — any file format issue (corruption, unsupported format, empty document) is detected and rejected before any AI call is made.

It is intended for server-to-serverintegrations (backends, scripts, n8n/Zapier/Make). It must not be called from an end user's browser because it requires a secret API key.

Like pdf-json, this endpoint treats the full document as a single data source and returns one object with your schema properties — suited for contracts, reports, letters, minutes, text forms, or any document where you need to extract a specific set of fields.

1. Authentication

Every request must include your API key. It is a personal server credential, distinct from any user session token, and should be handled with the same care as a database password.

You can send it in two ways, both valid and equivalent:

Option A — Dedicated header (recommended):

x-api-key: <YOUR_API_KEY>

Option B — Standard Authorization header:

Authorization: Bearer <YOUR_API_KEY>

You do not need to send both headers at once; either one is sufficient. If you send both, the x-api-key header takes priority.

What happens if authentication fails

Before processing any file, the system validates:

  • That the API key exists and is active.
  • That the account associated with that API key is in active status (not suspended).

If any of these checks fail, the request is rejected immediately with status code 401, without processing the attached document.

2. Request format

HTTP method: POST

Content-Type: multipart/form-data (required)

The request must be built as a multipart form (the same type as when uploading a file from an HTML <form> with enctype="multipart/form-data", or when using FormData in JavaScript, multipart/form-data in Python requests, or a Form-Data body in Postman/n8n/Insomnia).

Fields the form must contain

FieldTypeRequiredDescription
fileBinary fileYesThe document to analyze. Must be the file itself, not a path or URL.
schema_idText (UUID)YesIdentifier of the schema that defines the output JSON structure. Must be a schema previously created in your account, of the type corresponding to this endpoint.

Additional fields with other names for the file are not supported (for example, documento, doc, upload) — the file field name must be exactly file, and the schema identifier field exactly schema_id.

Important schema requirement

The schema_id must correspond to a schema configured specifically for document-to-JSON extraction. If you send the identifier of a schema intended for another conversion direction (for example, Excel to JSON or PDF to JSON), the request will be rejected with a 400 error without processing the file.

Supported file formats

FormatExtensionExpected MIME typeNotes
Modern Word.docxapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentText is extracted; images, styles, and metadata are discarded.
Plain text.txttext/plainDecoded directly as UTF-8.
Markdown.mdtext/markdownDecoded as plain text; Markdown syntax is neither interpreted nor removed.
Rich Text Format.rtfapplication/rtfBest-effort text extraction; for complex RTF documents, .docx or .txt offer greater reliability.

Explicitly NOT supported format: .doc (Word 97-2003, legacy binary format). If you send a file of this type (application/msword, or .doc extension), the request is rejected with 400 and a message asking you to convert it to .docx first.

If the file MIME type does not exactly match the table (some clients send generic types such as application/octet-stream), the system also checks the file name extension as a fallback.

File requirements

  • The file cannot be empty (0 bytes).
  • Maximum supported size: 10 MB. If you send a larger file, the request is rejected with status code 413 before attempting to process it.
  • Extracted document text cannot exceed 300,000 characters. This is a limit independent of the original file size. If exceeded, the request is rejected with 413 after extraction but before calling the AI.
  • The document must contain extractable text. An empty document, or one composed only of images without text, will be rejected.

3. How to build the request step by step

  1. Have your API key ready.
  2. Have the schema_id of the corresponding schema ready (previously created in your account, of the correct type for this endpoint).
  3. Build a POST request to the endpoint URL.
  4. Add the authentication header (x-api-key or Authorization: Bearer).
  5. Build the body as multipart/form-data with two parts: a file part with field name file, and a text part with field name schema_id containing the UUID as a string.
  6. Send the request and wait for the response.
  7. Check the HTTP status code before assuming success: only 200 indicates the document was processed correctly.

4. Request examples

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

5. Successful response format

200 OK · Content-Type: application/json

{
  "success": true,
  "schema_utilizado": "Contratos legales",
  "total_registros": 1,
  "data": [
    {
      "parte_a": "Inmobiliaria Norte S.L.",
      "parte_b": "Carlos Méndez",
      "fecha_firma": "2026-03-01"
    }
  ],
  "agent_data": {
    "clausula_penalizacion": true,
    "tipo_renovacion": "automatica",
    "resumen_contrato": "Arrendamiento con renovación automática y cláusula de penalización por impago."
  }
}
FieldTypeDescription
successbooleanAlways true when HTTP is 200.
schema_utilizadostringName of the schema used for extraction.
total_registrosnumberNumber of records in data.
dataarrayObjects extracted from the main schema (same as extraction mode).
agent_dataobjectTyped Agent Mode answers per agent_definition (booleans, numbers, strings).

6. Error codes

Every error response is JSON, with at least an error field containing a readable message. Some errors also include a detalle field with additional technical information.

{
  "error": "Descripción legible del problema.",
  "detalle": "Información técnica adicional (solo presente en algunos casos)."
}

400 — Invalid request

Specific cases:

  • The file field was not sent, or it is not a valid file.
  • The schema_id field was not sent.
  • The body could not be parsed as multipart/form-data.
  • The file is empty (0 bytes).
  • The file format is not among the supported ones (.docx, .txt, .md, .rtf).
  • A .doc file was sent (legacy Word 97-2003 format) — specific message asking to convert it to .docx.
  • The .docx is corrupt or could not be opened as a valid ZIP.
  • The .docx does not contain the expected internal structure (word/document.xml).
  • No text could be extracted from the document (empty content, or only images).
  • The schema indicated in schema_id is not of the correct type for this endpoint.

401 — Unauthorized — API key missing, nonexistent, deactivated, or account not active.

404 — Not found — The schema_id does not exist or does not belong to your API key account.

413 — File or text too large — The file exceeds 10 MB, or extracted text exceeds 300,000 characters.

422 — Unprocessable — Text was extracted successfully but no data related to your schema could be extracted.

502 — Processing service failure — Communication issue with the AI service (transient; retry with backoff).

405 — Method not allowed — HTTP method other than POST.

500 — Internal error — Unexpected server-side problem.

7. Quick 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

8. Best practices

  • Validate the HTTP status code before attempting to read data[0] from the response; a 4xx or 5xx error will not have that structure.
  • Prefer .docx or .txt over .rtf when you have the option: extraction from the first two formats is more reliable than .rtf.
  • If you generate documents yourself from another system, consider exporting directly to .txt or .md when visual layout does not matter.
  • Remember that data always contains exactly one element on this endpoint — one per full document, not per page or section.
  • Implement automatic retries only for status codes 500 and 502, never for 400, 401, 404, 413, or 422.
  • The clearer your schema property descriptions, the better the extraction accuracy.
  • Do not include your API key in frontend code or public repositories.

Request examples

curl -X POST "https://www.claix.dev/agent/doc-json" \
  -H "x-api-key: <TU_API_KEY>" \
  -F "file=@./contrato_alquiler.docx" \
  -F "schema_id=b980cfe7-61ef-4a5a-9724-881c8a5541e2"