API Errors

Error codes, response format, and troubleshooting for the Context212 API

When an API request fails, the Context212 API returns a JSON error with a consistent envelope. Use the machine-readable error code for programmatic handling, and detail for debugging.

Handle errors by code

Branch on error (and fields[].error for validation). Do not parse detail — the text may change between versions.

Error response format

All /api/v1/ error responses share this envelope:

{
  "id": null,
  "code": 400,
  "error": "bad_request",
  "detail": "file_id cannot be combined with workspace_id or tag_id.",
  "doc_url": "https://developers.context212.com/errors#bad_request"
}
FieldTypeDescription
idstring | nullResource or job identifier, when one exists at error time. null for most errors.
codeintegerHTTP status code (mirrors the response status).
errorstringMachine-readable error code. Use this for programmatic error handling.
detailstringHuman-readable explanation. May change between versions — do not parse.
doc_urlstringLink to the relevant section of this page.
indexinteger (optional)0-based position of the failing action in a batch request. Only present on errors from dedicated /batch endpoints.

Validation errors (422)

Requests that fail field-level validation return 422 Unprocessable Entity with an additional fields key mapping each invalid field to its errors:

{
  "id": null,
  "code": 422,
  "error": "validation_error",
  "detail": "One or more fields failed validation.",
  "doc_url": "https://developers.context212.com/errors#validation_error",
  "fields": {
    "name": [
      {"error": "required", "detail": "Field required"}
    ],
    "max_results": [
      {"error": "too_large", "detail": "Input should be less than or equal to 50"}
    ]
  }
}

Each entry in fields is an array of {error, detail} objects. A single field can have multiple errors. The error value is a field error code your application can map to form field states.

Batch error responses

Dedicated batch endpoints execute multiple actions in one request. When a batch request fails, the error response includes an index field — the 0-based position of the action that caused the failure:

{
  "id": null,
  "code": 400,
  "error": "bad_request",
  "detail": "The requested action is invalid.",
  "doc_url": "https://developers.context212.com/errors#bad_request",
  "index": 2
}

All error types (400, 403, 404, 422) include index when triggered inside a batch. Single-action requests never include this field.

Replay safety

Actions before the failing index are committed but their results are not returned. All action verbs are idempotent — re-send the entire batch after fixing the failing action to complete it.

HTTP status codes

StatusMeaningTypical action
400Business rule violated — the request is structurally valid but the operation is not allowedRead error and detail to understand the constraint. Fix the request logic.
401Not authenticated — credentials are missing or expiredRefresh your API key or session token.
403Forbidden — authenticated but lacking the required permissionCheck your role and permissions for this resource.
404Not found — the resource doesn't exist or isn't accessible to youVerify the resource ID or path.
409Conflict — a resource with the same identifier already existsUse a different name, or fetch the existing resource.
413Payload too large — the uploaded or fetched file exceeds the endpoint size limitReduce the file size (preview / sync parse: 20 MB).
422Validation error — one or more request fields are invalidRead fields to identify which fields to fix.
429Rate limited — too many requestsWait and retry after the indicated period.
500Server error — something unexpected went wrongRetry later. If persistent, contact support.
502Upstream error — a dependent service (AI model, external provider) failedRetry later. The error code indicates which service.
503Service unavailable — a required service is not deployed or reachableRetry later.
504Timeout — a dependent service did not respond in timeRetry with a simpler request (fewer pages, shorter query).

Error codes

Shared codes returned across the API. Expand a code for examples and remediation, or follow the doc_url in an error response to open the matching entry.

Domain error codes

Some endpoints return domain-specific error codes for fine-grained handling. Each code links directly from the doc_url in the error response.

Extract

Ontology

Files

Parse

Workspaces

Field error codes

When you receive a 422 response, each entry in the fields dict contains an error code from this vocabulary:

CodeDescriptionExample
requiredField is missing from the request body{"error": "required", "detail": "Field required"}
blankField is present but empty string{"error": "blank", "detail": "This field may not be blank."}
nullField is present but null{"error": "null", "detail": "This field may not be null."}
invalidWrong type or format{"error": "invalid", "detail": "Input should be a valid integer"}
invalid_choiceNot one of the allowed values{"error": "invalid_choice", "detail": "Input should be 'text', 'number' or 'date'"}
invalid_formatDoesn't match the expected pattern{"error": "invalid_format", "detail": "Invalid email format"}
too_shortString or array below minimum length{"error": "too_short", "detail": "String should have at least 3 characters"}
too_longString or array exceeds maximum length{"error": "too_long", "detail": "String should have at most 255 characters"}
too_smallNumber below minimum value{"error": "too_small", "detail": "Input should be greater than or equal to 1"}
too_largeNumber exceeds maximum value{"error": "too_large", "detail": "Input should be less than or equal to 100"}
already_existsDuplicate value{"error": "already_exists", "detail": "A group with this name already exists."}
does_not_existReferenced resource not found{"error": "does_not_exist", "detail": "User with this ID does not exist."}

Handling field errors in your application

Map fields to form state, and fall back to the top-level error for domain failures:

try {
  const response = await fetch(
    "https://your-instance.context212.com/api/v1/search",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ query: "quarterly revenue" }),
    },
  );

  if (!response.ok) {
    const error = await response.json();

    // Batch requests include the 0-based action index that failed
    if ("index" in error) {
      console.log(`  Failed at batch action #${error.index}`);
    }

    if (error.error === "validation_error" && error.fields) {
      // Per-field errors — collect for form display or logging
      for (const [field, errors] of Object.entries(error.fields) as [string, { error: string; detail: string }[]][]) {
        for (const entry of errors) {
          console.log(`  ${field}: [${entry.error}] ${entry.detail}`);
        }
      }
    } else {
      // Domain error (e.g. bad_request, not_found)
      console.log(`Error ${error.code}: [${error.error}] ${error.detail}`);
    }
  }
} catch (exc) {
  console.log(`Network error: ${exc}`);
}

API Reference

Overview of the Context212 REST API

Ask a question over your documents POST

Ask a question over your documents Retrieval-augmented generation: searches your indexed corpus, then generates an LLM answer grounded in the retrieved passages. **Modes:** - `stream=false` (default): returns a single JSON response with `results` and `answer`. - `stream=true`: returns Server-Sent Events — `event: sources` (retrieved chunks), `event: token` (answer tokens), `event: done` (stream complete), or `event: error` (generation failure). **Model:** defaults to `mistral-large-latest` (flagship, best answer quality). Pass `model=isaac-ft5` for the lighter, faster Context212 fine-tune. Company-specific custom models (`custom-{company_id}-{uuid}`) are also accepted. Any other value returns 422. **Relevance scoring:** relevance scoring always runs in `scoring_and_filtering` mode — candidates are scored for relevance and only those above the quality threshold are used as context. `score` equals the relevance score (`scores.relevance`, 0–1). Results are returned in descending order of `score`. If the scoring model is temporarily unavailable, `score` falls back to the combined retrieval score (higher is better, no fixed upper bound) and `scores.relevance` is null. **Scoping:** same rules as `/api/v1/search` — use `workspace_id` and/or `tag_id` to narrow results, or `file_id` to target specific files. `file_id` cannot be combined with `workspace_id` or `tag_id` (422). If the reranker is temporarily unavailable, results are returned in retrieval order and each result item includes a `warnings` array. Each warning has a `code` matching the degraded `scores` key (e.g. `relevance`) and a `reason` classifying the failure: `model_not_found`, `timeout`, `service_error`, or `unknown`. The `warnings` key is absent from result items when all pipeline steps succeed. Billing: 1 search-with-generation credit per request.

On this page