DocumentationHTTP clients

HTTP clients

cURL, Node.js, Python and TypeScript requests, response handling and bounded batch behavior.

On this page

The four implementations issue one POST /api/v3/ine with profile=extended and mode=both. They share the same multipart fields and an existing transaction key; redirects and automatic POST retries are disabled.

idempotencyKey / idempotency_key matches [A-Za-z0-9._:-]{8,128}. The same transaction retains its key and exact image bytes. Multipart boundaries are transport metadata and may differ between exact replays.

Response semantics

OutcomeMeaning
200 with status: "succeeded"Completed result in data; warnings and expires_at accompany it.
202 with status: "processing"Pending result; Retry-After controls the next GET interval.
Structured errorMachine-readable error.code, message and action; error reference.
Redirect, malformed body, network error or timeoutUnconfirmed outcome. Recovery retains the transaction key and uses a known request ID when available.

GET and exact replay do not initiate new extraction. A changed transaction key can reserve a new billable reading. The returned HTTP status and body remain separate; a parsed JSON body alone does not establish success.

Request implementations

curl --silent --show-error --max-time 90 \
  --request POST 'https://ocr.ecostudios.dev/api/v3/ine' \
  --header "X-API-Key: $INE_API_KEY" \
  --header "Idempotency-Key: $INE_IDEMPOTENCY_KEY" \
  --header 'Accept: application/json' \
  --form 'profile=extended' \
  --form 'mode=both' \
  --form "front=@${INE_FRONT_PATH}" \
  --form "back=@${INE_BACK_PATH}" \
  --dump-header "$INE_HEADERS_PATH" \
  --output "$INE_RESULT_PATH" \
  --write-out '%{http_code}\n'

Runtime contract

Runtime targets are cURL 8+, Node.js 22+, Python 3.10+ and TypeScript 5+. JavaScript and TypeScript use native Node.js web APIs; TypeScript compilation includes ES2022 and DOM types. Python uses only its standard library. No vendor SDK is required.

FormatInput and transport behavior
cURLImage paths in INE_FRONT_PATH and INE_BACK_PATH; headers in INE_HEADERS_PATH, response body in INE_RESULT_PATH, HTTP status on standard output.
Node.jsfront and back are Blob instances with the image MIME type. Native FormData generates the boundary.
Pythonfront and back are bytes; mime_type applies to both files. Response capture is bounded to 128 KiB.
TypeScriptTyped inputs and transport metadata; body: unknown remains unvalidated API content. request_id is narrowed to a string independently.

The cURL deadline and JavaScript abort deadline are 90 seconds; Python uses a 90-second socket timeout. These are client settings, not API latency guarantees. The response body and HTTP status remain separate, and these functions do not validate the full result schema.

Bounded result polling

The Node.js client and Python client accept PNG/JPEG files, submit the standard profile and reserve a 90-second total wait budget. A valid 202 switches subsequent requests to GET. POST is never automatically repeated.

Client inputMeaning
INE_API_KEYExtraction credential.
Two file paths and a transaction keyOne standard-profile, two-sided request.
--request-id UUIDGET-only retrieval; no image upload.
--print-dataFull response output; default output excludes identity values.

Alternative invocations:

node ine-node.mjs "$INE_FRONT_PATH" "$INE_BACK_PATH" "$INE_IDEMPOTENCY_KEY"
python3 ine-python.py "$INE_FRONT_PATH" "$INE_BACK_PATH" "$INE_IDEMPOTENCY_KEY"
node ine-node.mjs --request-id "$INE_REQUEST_ID"

Batch contract

The Node.js batch client accepts 1–100 manifest entries and runs at most two concurrent requests. Concurrency and rate limits remain shared with every process using the API account.

Manifest keyType / constraint
idempotency_keyDistinct stable string per transaction.
frontFile path relative to the manifest; required by both and front modes.
backFile path relative to the manifest; required by both and back modes.
profilestandard or extended; defaults to standard.
modeboth, front or back; defaults to both.
node ine-batch.mjs "$INE_MANIFEST_PATH" --output "$INE_STATE_PATH"

The state file is exclusively created with private permissions. It contains request IDs, statuses, image hashes and transaction keys; it excludes image paths, OCR values and API keys. The exported runBatch function accepts onResult({ index, request_id, result }) for successful result handling.

ConditionBatch behavior
Admission 429: rate_limited, concurrency_limited, admission_changedAt most two retries with the same bytes and key; full Retry-After must fit within 60 seconds.
Authentication, quota, network, technical 5xx, malformed response or result-handler failureNew submissions stop; active requests may complete. No automatic POST retry.
Valid 202Request state saved for a later explicit GET.
Existing stateNo automatic polling or resumption.