Skip to main content

Unified async batch API for AI providers

Project description

Batchwork

Batchwork — one typed API for provider-native AI batch jobs

Unified async batch API for OpenAI, Anthropic, Google Gemini, Groq, Mistral, Together AI, and xAI. Providers price eligible batch requests up to 50% below standard synchronous calls, and Batchwork gives you that pricing through one typed Python interface and one CLI. It handles provider-specific serialization, submission, polling, and result parsing so you do not have to. Pricing and eligibility remain provider- and model-specific.

  • One typed API for provider-native batch jobs
  • Text, embedding, and image workloads
  • Normalized jobs, results, usage, and errors
  • Messages, tools, structured content, and remote media
  • Polling, persistent stores, and signed webhooks
  • A batchwork CLI and Agent Skill for terminals, scripts, and coding agents
  • No provider SDK or JavaScript runtime dependencies

📖 Full documentation: batchwork.ajanraj.com

Installation

Batchwork requires Python 3.11 or newer.

With uv:

uv add batchwork-ai

With pip:

pip install batchwork-ai

Then configure a provider credential:

export OPENAI_API_KEY="..."

See Configuration for every provider credential, endpoint override, model format, and batch limit.

Command-line tool

The same package ships a batchwork command, so you can submit and manage batches without writing Python. Install it with uv tool:

uv tool install batchwork-ai
batchwork --version

Human quick start:

batchwork submit text prompts.txt --model openai/gpt-5
batchwork list
batchwork status BW_RECORD_ID
batchwork results BW_RECORD_ID

Agent and automation quick start:

batchwork --jsonl --quiet run text requests.jsonl --model openai/gpt-5

Machine output uses schema version 1. Global controls such as --jsonl, --profile, and --quiet precede the command. Preserve the first emitted job identity, capture stdout/stderr/exit status separately, and never retry an acceptance-ambiguous submission automatically. Image files are written only when --output-dir is explicit.

If you use a coding agent, the batchwork-ai Agent Skill teaches it the same contract, including when to ask before spending money and how to resume interrupted jobs:

npx skills add ajanraj/batchwork-ai@batchwork-ai

See the CLI guide, configuration and registry reference, machine schema, and exit catalog.

Quickstart

import asyncio

from batchwork import BatchRequest, Batchwork


async def main() -> None:
    async with Batchwork() as client:
        job = await client.batch(
            model="openai/gpt-5.6-sol",
            requests=[BatchRequest(custom_id="hello", prompt="Say hello")],
        )
        await job.wait(timeout=3600)

        for result in await job.collect():
            print(result.custom_id, result.text)


asyncio.run(main())

Submitting returns a BatchJob immediately. Provider processing is asynchronous and may take minutes or, depending on the provider and workload, up to 24 hours.

Models use provider/model form. Results are correlated with requests through custom_id; provider output order is not guaranteed.

Providers

Output workloads supported by Batchwork:

Provider Text Embeddings Image generation
OpenAI Yes Yes Yes
Anthropic Yes No No
Google Gemini Yes Yes Yes
Groq Yes No No
Mistral Yes Yes No
Together AI Yes No No
xAI Yes No Yes

Image, PDF, text-file, and audio inputs for text requests vary separately from output modalities. Provider APIs may also impose model-specific limits. See the provider overview for input support, submission transport, credentials, and restrictions.

Optional Redis store

Install the Upstash Redis integration for persistent polling state:

uv add "batchwork-ai[redis]"
# or
pip install "batchwork-ai[redis]"

The base package does not import or require upstash-redis.

Documentation

License

MIT © Ajanraj

Acknowledgements

Inspired by Hayden Bleasel's Batchwork.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

batchwork_ai-0.2.1.tar.gz (131.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

batchwork_ai-0.2.1-py3-none-any.whl (159.7 kB view details)

Uploaded Python 3

File details

Details for the file batchwork_ai-0.2.1.tar.gz.

File metadata

  • Download URL: batchwork_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 131.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for batchwork_ai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b7e7921c25eb026151e48727f713e9709303746cc9267d9692c5fdbc8d30b7e9
MD5 2d763704f4cb2a4e211d27ed648d8c3d
BLAKE2b-256 e3a791490fdfa3a6d4d75f264685e0fa8bbbe764054d65cd660f7ee8d4de4ebd

See more details on using hashes here.

Provenance

The following attestation bundles were made for batchwork_ai-0.2.1.tar.gz:

Publisher: publish.yml on ajanraj/batchwork-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file batchwork_ai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: batchwork_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 159.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for batchwork_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2361fa19d92c95f33541768fdfeda58b849a6ed0200bad1fc71ed2a02347f8f2
MD5 e4450945e131b1a679f09993ca5b2e8f
BLAKE2b-256 dee0a8be4a14842d8919b5ee34cc767544e5fd82aa2ce822d30409b8fc8e71cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for batchwork_ai-0.2.1-py3-none-any.whl:

Publisher: publish.yml on ajanraj/batchwork-ai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page