Anthropic
Run batches on Anthropic's Message Batches API — an inline request array, no file uploads.
Anthropic's Message Batches API takes a different shape from OpenAI's: instead of uploading a file, you send all requests inline as a JSON array, then stream results from a results_url once the batch ends. Batchwork normalizes that into the same batch() call you use everywhere else.
| Property | Value |
|---|---|
| Shape | Inline requests[] array |
| Endpoint | /v1/messages/batches |
| Results | results_url (JSONL stream) |
| Webhooks | Poll-only (managed by the server) |
| Env var | ANTHROPIC_API_KEY |
| Package | @ai-sdk/anthropic |
| Base URL | https://api.anthropic.com |
Example
import { batch } from "batchwork";
import { anthropic } from "@ai-sdk/anthropic";
const job = await batch({
model: anthropic("claude-opus-4-8"),
requests: [
{ customId: "fr", prompt: "Capital of France? One word." },
{ customId: "jp", prompt: "Capital of Japan? One word." },
],
});How it works
- Build — each request becomes an inline entry
{ custom_id, params }, whereparamsis the captured message body. - Submit —
POST /v1/messages/batchessends the wholerequestsarray in one call (sent withanthropic-version: 2023-06-01). - Poll — Batchwork reads
processing_statusuntil it reportsended. - Read — the JSONL at
results_urlis streamed and parsed intoBatchResults.
Batchwork only follows results_url values on the configured Anthropic API origin, so provider auth headers are not sent to arbitrary hosts.
Batchwork validates Anthropic batch ids before using them in API paths.
Each result line carries a result.type of succeeded, errored, canceled, or expired, which Batchwork maps onto the normalized result status.
Webhooks
Anthropic has no native batch webhook, so it is poll-only. Use the server layer's managed poller to get one unified, signed event when a batch finishes — the same event shape as every other provider.
Credentials
Set ANTHROPIC_API_KEY, or pass apiKey / baseURL / headers to batch(). To enable beta features, pass an anthropic-beta value via headers. Install the peer dependency:
bun add @ai-sdk/anthropic