Skip to content
APIonWeb

Developer Docs

Examples

Browse documentation

Worked examples that go beyond a single request — submitting an asynchronous job and polling it to completion, and handling errors the way a production integration should.

Submit and poll an async job

A complete workflow for an AI-generative category (dress, in this case): submit the request, then poll the status endpoint every couple of seconds until it's no longer processing. For production use, prefer a webhook over polling where you can.

# 1. Submit the job
curl -s -X POST https://apionweb.com/v1/virtual-try-on \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "category": "dress",
    "person_image": "https://example.com/person.jpg",
    "product_image": "https://example.com/dress.jpg"
  }'
# => { "request_id": "3af9c2e1-...", "status": "processing" }

# 2. Poll until it's done
curl -s https://apionweb.com/v1/virtual-try-on/3af9c2e1-... \
  -H "Authorization: Bearer YOUR_API_KEY"

Branching on error codes

Handle each error meaningfully instead of showing a generic failure — see the full list on Errors.

Laravel
use Illuminate\Support\Facades\Http;

$response = Http::withToken('YOUR_API_KEY')
    ->post('https://apionweb.com/v1/virtual-try-on', [
        'category' => 'glasses',
        'person_image' => $personImageUrl,
        'product_model' => $productModelUrl,
    ]);

if ($response->failed()) {
    $code = $response->json('error.code');

    match ($code) {
        'insufficient_balance' => $this->promptUserToRecharge(),
        'rate_limit_exceeded' => $this->retryLater($response),
        'invalid_image', 'invalid_model' => $this->reportBadInput($response->json('error.message')),
        default => $this->logUnexpectedError($response->status(), $code),
    };

    return;
}

$result = $response->json();

Polling with backoff on rate limits

If you're polling frequently, back off when you hit 429 rate_limit_exceeded instead of retrying immediately — see Rate Limits.

Python
import time
import requests

def poll_with_backoff(request_id, headers, max_attempts=8):
    delay = 1

    for attempt in range(max_attempts):
        response = requests.get(
            f"https://apionweb.com/v1/virtual-try-on/{request_id}",
            headers=headers,
        )

        if response.status_code == 429:
            time.sleep(delay)
            delay = min(delay * 2, 30)
            continue

        data = response.json()

        if data.get("status") != "processing":
            return data

        time.sleep(2)

    raise TimeoutError("Try-on did not finish in time")