Quickstart
Upload a payslip, ask for its net salary and read the answer.
Install the SDK
AirCredit has typed clients, the SDKs, for TypeScript, Python and Rust. The examples in these guides
use them. Pick your language in the tabs of any example, and the guides show that language
everywhere. The cURL examples need only curl and uuidgen.
npm install @aircredit/sdkPrepare
Create an API key under Partner API in your AirCredit account settings, as
Authentication describes. Start with a test key. It begins with
sk_test_ and is free.
A test analysis finishes at once, but its result holds sample values, not the values on your payslip
(Test mode). Once everything works, run the same steps with a live key, which
begins with sk_live_. A live key reads the real document and charges the analysis to your prepaid
balance (Billing).
Every example reads the key from the environment variable AIRCREDIT_API_KEY, so set it to your
key. The examples send every request to the base URL https://api.aircredit.de/partner.
You also need a payslip as a PDF or in another supported format.
Save it as payslip.pdf in the directory you run the example in.
Run the example
The example fetches the catalog, uploads the payslip and asks for its net salary. It then waits for the result, prints it, and deletes the analysis and the file. The sections below explain each step.
// Uploads a payslip, asks for its net salary, reads the answer and cleans up.
import { Client } from "@aircredit/sdk/partner/v1";
// Read the key from AIRCREDIT_API_KEY and, if set, the base URL from AIRCREDIT_BASE_URL.
const client = Client.fromEnv();
// The catalog lists every builtin field, check, document type and template.
const catalog = await client.getCatalog();
console.log("catalog version:", catalog.catalog_version);
// Upload the payslip. The filename and media type come from the path.
const file = await client.createFile("payslip.pdf");
// Ask for the builtin net salary under your own key, waiting up to 30 seconds.
const created = await client.createAnalysis(
{
files: [file.id],
language: "en",
spec: { fields: { net_income: { builtin: "net_salary" } } },
},
{ wait: 30 },
);
// A live analysis can take longer, so poll for up to two minutes.
const analysis = await client.waitForAnalysis(created.id, { timeout: 120 });
// Only a succeeded analysis has a result.
if (analysis.status !== "succeeded") {
throw new Error(`the analysis ended as ${analysis.status}`);
}
const netIncome = analysis.result.fields.net_income;
console.log(netIncome?.status, netIncome?.value, netIncome?.citations);
// Delete the analysis, then the file.
await client.deleteAnalysis(analysis.id);
await client.deleteFile(file.id);Fetch the catalog
The catalog lists everything you can request by name: builtin fields, checks, document types and
templates. This quickstart uses one builtin field from it, net_salary. The example fetches the
catalog with GET /v1/catalog.
The response also contains catalog_version, a fingerprint of the builtin definitions. It changes
whenever the meaning of a builtin changes. It is for your records only. No request accepts it.
Upload the payslip
The example sends the file as multipart form data to POST /v1/files. The SDKs take the file name
and content type from the path, and send a new Idempotency-Key with every upload.
The API answers 201 with the ID of the new file and a Location header. The next step uses the
ID. AirCredit prepares the file in the background. You can create an analysis right away.
Ask for the net salary
An analysis names the files to read and what to find in them. The example's request to
POST /v1/analyses asks for one builtin field:
net_incomeis your own name for the result. The response uses it as the key.net_salaryis the builtin field from the catalog.languagesets the language of the result. Without it, the result is in German.- The wait of 30 seconds sends
Prefer: wait=30. The API then holds the response for up to 30 seconds while the analysis runs.
The SDKs send a new Idempotency-Key with every new analysis. If the response is lost, send the
same request again with the key of the first attempt, which the SDKs accept as an option. The API
then returns the existing analysis. It does not create or charge a second one.
Use case 6 passes its own key.
| Status | Meaning |
|---|---|
200 | The analysis has finished. It succeeded, failed or was canceled. |
202 | The analysis is still queued or running. The next step waits for it. |
Analyses explains the Location, Retry-After and
Preference-Applied headers of these responses.
Read the result
With a test key, the analysis has already finished. A live analysis can take longer. The example
requests it with GET /v1/analyses/{id} every two seconds until its status is succeeded,
failed or canceled, and stops waiting after two minutes.
Check status before you use a value:
succeeded: the net salary is inresult.fields.net_income, with itsstatus,valueandcitations.failed:errorgives the reason.
If the analysis is still running when the example stops waiting, keep its ID and request it again later. Alternatively, a webhook reports when it finishes.
citations lists the passages the value was read from. A test result has no citations. Some live
citations have no position on the page, as Citations explains.
Clean up
The example deletes the finished analysis with DELETE /v1/analyses/{id}, then the file with
DELETE /v1/files/{id}. Each call returns an empty 204. Both are unavailable immediately.
AirCredit removes the stored data later, as Retention and deletion explains.
Next steps
Use cases shows six typical broker tasks with the same setup, from several fields and checks to a complete financing case.