Skip to content
Batchwork
Esc
navigateopen⌘Jpreview
On this page

Installation

Install Batchwork and the AI SDK provider packages for the providers you batch with — optional peer dependencies that load lazily per provider.

Install

Batchwork depends on ai (the Vercel AI SDK). The provider packages are optional peer dependencies — install only the ones you batch with.

npm install batchwork @ai-sdk/openai @ai-sdk/anthropic
pnpm add batchwork @ai-sdk/openai @ai-sdk/anthropic
yarn add batchwork @ai-sdk/openai @ai-sdk/anthropic
bun add batchwork @ai-sdk/openai @ai-sdk/anthropic

If you only batch with OpenAI, you only need @ai-sdk/openai — and vice versa.

Credentials

Batchwork reads provider credentials from the standard environment variables:

OPENAI_API_KEY=sk-…
ANTHROPIC_API_KEY=sk-ant-…
AZURE_RESOURCE_NAME=my-azure-openai-resource
AZURE_API_KEY=

Or pass them explicitly per call:

await batch({
  model: "openai/gpt-5.5",
  apiKey: process.env.MY_OPENAI_KEY,
  requests,
});

baseURL and extra headers are accepted the same way for self-hosted gateways or beta flags.

Azure OpenAI also needs AZURE_RESOURCE_NAME (or an explicit Azure baseURL) and accepts AZURE_API_KEY or AZURE_OPENAI_API_KEY. See Azure OpenAI for deployment and Global Batch requirements.

Requirements

  • Node 20+, Bun, or any edge runtime with fetch, FormData, and Web Crypto.
  • The AI SDK v6 (ai@^6) and provider packages v3 (@ai-sdk/openai@^3, @ai-sdk/anthropic@^3).

Errors

All thrown errors extend BatchworkError, with two typed subclasses you may want to catch:

  • MissingDependencyError — you batched a provider whose @ai-sdk/* package isn’t installed. The message tells you exactly what to npm install.
  • UnsupportedProviderError — the model resolved to a provider without a batch adapter (i.e. not one of the eight supported providers).

Provider error responses include the method, URL, and status code, but not the upstream response body. This keeps prompts, provider diagnostics, and other batch data out of route responses and logs by default.

import { batch, MissingDependencyError } from "batchwork";

try {
  await batch({ model: "anthropic/claude-opus-4-8", requests });
} catch (error) {
  if (error instanceof MissingDependencyError) {
    // e.g. run `npm install @ai-sdk/anthropic`
  }
}

Was this page helpful?