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.2.tar.gz (131.7 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.2-py3-none-any.whl (159.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: batchwork_ai-0.2.2.tar.gz
  • Upload date:
  • Size: 131.7 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.2.tar.gz
Algorithm Hash digest
SHA256 e07f62d2f339daf9d4c3297d7fe291e0f4b25a95229d79734825e926e63940ff
MD5 31a16a04321df7c2b5c1fcd62d06894e
BLAKE2b-256 4ce85a0e4d590d5608aac5d81ea3049322930f734ee6eca27efad11547299736

See more details on using hashes here.

Provenance

The following attestation bundles were made for batchwork_ai-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: batchwork_ai-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 159.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 34eb2bca6d7ad938da17220c42d9ff0ca7fe00ea050597ff4c82e9a4efbfef15
MD5 a25055efdbec3fd229659a996ed24017
BLAKE2b-256 d1220cf448bd2d0b0b9a1d5fed52c20121308b168b75d0870215dcc9a5af8454

See more details on using hashes here.

Provenance

The following attestation bundles were made for batchwork_ai-0.2.2-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