Unified async batch API for AI providers
Project description
Batchwork
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
batchworkCLI 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
- Installation
- Configuration
- Jobs
- Results
- Text, embeddings, and images
- Provider overview
- Polling and webhooks
- Stores
- Security
- Examples
- Public API
- FAQ
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7e7921c25eb026151e48727f713e9709303746cc9267d9692c5fdbc8d30b7e9
|
|
| MD5 |
2d763704f4cb2a4e211d27ed648d8c3d
|
|
| BLAKE2b-256 |
e3a791490fdfa3a6d4d75f264685e0fa8bbbe764054d65cd660f7ee8d4de4ebd
|
Provenance
The following attestation bundles were made for batchwork_ai-0.2.1.tar.gz:
Publisher:
publish.yml on ajanraj/batchwork-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
batchwork_ai-0.2.1.tar.gz -
Subject digest:
b7e7921c25eb026151e48727f713e9709303746cc9267d9692c5fdbc8d30b7e9 - Sigstore transparency entry: 2206952873
- Sigstore integration time:
-
Permalink:
ajanraj/batchwork-ai@4b40af1c1c69c9d75554785e4a977fda9e6ebbd3 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ajanraj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b40af1c1c69c9d75554785e4a977fda9e6ebbd3 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2361fa19d92c95f33541768fdfeda58b849a6ed0200bad1fc71ed2a02347f8f2
|
|
| MD5 |
e4450945e131b1a679f09993ca5b2e8f
|
|
| BLAKE2b-256 |
dee0a8be4a14842d8919b5ee34cc767544e5fd82aa2ce822d30409b8fc8e71cf
|
Provenance
The following attestation bundles were made for batchwork_ai-0.2.1-py3-none-any.whl:
Publisher:
publish.yml on ajanraj/batchwork-ai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
batchwork_ai-0.2.1-py3-none-any.whl -
Subject digest:
2361fa19d92c95f33541768fdfeda58b849a6ed0200bad1fc71ed2a02347f8f2 - Sigstore transparency entry: 2206952880
- Sigstore integration time:
-
Permalink:
ajanraj/batchwork-ai@4b40af1c1c69c9d75554785e4a977fda9e6ebbd3 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ajanraj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4b40af1c1c69c9d75554785e4a977fda9e6ebbd3 -
Trigger Event:
push
-
Statement type: