Products · LLM Extraction V1

Extraction with Claude

Claude turns a document into structured data, with a confidence score and evidence for every field.

Version 1 · One Claude call per documentDesigned, not builtModule 4 of 15

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 act claim) 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 queued or processing, returns it with 200. Nothing new is started or charged.
  • Otherwise records a job as queued, with the model ID and prompt version from configuration, and returns 202.
  • With hold: true, records the acting app from the delegated token's act claim as held_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_by records 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_found and 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.completed or extraction.job.failed to subscribed apps, and records job.completed or job.failed in the audit log.

Responses

  • 202A new job was started. job (status queued). Location: the job's address. Retry-After: 2.
  • 200A job for this file was already running. That job.
  • 404file_not_found Upload does not know the file, or it is another user's.
  • 409file_not_ready The file is still uploading or was rejected.
  • 422unknown_schema schema is not one Extraction supports.
  • 422hold_requires_app hold: true without a delegated token, so there is no app to hold the results for.
  • 422validation_failed Another input is missing or malformed.
  • 429rate_limited More than 10 jobs a minute for one user.
  • 429quota_exceeded The person has used today's free jobs (EXTRACTION-V1-E3-09). Retry-After gives the seconds until 00:00 UTC; the message says how many were used and when more open.
  • 503dependency_unavailable Upload could not be reached to check the file. Safe to retry.
  • 401not_authenticated No 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[] lists fetching_file, reading_text, reading_document, checking_rules, saving, each waiting, running, done or failed.
  • A failed job has error_code, a plain-language error_message, and retryable: true when starting a new job may succeed.
  • Sends Retry-After: 2 while the job is queued or processing.
  • held_by names the app holding the results, or is empty; released_at is when it released them (EXTRACTION-V1-E3-08).

Responses

  • 200The job exists and is the caller's. job.
  • 404job_not_found No such job, or it belongs to another user. The same answer in both cases.
  • 401not_authenticated No 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.
true returns 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, whatever flagged says, so a person can check them; the holding app, with a delegated token naming it in act, 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[]; and held (true while the results are held from this caller) with fields_hidden, how many fields were left out.
  • 404job_not_found No such job, or it belongs to another user. The same answer in both cases.
  • 409job_not_finished The job is still running, or failed.
  • 401not_authenticated No 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_items as an array of objects. Amounts as decimal strings.
job_idbodyuuidoptional
When given, also checks that each source_quote in values appears 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, currency and total are present; each quote appears in the document's text.

Responses

  • 200The checks ran (whether or not they passed). passed and checks[]: name, passed, fields[] involved, and a plain-language message.
  • 422unknown_schema schema is not supported.
  • 422validation_failed values is malformed.
  • 401not_authenticated No 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 in plan.

Responses

  • 200Always. date, direct_jobs_used, direct_jobs_limit, resets_at and plan (free).
  • 401not_authenticated No 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 act claim equals held_by.
  • Sets released_at and records job.released in the audit log. Safe to call again: a released job answers 200 unchanged.
  • Nothing is copied or sent: the next read simply returns every field.

Responses

  • 200The job is released (now or before). job.
  • 404job_not_found No such job, or it belongs to another user. The same answer in both cases.
  • 403not_holder The caller is not the app holding this job.
  • 409not_held The job was never held.
  • 401not_authenticated No 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 and summary: failure_rate, avg_cost_usd, p95_duration_ms, jobs.
  • 404not_found The caller is not an admin. The endpoint does not reveal that it exists.
  • 401not_authenticated No 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 200 with 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.
  • 401invalid_signature The 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 OK

Errors

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.completed with {job_id, file_id, reference, fields_total, fields_flagged}, and extraction.job.failed with {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 with output_invalid and 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 202 response. A sweep every minute picks up any job left queued for over a minute, so a lost background task is not a lost job.
DocFlow's retry endpoint
POST /api/docflow/v1/documents/{documentId}/retry-extraction belongs to the DocFlow app. It calls POST /jobs again; 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 checks getUsage before starting a job. The service-only POST /jobs/{jobId}/release has no tool: only the holding app releases.
Health and contract
Like every service, Extraction also serves GET /health and GET /openapi.json from 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.
  • schema must 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, never 403.
  • Admin endpoints answer 404 not_found to 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.