Extraction with Claude
Claude turns a document into structured data, with a confidence score and evidence for every field.
InterfacesAPI SpecSections
API Spec Designed
Base address: https://01scale.com/api/extraction/v1. Open an endpoint for its inputs, constraints, errors and samples.
POST/jobsStart extracting a file
Starts reading a ready file into structured fields. Returns at once; the work continues in the background. Calling it again for the same file while a job is running returns that job instead of starting another. Signed in
Scope: extraction:write
Inputs
file_idbodyuuidrequired- The document to read.
- A file of the caller's in the Upload service, with status
ready. schemabodystringrequired- Which fields to extract. Each schema has its own prompt and rule checks.
- In version 1, only
invoice-v1. referencebodystringoptional- The caller's own label for the job, returned in its events. DocFlow sends
docflow:{document_id}. - 1 to 200 characters. Opaque to Extraction.
holdbodybooleanoptional- Hold the results for the app until it releases them (
EXTRACTION-V1-E3-08). While held, the owner sees only the flagged fields. - Only with a delegated token: the acting app (its
actclaim) becomes the holder. Default false.
What it does
- Checks the file through Upload, forwarding the caller's access token, so only the caller's own ready files can be read.
- If a job for this file and schema is
queuedorprocessing, returns it with200. Nothing new is started or charged. - Otherwise records a job as
queued, with the model ID and prompt version from configuration, and returns202. - With
hold: true, records the acting app from the delegated token'sactclaim asheld_by(EXTRACTION-V1-E3-08). A person's own token or an API key cannot place a hold. - A job started with a person's own token or API key counts toward that person's free daily quota: 3 a day by default (
EXTRACTION_DIRECT_DAILY_QUOTA), reset at 00:00 UTC (EXTRACTION-V1-E3-09). A job an app starts with a delegated token counts toward the app, not the person. Returning a job that is already running, and a job that fails for a temporary reason, do not count.started_byrecords which it was. - The job then runs in the background: with a delegated token for the owner, fetch the file through a 5-minute Upload link, and read its text. A PDF with a text layer gives its text directly; a scanned PDF or a photo is read by OCR (Claude transcribing each page, in a call separate from extraction so the quote check stays independent). Each page's text is saved for the quote check.
- If no text is found on any page, the job fails with
no_text_foundand the message 'No text found'. It is not retryable: the same file would give the same result. - Otherwise it sends the document to Claude with the versioned prompt, checks the answer against the schema, applies the rule checks (including every quote against the saved text, for photos and scans too), and saves the fields.
- Temporary failures (rate limit, timeout, overload) are retried up to 2 times, after 2 and then 8 seconds. After that the job is
failed. - When the job ends, announces
extraction.job.completedorextraction.job.failedto subscribed apps, and recordsjob.completedorjob.failedin the audit log.
Responses
- 202A new job was started.
job(statusqueued).Location: the job's address.Retry-After: 2. - 200A job for this file was already running. That
job. - 404
file_not_foundUpload does not know the file, or it is another user's. - 409
file_not_readyThe file is still uploading or was rejected. - 422
unknown_schemaschemais not one Extraction supports. - 422
hold_requires_apphold: truewithout a delegated token, so there is no app to hold the results for. - 422
validation_failedAnother input is missing or malformed. - 429
rate_limitedMore than 10 jobs a minute for one user. - 429
quota_exceededThe person has used today's free jobs (EXTRACTION-V1-E3-09).Retry-Aftergives the seconds until 00:00 UTC; the message says how many were used and when more open. - 503
dependency_unavailableUpload could not be reached to check the file. Safe to retry. - 401
not_authenticatedNo valid access token.
Sample request
POST /api/extraction/v1/jobs HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>
Content-Type: application/json
{
"file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
"schema": "invoice-v1",
"reference": "docflow:0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c"
}Sample response
HTTP/1.1 202 Accepted
Location: /api/extraction/v1/jobs/0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b
Retry-After: 2
Content-Type: application/json
{
"job": {
"id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
"file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
"schema": "invoice-v1",
"reference": "docflow:0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
"status": "queued",
"steps": [
{
"name": "fetching_file",
"state": "waiting"
},
{
"name": "reading_text",
"state": "waiting"
},
{
"name": "reading_document",
"state": "waiting"
},
{
"name": "checking_rules",
"state": "waiting"
},
{
"name": "saving",
"state": "waiting"
}
],
"fields_total": null,
"fields_flagged": null,
"error_code": null,
"error_message": null,
"retryable": false,
"started_by": "service:docflow",
"held_by": "service:docflow",
"released_at": null,
"created_at": "2026-11-17T09:14:12Z",
"finished_at": null
}
}GET/jobs/{jobId}Check a job
Where a job is, step by step. A page polls this every 2 seconds while the job runs. Signed in
Scope: extraction:read
Inputs
jobIdpathuuidrequired- The job.
- A UUID.
What it does
- Read only.
steps[]listsfetching_file,reading_text,reading_document,checking_rules,saving, eachwaiting,running,doneorfailed.- A failed job has
error_code, a plain-languageerror_message, andretryable: true when starting a new job may succeed. - Sends
Retry-After: 2while the job isqueuedorprocessing. held_bynames the app holding the results, or is empty;released_atis when it released them (EXTRACTION-V1-E3-08).
Responses
- 200The job exists and is the caller's.
job. - 404
job_not_foundNo such job, or it belongs to another user. The same answer in both cases. - 401
not_authenticatedNo valid access token.
Sample request
GET /api/extraction/v1/jobs/0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>Sample response
{
"job": {
"id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
"file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
"schema": "invoice-v1",
"reference": "docflow:0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
"status": "extracted",
"steps": [
{
"name": "fetching_file",
"state": "done"
},
{
"name": "reading_text",
"state": "done"
},
{
"name": "reading_document",
"state": "done"
},
{
"name": "checking_rules",
"state": "done"
},
{
"name": "saving",
"state": "done"
}
],
"fields_total": 19,
"fields_flagged": 3,
"error_code": null,
"error_message": null,
"retryable": false,
"started_by": "service:docflow",
"held_by": "service:docflow",
"released_at": null,
"created_at": "2026-11-17T09:14:12Z",
"finished_at": "2026-11-17T09:14:41Z"
}
}GET/jobs/{jobId}/fieldsGet the extracted fields
Every field the job extracted, with its value, how confident the system is, and the exact text it was read from. Signed in
Scope: extraction:read
Inputs
jobIdpathuuidrequired- The job.
- A job with status
extracted. flaggedquerybooleanoptional- Only what needs a person's check.
truereturns only flagged fields.
What it does
- Read only. Fields never change after a job saves them; corrections happen in the Human Review service, on its own copy.
- Ordered by the schema's field order; line-item fields by
line_index, then field. - Amounts and quantities are decimal strings (
"1240.00"), never floating-point numbers, so no value is rounded on the way. - While the job is held (
EXTRACTION-V1-E3-08), the owner's own token or API key gets only the flagged fields, whateverflaggedsays, so a person can check them; the holding app, with a delegated token naming it inact, gets every field. After release, everyone the owner allows gets every field.
Responses
- 200The job has finished extracting.
data[]of fields:id,name,line_index(line items only),value,confidence(final),model_confidence,source_page,source_quote,flagged,flag_reasons[]; andheld(true while the results are held from this caller) withfields_hidden, how many fields were left out. - 404
job_not_foundNo such job, or it belongs to another user. The same answer in both cases. - 409
job_not_finishedThe job is still running, or failed. - 401
not_authenticatedNo valid access token.
Sample request
GET /api/extraction/v1/jobs/0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b/fields?flagged=true HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>Sample response
{
"data": [
{
"id": "0193b0d2-1f00-7a01-8b02-0c03d04e05f6",
"name": "total",
"line_index": null,
"value": "1240.00",
"confidence": 0.3,
"model_confidence": 0.92,
"source_page": 2,
"source_quote": "TOTAL DUE $1,240.00",
"flagged": true,
"flag_reasons": [
"Total \u2260 subtotal + tax (1,150.00 + 80.00 = 1,230.00)"
]
}
]
}POST/validationsCheck values against a schema's rules
Runs the same rule checks the job runs, on any set of values. An app uses it to re-check values after a person has corrected them. Signed in
Scope: extraction:write
Inputs
schemabodystringrequired- Which rules to apply.
invoice-v1.valuesbodyobjectrequired- The values to check.
- The schema's fields by name;
line_itemsas an array of objects. Amounts as decimal strings. job_idbodyuuidoptional- When given, also checks that each
source_quoteinvaluesappears in that job's saved page text, for scans and photos as well as text PDFs. Nothing is read again. - A job of the caller's that read text.
What it does
- Runs every rule for the schema and reports each one. Stores nothing.
- Invoice v1 rules: line amounts add up to the subtotal (±0.01); subtotal + tax = total (±0.01); dates are real dates and the due date is not before the invoice date; the currency is an ISO 4217 code;
vendor_name,invoice_number,invoice_date,currencyandtotalare present; each quote appears in the document's text.
Responses
- 200The checks ran (whether or not they passed).
passedandchecks[]:name,passed,fields[]involved, and a plain-languagemessage. - 422
unknown_schemaschemais not supported. - 422
validation_failedvaluesis malformed. - 401
not_authenticatedNo valid access token.
Sample request
POST /api/extraction/v1/validations HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>
Content-Type: application/json
{
"schema": "invoice-v1",
"values": {
"vendor_name": "Acme Supplies Ltd",
"invoice_number": "INV-0042",
"invoice_date": "2026-11-02",
"due_date": "2026-12-02",
"currency": "USD",
"subtotal": "1150.00",
"tax_total": "80.00",
"total": "1230.00",
"line_items": [
{
"description": "Paper, A4",
"quantity": "10",
"unit_price": "115.00",
"amount": "1150.00"
}
]
}
}Sample response
{
"passed": true,
"checks": [
{
"name": "line_amounts_match_subtotal",
"passed": true,
"fields": [
"line_items",
"subtotal"
],
"message": "Line amounts add up to the subtotal."
},
{
"name": "subtotal_plus_tax_is_total",
"passed": true,
"fields": [
"subtotal",
"tax_total",
"total"
],
"message": "Subtotal plus tax equals the total."
},
{
"name": "dates_valid",
"passed": true,
"fields": [
"invoice_date",
"due_date"
],
"message": "Dates are valid and the due date is after the invoice date."
},
{
"name": "currency_valid",
"passed": true,
"fields": [
"currency"
],
"message": "USD is a valid currency."
},
{
"name": "required_present",
"passed": true,
"fields": [
"vendor_name",
"invoice_number",
"invoice_date",
"currency",
"total"
],
"message": "All required fields are present."
}
]
}GET/usageToday's free jobs
How many jobs the person has started themselves today, out of their free daily quota, and when it resets. An agent checks this before starting a job. Signed in
Scope: extraction:read
Inputs
None.
What it does
- Read only. Counts jobs started with the person's own token or API key since 00:00 UTC; jobs an app started for them are not counted.
- Until Extraction has a paid plan (
01SCALE-V1-E0-28), the quota is the limit; the response says so inplan.
Responses
- 200Always.
date,direct_jobs_used,direct_jobs_limit,resets_atandplan(free). - 401
not_authenticatedNo valid access token.
Sample request
GET /api/extraction/v1/usage HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>Sample response
{
"date": "2026-11-23",
"direct_jobs_used": 2,
"direct_jobs_limit": 3,
"resets_at": "2026-11-24T00:00:00Z",
"plan": "free"
}POST/jobs/{jobId}/releaseRelease held results
The holding app lets the owner see every field, once its own condition is met (for DocFlow, the order is paid). Extraction never knows why. Service
Scope: extraction:write
Inputs
jobIdpathuuidrequired- The job.
- A held job.
What it does
- Only the holder can release: a delegated token for the job's owner whose
actclaim equalsheld_by. - Sets
released_atand recordsjob.releasedin the audit log. Safe to call again: a released job answers200unchanged. - Nothing is copied or sent: the next read simply returns every field.
Responses
- 200The job is released (now or before).
job. - 404
job_not_foundNo such job, or it belongs to another user. The same answer in both cases. - 403
not_holderThe caller is not the app holding this job. - 409
not_heldThe job was never held. - 401
not_authenticatedNo valid access token.
Sample request
POST /api/extraction/v1/jobs/0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b/release HTTP/1.1
Host: 01scale.com
Authorization: Bearer <delegated token, act: service:docflow>Sample response
{
"job": {
"id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
"file_id": "0193b0c4-2a10-7e55-8d31-6c7d8e9f0a1b",
"schema": "invoice-v1",
"reference": "docflow:0193b0c4-91aa-7b33-8c44-5d6e7f8a9b0c",
"status": "extracted",
"steps": [
{
"name": "fetching_file",
"state": "done"
},
{
"name": "reading_text",
"state": "done"
},
{
"name": "reading_document",
"state": "done"
},
{
"name": "checking_rules",
"state": "done"
},
{
"name": "saving",
"state": "done"
}
],
"fields_total": 19,
"fields_flagged": 3,
"error_code": null,
"error_message": null,
"retryable": false,
"started_by": "service:docflow",
"held_by": "service:docflow",
"released_at": "2026-11-17T09:20:05Z",
"created_at": "2026-11-17T09:14:12Z",
"finished_at": "2026-11-17T09:14:41Z"
}
}GET/admin/jobsRecent jobs with cost and timing
The last 100 jobs across all users, with tokens, cost and duration, and the failure rate. For the owner, to watch quality and spend. Admin
Scope: is_admin
Inputs
limitqueryintegeroptional- How many jobs.
- 1 to 100. Default 100.
What it does
- Read only. Shows no field values and no file names: only IDs, status, model, prompt version, tokens, cost, duration and error codes.
Responses
- 200The caller is an admin.
data[]of jobs andsummary:failure_rate,avg_cost_usd,p95_duration_ms,jobs. - 404
not_foundThe caller is not an admin. The endpoint does not reveal that it exists. - 401
not_authenticatedNo valid access token.
Sample request
GET /api/extraction/v1/admin/jobs?limit=1 HTTP/1.1
Host: 01scale.com
Authorization: Bearer <access token>Sample response
{
"data": [
{
"id": "0193b0d1-4b2c-7d10-9a8b-1c2d3e4f5a6b",
"status": "extracted",
"model": "claude-opus-5-5",
"prompt_version": "extract-invoice/v1",
"pages": 2,
"tokens_in": 6210,
"tokens_out": 1480,
"cost_usd": "0.040830",
"duration_ms": 28900,
"error_code": null,
"created_at": "2026-11-17T09:14:12Z"
}
],
"summary": {
"jobs": 100,
"failure_rate": 0.02,
"avg_cost_usd": "0.0412",
"p95_duration_ms": 41200
}
}POST/eventsReceive platform events
Where other services' signed events arrive. In version 1 Extraction acts on one: a user's account was deleted, so their jobs and the values read from their documents go too. Service
Scope: None: HMAC signature
Inputs
X-01scale-Signatureheaderstringrequired- Proves the event came from the platform.
- HMAC-SHA256 of the raw body, compared in constant time.
event_idbodyuuidrequired- The event's ID.
- Processed once; a repeat returns
200with no effect. typebodystringrequired- What happened.
- Version 1 acts on
identity.user.deleted; other types are acknowledged and ignored. databodyobjectrequired- The event's details.
- For
identity.user.deleted:{user_id}.
What it does
- For
identity.user.deleted: deletes that user's fields (they contain document content), and keeps their jobs with only IDs, counts, tokens and cost, for the cost records.
Responses
- 200Accepted, including a repeat or an ignored type. No body.
- 401
invalid_signatureThe signature is missing or wrong.
Sample request
POST /api/extraction/v1/events HTTP/1.1
X-01scale-Signature: sha256=8c1f...
Content-Type: application/json
{
"event_id": "0193b2aa-6f01-7c2d-9e3f-4a5b6c7d8e9f",
"type": "identity.user.deleted",
"occurred_at": "2026-11-17T10:00:00Z",
"data": {
"user_id": "0193a5b2-7c1e-7a3f-9b2d-4e6f8a1c2d3e"
}
}Sample response
HTTP/1.1 200 OKErrors
Every error has the same shape and a stable code to branch on.
{
"type": "https://01scale.com/errors/file_not_ready",
"title": "File not ready",
"status": 409,
"detail": "This file is still uploading. Try again when the upload has finished.",
"code": "file_not_ready",
"request_id": "req_0193a61f9c2e"
}Handled without an endpoint
- Events Extraction announces
extraction.job.completedwith{job_id, file_id, reference, fields_total, fields_flagged}, andextraction.job.failedwith{job_id, file_id, reference, error_code, retryable}. Signed and delivered with retries from the outbox to each subscribed app (DocFlow's webhook,DOCFLOW-V1-E0-09).- The Claude call (EXTRACTION-V1-E3-02)
- Inside the job, not an endpoint. The document goes to Claude as a document or image input with the versioned prompt
prompts/extract-invoice/v1.md. The answer is forced into the invoice v1 schema with a tool definition, then validated with zod. A failure triggers one repair attempt; if that fails too, the job fails withoutput_invalidand nothing is stored. - Final confidence (EXTRACTION-V1-E3-03)
- Each field's final confidence is the lower of the model's own confidence and its rule result: a failed check sets 0.3. A field under the threshold (0.85 by default, set in configuration) or failing a check is
flagged, with each reason stored. - Where the job runs
- In the Extraction service itself, continuing after the
202response. A sweep every minute picks up any job leftqueuedfor over a minute, so a lost background task is not a lost job. - DocFlow's retry endpoint
POST /api/docflow/v1/documents/{documentId}/retry-extractionbelongs to the DocFlow app. It callsPOST /jobsagain; a failed job is never restarted, a new one is created.- AI agents
- Each endpoint a person can call is also a tool on Extraction's MCP server,
POST /api/extraction/mcp, with the same inputs and errors; an agent checksgetUsagebefore starting a job. The service-onlyPOST /jobs/{jobId}/releasehas no tool: only the holding app releases. - Health and contract
- Like every service, Extraction also serves
GET /healthandGET /openapi.jsonfrom the service template (SERVICEKIT-V1-E0-05).
Constraints at the API level
- A job can only be started for the caller's own file, and only when Upload says it is
ready. schemamust be one Extraction supports; in version 1,invoice-v1.- Only one job per file and schema can be running at a time; asking again returns the running job.
- Another user's job answers
404 job_not_found, never403. - Admin endpoints answer
404 not_foundto anyone who is not an admin. - Amounts are exchanged as decimal strings, never as floating-point numbers.
- Events must carry a valid signature and are processed once per
event_id. - Starting rate limit at the gateway: 10 jobs a minute per user.