Skip to content

Quickstart

This walk-through creates a case, attaches its agreement and runs the automatic pipeline. You need an API key (see Authentication).

Terminal window
export RECOVAI_API_KEY="rk_..." # your key
export RECOVAI=https://api.recovai.ai
  1. 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.id from the response.

  2. Upload the agreement.

    Terminal window
    curl -s $RECOVAI/cases/$CASE_ID/documents \
    -H "X-API-Key: $RECOVAI_API_KEY" \
    -F type=contract \
    -F file=@agreement.pdf

    The response includes the case’s new readiness.

  3. Run the pipeline.

    Terminal window
    curl -s -X POST $RECOVAI/cases/$CASE_ID/advance \
    -H "X-API-Key: $RECOVAI_API_KEY"

    This returns 202 Accepted with a job_id.

  4. Wait for the job.

    Terminal window
    curl -s $RECOVAI/jobs/$JOB_ID -H "X-API-Key: $RECOVAI_API_KEY"

    Poll every few seconds until finished is true.

  5. Read the case.

    Terminal window
    curl -s $RECOVAI/cases/$CASE_ID -H "X-API-Key: $RECOVAI_API_KEY"

    readiness and main_blocker tell you what the case needs next.

PHP 8 or later with the cURL extension.

<?php
// quickstart.php: php quickstart.php agreement.pdf
const 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 agreement
api('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";