Browse docs ▾
API reference

Batch API

Send thousands of requests at once and collect the results within 24 hours, at half the usual price. Batches run on the provider's own batch service, and you get the provider's full discount.

FieldTypeDescription
OpenAI format/v1/files + /v1/batchesOpenAI, Google (Gemini), Mistral and Qwen models, each on that provider's own batch service. Up to 50,000 requests or 200 MB per batch.
Anthropic format/v1/messages/batchesClaude models, on Anthropic's Message Batches API. Up to 100,000 requests or 256 MB per batch. Results kept 29 days.

Every provider bills batch tokens at 50% of the standard price, and the full discount is passed on. Requests that fail, expire or are cancelled are free.

Providers

FieldTypeDescription
OpenAIchat, embeddingsResults kept 30 days. Several models can share a batch.
AnthropicmessagesAnthropic format only. Results kept 29 days.
GooglechatRequests are translated to Gemini and results back to OpenAI's shape. One model per batch. Batches expire after 48 hours.
Mistralchat, embeddingsOne model per batch.
Qwenchat, embeddingsOnly models Alibaba enables for batch in its international region.

OpenAI format

Works with the OpenAI SDKs unchanged: point them at https://boldrouter.com/v1. Each line of the file is one request. Use the provider's model ids or boldrouter ids such as openai/gpt-4.1 or google/gemini-2.5-flash. All requests in a batch must be for the same provider, which runs the batch.

python
from openai import OpenAI

client = OpenAI(base_url="https://boldrouter.com/v1", api_key="sk-bold-...")

# requests.jsonl - one request per line:
# {"custom_id": "q1", "method": "POST", "url": "/v1/chat/completions",
#  "body": {"model": "openai/gpt-4.1", "messages": [{"role": "user", "content": "Hi"}], "max_tokens": 200}}
file = client.files.create(file=open("requests.jsonl", "rb"), purpose="batch")
batch = client.batches.create(input_file_id=file.id, endpoint="/v1/chat/completions", completion_window="24h")

batch = client.batches.retrieve(batch.id)          # poll until status is "completed"
results = client.files.content(batch.output_file_id).text
POST/v1/files
POST/v1/batches
GET/v1/batches/{id}
POST/v1/batches/{id}/cancel
GET/v1/files/{id}/content

Supported endpoints: /v1/chat/completions and /v1/embeddings. GET /v1/batches, GET /v1/files, GET /v1/files/{id} and DELETE /v1/files/{id} work as on OpenAI. A finished batch also reports its cost in USD and the provider that ran it.

Anthropic format

Works with the Anthropic SDKs: set the base URL to https://boldrouter.com. Each request's params are a normal Messages request and reach Anthropic unchanged, cache_control and anthropic-beta headers included. Only model is rewritten, and only when you use a boldrouter id.

python
import anthropic

client = anthropic.Anthropic(base_url="https://boldrouter.com", api_key="sk-bold-...")
batch = client.messages.batches.create(requests=[
    {"custom_id": "q1", "params": {"model": "claude-sonnet-4-6", "max_tokens": 200,
                                   "messages": [{"role": "user", "content": "Hi"}]}},
])

batch = client.messages.batches.retrieve(batch.id)  # poll until processing_status is "ended"
for result in client.messages.batches.results(batch.id):
    print(result.custom_id, result.result.type)
POST/v1/messages/batches
GET/v1/messages/batches/{id}
GET/v1/messages/batches/{id}/results
POST/v1/messages/batches/{id}/cancel

GET /v1/messages/batches lists your batches, and DELETE /v1/messages/batches/{id} deletes one that has ended.

Billing

  • When you submit a batch, its worst-case cost at the batch price is held against your balance and budgets. That uses each request's max_tokens, or 4,096 output tokens when a request sets none. If the hold doesn't fit, the batch is refused with 402 and nothing is sent.
  • When the batch ends, each successful request is billed at its real usage and the hold is released. Usage appears in your dashboard under each model, marked as batch.
  • With your own provider key, the batch runs in your provider account and boldrouter charges its platform fee on the batch price.
  • Anthropic web searches are billed at $0.01 each. The batch discount doesn't apply to them.

Checked before anything runs

Every request in a batch is checked against your workspace's model rules and blocked countries. Any problem rejects the whole batch with a 400 that lists the line numbers (OpenAI format) or requests[i] indexes (Anthropic format).

Limits and data

  • Claude models use the Anthropic format; OpenAI, Google, Mistral and Qwen models use the OpenAI format. Other providers don't offer batches.
  • Routing, failover and prompt anonymization don't apply to batches: each request runs on the one provider you chose. Workspace keys with data protection on can't submit batches.
  • An uploaded file is stored encrypted only until its batch is submitted. Unused uploads are deleted after 7 days. boldrouter stores no results: downloads come straight from the provider for as long as it keeps them.
Batches usually finish well within an hour, but can take up to 24 hours. Requests still waiting at 24 hours expire, and aren't billed.