Skip to content

Quickstart

BatchRouter is an OpenAI-Batch-compatible API that routes batch AI workloads across many providers, picking the cheapest lane that meets your SLA, privacy, and tool requirements — with a routing receipt for every decision. This page takes you from zero to your first completed batch in five steps.

The flow is always: quote (free) → create → poll → results. Quotes cost nothing; credits are reserved only when you create a batch and settled from actual token usage.

You’ll need an API key and a small credit balance. The base URL is https://api.batchrouter.com (use https://test.api.batchrouter.com for testing), and every endpoint lives under /v1. Authenticate by sending your key as a bearer token:

Terminal window
export BATCHROUTER_API_KEY="br_live_…"
Terminal window
curl https://api.batchrouter.com/v1/auth/account \
-H "Authorization: Bearer $BATCHROUTER_API_KEY"

That call returns your account, including credit_balance. If it’s zero, you’ll get a 402 on create — add credits from the billing dashboard.

  1. Create an API key.

    Create a key in the dashboard or, for an agent-first flow with no email, call POST /v1/auth/agent-register to get an org_id and api_key in one shot.

    See Authentication for both paths and key rotation.

  2. Get a free quote.

    Send your items to POST /v1/quotes/model. BatchRouter prices the work, picks a lane, and returns a quote_id (qlock_…) plus a per-lane breakdown. Quoting is free and reserves nothing.

    Terminal window
    curl https://api.batchrouter.com/v1/quotes/model \
    -H "Authorization: Bearer $BATCHROUTER_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "routing_mode": "cheapest",
    "items": [
    {
    "customer_item_id": "item-1",
    "operation": "responses",
    "model": "gpt-4o-mini",
    "input": {
    "messages": [
    { "role": "user", "content": "Summarize: BatchRouter routes batch-AI workloads across providers." }
    ]
    }
    }
    ]
    }'

    The response includes quote_id, a pricing_estimate (provider_subtotal, batchrouter_fee, customer_discount, total), the selected quote_lanes, and a plain-language customer_explanation. Unselected lanes come back with rejection reasons such as capacity_full, context_window_exceeded, or tool_support.

  3. Submit your first batch.

    Pass the quote_id to POST /v1/batches and include an Idempotency-Key header (8–128 chars) so retries never create a duplicate. A 202 means it’s accepted and queued.

    Terminal window
    curl https://api.batchrouter.com/v1/batches \
    -H "Authorization: Bearer $BATCHROUTER_API_KEY" \
    -H "Content-Type: application/json" \
    -H "Idempotency-Key: quickstart-batch-001" \
    -d '{
    "quote_id": "qlock_…",
    "sla_tier": "standard",
    "items": [
    {
    "customer_item_id": "item-1",
    "operation": "responses",
    "model": "gpt-4o-mini",
    "input": {
    "messages": [
    { "role": "user", "content": "Summarize: BatchRouter routes batch-AI workloads across providers." }
    ]
    }
    }
    ]
    }'

    The response is { "batch": { "id": "bat_…", "status": "pending", "item_count": 1 } }.

  4. Poll for status.

    Fetch the batch until it reaches a terminal state. Add ?include_billing_receipt=true once it’s done to see the final cost.

    Terminal window
    curl "https://api.batchrouter.com/v1/batches/bat_…" \
    -H "Authorization: Bearer $BATCHROUTER_API_KEY"

    Status moves through this lifecycle:

    pendingqueuedroutingdispatchedprocessingcompletingcompleted

    Terminal states are completed, failed, cancelled, and expired. Poll on an interval (e.g. every 30–60s); to avoid polling entirely, attach a webhook at create time.

  5. Retrieve your results.

    Once status is completed, read the output. GET /v1/batches/{batchId}/results returns one entry per item, paginated.

    Terminal window
    curl "https://api.batchrouter.com/v1/batches/bat_…/results?limit=100" \
    -H "Authorization: Bearer $BATCHROUTER_API_KEY"

    Each result has customer_item_id, status (completed or failed), output, and error. Page with ?cursor=<next_cursor> (limit 1–1000, default 100). For large batches, prefer GET /v1/batches/{batchId}/artifact-url, which returns a short-lived signed url to the full JSONL artifact instead of paginating.

That’s a complete batch, end to end. From here, scale up with file uploads, point an existing OpenAI Batch client at BatchRouter, or switch from polling to webhooks.