Analyses

Analyze a set of uploaded files, wait for the result, read it, and cancel or delete the analysis.

An analysis reads a set of uploaded files. It returns the field values and check answers that its spec asks for, and it lists the documents it found in the files. You define the fields and checks yourself or use a builtin template. Use cases has example requests for common broker tasks.

Create an analysis

Send POST /v1/analyses with a spec and the IDs of the files to analyze. The analysis reads only the files you list, at most 32 (Limits). This example uploads a payslip, asks for four builtin fields and waits for the result:

// Reads the income facts from one payslip.
import { Client } from "@aircredit/sdk/partner/v1";

const client = Client.fromEnv();
const payslip = await client.createFile("payslip.pdf");

// Ask for four builtin fields, each under its own key.
const created = await client.createAnalysis(
  {
    files: [payslip.id],
    language: "en",
    spec: {
      fields: {
        net_salary: { builtin: "net_salary" },
        gross_salary: { builtin: "gross_salary" },
        employer: { builtin: "employer" },
        employed_since: { builtin: "employed_since" },
      },
    },
  },
  { wait: 30 },
);
const analysis = await client.waitForAnalysis(created.id);

// Each field carries its status, its typed value and the citations it was read from.
if (analysis.status === "succeeded") {
  console.log(analysis.result.fields);
}

You can create the analysis directly after the upload. If a file is still being prepared, the analysis waits for it.

Send a new Idempotency-Key with each new analysis, as the SDKs do by default. If the request fails on the network, send it again with the same key. AirCredit then creates no second analysis (Repeated requests).

external_id is an optional reference of your own, such as a case number. The analysis and its webhook events return it. It does not prevent duplicates.

With a live key, AirCredit charges the analysis to your prepaid balance when it is created. If the balance is too low, the request returns 402 insufficient_balance (Billing). A test key returns a sample result at once (Test mode).

A collection requirement counts documents across all files of an analysis. If your spec contains one, create a separate analysis for each person or account.

Wait for the result

The create request returns at once by default. To wait for the result, send Prefer: wait=N, where N is a number of seconds up to 30.

ResponseMeaning
200The analysis finished within the wait time. It succeeded, failed or was canceled
202The analysis is still queued or running. Retry-After gives the number of seconds to wait before you poll

Every create response has a Location header with the URL of the analysis. This includes the response to a retry with the same Idempotency-Key. If you sent Prefer: wait, the Preference-Applied header shows the wait time that was applied.

To poll, call GET /v1/analyses/{id}. It returns 200 in every state, so check status in the body. The example above polls with the SDKs' wait helper, waitForAnalysis in TypeScript and wait_for_analysis in Python and Rust. It reads the analysis every two seconds until its status is succeeded, failed or canceled, for two minutes by default. It then returns the last state it read, which can still be queued or running.

States

An analysis is always in one of these five states:

statusMeaning
queuedCreated, and waiting for its files or for work to start
runningBeing processed
succeededFinished with a result
failedFinished without a result. error explains what happened
canceledStopped before it finished. The record is kept

v1 adds no further states, so your code can handle these five exhaustively. Read status first, because it determines which other members are present. A succeeded analysis always has result and usage. A failed analysis always has error. The other three states have neither.

The code in error says why the analysis failed. It names the cause, never internal details, and new codes can appear (Execution failures).

Concurrent analyses

Each integration can have at most 32 analyses that are queued or running at the same time. Test and live mode are counted separately. A further create request returns 429 rate_limited with a Retry-After header. Retry it with the same Idempotency-Key and body after earlier analyses have finished.

Read the result

A result always has the members documents, files, fields, checks and collection.

  • files has one entry for each input file.
  • fields and checks have one entry for each field and check alias, the name you gave it in the spec (Fields and checks).
  • collection has one entry for each collection requirement.

New members can appear in v1 without notice. Ignore the ones you do not know (Versioning).

succeeded means that the analysis produced a result. Single checks in it can still have failed, so read the status of each check (Checks).

Documents

Every analysis classifies its files, even if the spec does not ask about documents. result.documents lists each document found, in file order, including documents that match no type. A file can contain several documents.

Without spec.documents, AirCredit classifies the files against every builtin document type and checks no document requirements. Each entry then has requirements: {}.

Each entry has these members:

MemberMeaning
file_idThe input file that contains the document
pagesWhere the document sits in the file, such as {"start": 1, "end": 2}. These are physical pages counted from one, not printed page numbers. Text files have no pages
periodThe months the document covers, both ends included, such as {"start": "2026-07", "end": "2026-09"}. A monthly document has the same start and end, and a quarterly bank statement spans three months. null when the content establishes no period
classificationmatched when the document matches a type, no_match when it matches none of the selected types, and unknown when there is no reliable answer
document_typeThe matched type, such as {"builtin": "gehaltsabrechnung"}, otherwise null
confidenceThe confidence of the classification, from 0 to 1
alternativesOther types the document might be, each with document_type and confidence
requirementsThe results of the document requirements, keyed by requirement ID

document_type is an object with a single key. Today that key is always builtin. The form {"custom": "<key>"} is reserved for custom document types, which are not supported yet.

Readability

Each entry in result.files has the file's number of pages and its readability:

readabilityMeaning
status: succeeded, readable: trueAll material content is legible
status: succeeded, readable: falseThe file is partly or wholly illegible
status: not_evaluated, reason: not_evaluated, no readableThe evidence does not establish whether the file is legible

Classification, readability and requirement results are independent of each other. Evaluate each one separately.

Documents-only analysis

To classify documents and check them against requirements without fields or checks, send only spec.documents. This example:

  • selects payslips
  • turns on their default requirements from the catalog
  • adds a requirement that each payslip is at most three months old, counted from the end of its period

The example waits up to 30 seconds for the result, and prints the type and requirement results of each document:

// Classifies a document and judges its document requirements.
import { Client } from "@aircredit/sdk/partner/v1";

const client = Client.fromEnv();
const file = await client.createFile("payslip.pdf");

// Look only for payslips, with the catalog's default requirements and one of your own.
const analysis = await client.createAnalysis(
  {
    files: [file.id],
    language: "en",
    spec: {
      documents: {
        builtins: { gehaltsabrechnung: {} },
        default_requirements: true,
        requirements: {
          recent: { kind: "max_age", months: 3, basis: "period_end" },
        },
      },
    },
  },
  { wait: 30 },
);

// Every document occurrence lists its type and a verdict per requirement.
if (analysis.status === "succeeded") {
  for (const document of analysis.result.documents) {
    console.log(document.document_type, document.requirements);
  }
}

Choose document types

  • Leave out builtins to consider every builtin type in the catalog.
  • builtins: {} selects no type. If the spec then asks for nothing else, the request returns 422 invalid_field.
  • Selecting a type does not require a document of that type to be present.
  • Custom document types are not supported yet. A nonempty custom map returns 422 unsupported_candidate.

Add requirements

default_requirements: true adds the default requirements that the catalog lists for each selected type. Each one has a kind and a description. New kinds can appear in v1. Treat an unknown kind like text, which is a requirement described only by its description.

requirements adds your own requirements, either for all selected types or for a single type. Requirement IDs must not collide. For each type, the requirements for all types, the type's own requirements and its enabled defaults need distinct IDs. A collision returns 422 duplicate_requirement_key. Two different types may use the same ID.

Requirements are not evaluated yet

AirCredit does not evaluate document requirements yet. Every requirement result currently looks like this:

{
  "status": "not_evaluated",
  "reason": "not_implemented",
  "verdict": null
}

This is one requirement result, not the whole response. Its verdict is null, so a succeeded analysis does not mean that a document requirement was met.

Requirements about the whole file set work differently. They are collection requirements.

Repeated requests

After a network failure, you cannot tell whether AirCredit received your create request. Send it again with the same Idempotency-Key and the same body. You get the original analysis back, and you are not charged twice.

An Idempotency-Key applies only to create-analysis requests from the same integration and with an API key of the same mode.

  • A retry with the same key and body returns the analysis in its current state.
  • The same key with a different body returns 409 idempotency_conflict, even if the original analysis was deleted.
  • A retry for an analysis that was deleted or has expired returns 410 resource_deleted.
  • Rotating your API key keeps these records. Deleting the integration removes them.

Correct an input

You cannot change an analysis after you create it. To correct a document, upload the corrected version as a new file. Then create a new analysis with the complete revised file list and a new Idempotency-Key.

AirCredit may reuse the classifications of files that did not change. Fields and checks always run again. usage.reused.classifications counts the reused classifications. Reuse is not guaranteed for every unchanged file. The original analysis keeps its result until it expires or one of its files is deleted.

Cancel or delete

To stop a queued or running analysis, send POST /v1/analyses/{id}/cancel with no body, not even an empty JSON object. Repeating the request is safe. For an analysis that has already finished, it returns the current state.

This example starts an analysis without waiting and cancels it:

// Cancels an analysis that is no longer needed.
import { Client } from "@aircredit/sdk/partner/v1";

const client = Client.fromEnv();
const file = await client.createFile("payslip.pdf");

// Start an analysis without waiting for it.
const started = await client.createAnalysis({
  files: [file.id],
  spec: { template: { key: "default_personal_property_purchase" } },
});

// Cancel it. An analysis that already finished comes back unchanged.
const analysis = await client.cancelAnalysis(started.id);
console.log(`analysis ${analysis.id} is ${analysis.status}`);

A canceled analysis keeps its record. To remove an analysis, delete it after it has finished, as in the quickstart. The response is an empty 204. Deleting an analysis that is still queued or running returns 409 analysis_in_progress, so cancel it first.

Deleting a file also deletes every analysis that uses it. Retention explains what a deletion removes and when.

On this page