Quickstart
This walk-through creates a case, attaches its agreement and runs the automatic pipeline. You need an API key (see Authentication).
export RECOVAI_API_KEY="rk_..." # your keyexport RECOVAI=https://api.recovai.ai-
Create a case.
Terminal window curl -s $RECOVAI/cases \-H "X-API-Key: $RECOVAI_API_KEY" \-H "Content-Type: application/json" \-d '{"business_name": "Example Trading LLC","balance": 48250.00,"external_reference": "ACCT-000123"}'Keep the
case.idfrom the response. -
Upload the agreement.
Terminal window curl -s $RECOVAI/cases/$CASE_ID/documents \-H "X-API-Key: $RECOVAI_API_KEY" \-F type=contract \The response includes the case’s new
readiness. -
Run the pipeline.
Terminal window curl -s -X POST $RECOVAI/cases/$CASE_ID/advance \-H "X-API-Key: $RECOVAI_API_KEY"This returns
202 Acceptedwith ajob_id. -
Wait for the job.
Terminal window curl -s $RECOVAI/jobs/$JOB_ID -H "X-API-Key: $RECOVAI_API_KEY"Poll every few seconds until
finishedistrue. -
Read the case.
Terminal window curl -s $RECOVAI/cases/$CASE_ID -H "X-API-Key: $RECOVAI_API_KEY"readinessandmain_blockertell you what the case needs next.
The same flow in code
Section titled “The same flow in code”PHP 8 or later with the cURL extension.
<?php// quickstart.php: php quickstart.php agreement.pdfconst BASE = 'https://api.recovai.ai';
function api(string $method, string $path, array $options = []): array{ $ch = curl_init(BASE . $path); $headers = ['X-API-Key: ' . getenv('RECOVAI_API_KEY')]; if (isset($options['json'])) { $headers[] = 'Content-Type: application/json'; curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($options['json'])); } elseif (isset($options['multipart'])) { curl_setopt($ch, CURLOPT_POSTFIELDS, $options['multipart']); } curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => $method, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => $headers, CURLOPT_TIMEOUT => 60, ]); $body = json_decode(curl_exec($ch), true); $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); curl_close($ch); if ($status >= 400) { throw new RuntimeException("$status {$body['error']}: " . ($body['details'] ?? '')); } return $body;}
// 1. Create a case$case = api('POST', '/cases', ['json' => [ 'business_name' => 'Example Trading LLC', 'balance' => 48250.00, 'external_reference' => 'ACCT-000123',]])['case'];echo "created {$case['case_number']}\n";
// 2. Upload the agreementapi('POST', "/cases/{$case['id']}/documents", ['multipart' => [ 'type' => 'contract', 'file' => new CURLFile($argv[1], 'application/pdf'),]]);
// 3. Run the pipeline and 4. wait for it$jobId = api('POST', "/cases/{$case['id']}/advance")['job_id'];do { sleep(3); $job = api('GET', "/jobs/$jobId")['job'];} while (!$job['finished']);
// 5. Read the case$case = api('GET', "/cases/{$case['id']}")['case'];echo $case['readiness'] . ' ' . ($case['main_blocker'] ?? '') . "\n";Node 18 or later (built-in fetch).
// quickstart.mjs: node quickstart.mjs agreement.pdfimport { readFile } from 'node:fs/promises';import { basename } from 'node:path';
const BASE = 'https://api.recovai.ai';const headers = { 'X-API-Key': process.env.RECOVAI_API_KEY };
async function api(path, init = {}) { const res = await fetch(BASE + path, { ...init, headers: { ...headers, ...init.headers } }); const body = await res.json(); if (!res.ok) throw new Error(`${res.status} ${body.error}: ${body.details ?? ''}`); return body;}
// 1. Create a caseconst { case: kase } = await api('/cases', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ business_name: 'Example Trading LLC', balance: 48250.0, external_reference: 'ACCT-000123' }),});console.log('created', kase.case_number);
// 2. Upload the agreementconst file = process.argv[2];const form = new FormData();form.append('type', 'contract');form.append('file', new Blob([await readFile(file)], { type: 'application/pdf' }), basename(file));await api(`/cases/${kase.id}/documents`, { method: 'POST', body: form });
// 3. Run the pipeline and 4. wait for itlet { job_id } = await api(`/cases/${kase.id}/advance`, { method: 'POST' });let job;do { await new Promise((r) => setTimeout(r, 3000)); ({ job } = await api(`/jobs/${job_id}`));} while (!job.finished);
// 5. Read the caseconst { case: updated } = await api(`/cases/${kase.id}`);console.log(updated.readiness, updated.main_blocker ?? '');Python 3.9 or later, with the requests package installed.
# quickstart.py: python quickstart.py agreement.pdfimport os, sys, timeimport requests
BASE = "https://api.recovai.ai"session = requests.Session()session.headers["X-API-Key"] = os.environ["RECOVAI_API_KEY"]
def api(method, path, **kwargs): res = session.request(method, BASE + path, timeout=60, **kwargs) body = res.json() if not res.ok: raise RuntimeError(f"{res.status_code} {body.get('error')}: {body.get('details', '')}") return body
# 1. Create a casecase = api("POST", "/cases", json={ "business_name": "Example Trading LLC", "balance": 48250.00, "external_reference": "ACCT-000123",})["case"]print("created", case["case_number"])
# 2. Upload the agreementpath = sys.argv[1]with open(path, "rb") as f: api("POST", f"/cases/{case['id']}/documents", data={"type": "contract"}, files={"file": (os.path.basename(path), f, "application/pdf")})
# 3. Run the pipeline and 4. wait for itjob_id = api("POST", f"/cases/{case['id']}/advance")["job_id"]while True: time.sleep(3) job = api("GET", f"/jobs/{job_id}")["job"] if job["finished"]: break
# 5. Read the casecase = api("GET", f"/cases/{case['id']}")["case"]print(case["readiness"], case.get("main_blocker") or "")