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.

PropertyValue
ShapeInline requests[] array
Endpoint/v1/messages/batches
Resultsresults_url (JSONL stream)
WebhooksPoll-only (managed by the server)
Env varANTHROPIC_API_KEY
Package@ai-sdk/anthropic
Base URLhttps://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

  1. Build — each request becomes an inline entry { custom_id, params }, where params is the captured message body.
  2. SubmitPOST /v1/messages/batches sends the whole requests array in one call (sent with anthropic-version: 2023-06-01).
  3. Poll — Batchwork reads processing_status until it reports ended.
  4. Read — the JSONL at results_url is streamed and parsed into BatchResults.

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

On this page