Skip to content

Authentication & Errors

Each API key belongs to an environment. Use a key from the environment that contains your templates and filters, and use a key from that same environment to read your extraction jobs.

  1. Select your environment in the app.
  2. Open Dashboard > API Keys and select Create New Key.
  3. Name the key after the backend or integration that will use it.
  4. Copy the key when it appears. The full value is shown once.
  5. Store it in your backend’s secret manager or protected configuration.

Keep API keys out of browser code, source control, and logs. When replacing a key, update your callers to use the new key before deleting the old one.

Send this header on every extraction API request:

Authorization: api-key <environment-api-key>

For example:

Terminal window
curl "https://api.terrafai.com/api/v1/extraction-jobs/$JOB_ID" \
-H "Authorization: api-key $API_KEY"
HeaderUse it for
Idempotency-KeyRetrying an async upload after a timeout or interrupted connection. See Safe Retries.
X-Client-ReferenceLinking an upload and its usage to a record in your system. See Client Reference.

Successful upload responses include a generated requestId. Save it, and the async job.id when applicable, to help trace the request later.

Check the HTTP status before reading extraction data. An API error usually includes a code, a message, and a request ID:

{
"success": false,
"error": {
"code": "JOB_NOT_FOUND",
"message": "Extraction job not found.",
"requestId": "request-id"
}
}

Use error.code to choose how your application responds. The message explains the problem; its wording may change. Keep the request ID when one is available so support can help investigate.

Handle empty or non-JSON error bodies too, using the HTTP status as your fallback. For 429 or 503, honor the Retry-After header when supplied. It can contain a delay in seconds or an HTTP date.

StatusWhat to do
400Correct the request using the error message and the endpoint’s documented fields.
401Check the api-key authorization header and confirm the key is active.
402Check your environment’s remaining monthly page allowance. Increase the allowance or wait for it to reset.
404Check the template or filter name, or the job ID and environment. An expired job also returns 404.
409Read the error code or message. An idempotency key may conflict with the request, an upload may still be in progress, or a result may be waiting for processing or review.
410The completed result has expired. Retrieve and store future results before retention ends.
413Reduce the JSON request size or use multipart upload.
429Slow down requests and wait for Retry-After when supplied.
500, 503, 504The request failed or timed out. Follow the retry guidance below.
CodeWhat to do
MISSING_API_KEY, UNSUPPORTED_AUTH_SCHEMESend Authorization: api-key <environment-api-key>.
INVALID_API_KEYUse an active key from the correct environment.
INVALID_FILE_TYPE, FILE_TYPE_MISMATCHUse a supported file format with a matching MIME type.
FILE_TOO_LARGEReduce or split the file. The error message includes the active file size limit.
TOO_MANY_FILESSend one file per request.
IDEMPOTENCY_KEY_CONFLICTRetry the original file and settings, or use a new key for new work. See Key Conflicts.
MONTHLY_PAGE_LIMIT_EXCEEDEDIncrease the page allowance or wait for the monthly reset.
PAGE_QUOTA_RESERVATION_CONFLICTRetry the same request.

See Files And Upload Limits for accepted formats, Asynchronous Extraction for job errors, and Webhooks for webhook setup errors.

If an async upload times out, the job may already have been created. Retry the same file and settings with the same Idempotency-Key within the replay window. Once you have a job ID, use it to check status and retrieve the result.

A synchronous retry can process the document again. Use async jobs with an idempotency key when your integration needs to recover safely from an interrupted upload.