API reference
Extract text with OCR
POST /api/pub/v1/ocr, read the text out of an image or PDF as a job.
POST
https://api.dhanu.ai/api/pub/v1/ocrQueues OCR for an image or PDF sent as base64 and returns the
job. OCR runs on a separate service and can take a
while for long PDFs, so the text arrives in the job’s result once it succeeds,
wait on it or subscribe to job.succeeded. A test key answers with an already
succeeded fixture job.
Request
| Field | Type | Required | Notes |
|---|---|---|---|
data | string | Yes | The file bytes, base64-encoded. At least 1 characters. |
mimeType | string | Yes | At least 1 characters. |
filename | string | No | Up to 255 characters. |
languageHint | string | No | The document's language: ne, en, or auto to decide from the filename. One of ne, en, auto. |
curl -X POST https://api.dhanu.ai/api/pub/v1/ocr \
-H "Authorization: Bearer $DHANU_API_KEY" \
-H "Content-Type: application/json" \
-d "{ \"data\": \"$(base64 -i receipt.png)\", \"mimeType\": \"image/png\", \"filename\": \"receipt.png\" }"const job = await dhanu.ocr.extract({
data: await fs.readFile("receipt.png"),
mimeType: "image/png",
filename: "receipt.png",
});
const done = await dhanu.jobs.wait(job.id);
console.log(done.result);with open("receipt.png", "rb") as fh:
job = dhanu.ocr.extract(data=fh.read(), mime_type="image/png", filename="receipt.png")
done = dhanu.jobs.wait(job.id)
print(done.result) Response
202 Accepted
{ "job": { "id": "…", "type": "ocr.extract", "status": "queued", "result": null, "error": null, "createdAt": "…", "completedAt": null } }
Errors
| Code | Status | Meaning |
|---|---|---|
invalid_api_key | 401 | The bearer key is missing or unknown. |
api_key_revoked | 401 | The key was revoked. |
api_key_expired | 401 | The key passed its expiry date. |
api_key_ip_not_allowed | 403 | The caller's IP is outside the key's allowlist. |
developer_access_revoked | 403 | The key's creator lost developer access in the workspace. |
api_key_project_scope | 403 | The key covers no active projects, or projectId is outside its scope. |
invalid_request_body | 422 | The body did not match the schema; error.issues names each field. |
project_id_required | 422 | A multi-project key called without projectId. |
insufficient_credits | 402 | The workspace credit balance is zero or below. |
key_spend_limit_reached | 402 | The key reached its monthly spend cap. |
invalid_generation_prompt | 422 | The prompt was empty or longer than 2000 characters. |