Tiny, production-friendly helper for the OpenAI Batch API
Project description
OpenAI Batch Helper
Tiny, production-friendly helper for the OpenAI Batch API.
Installation
pip install openai-batch-helper
Minimal Example
from openai_batch_helper import BatchHelper
helper = BatchHelper(endpoint="/v1/chat/completions", completion_window="24h")
job = helper.init_job()
job.add_lines([
{
"custom_id": "t1",
"method": "POST",
"url": "/v1/chat/completions",
"body": {
"model": "gpt-4o-mini",
"messages": [
{"role": "system", "content": "Be concise."},
{"role": "user", "content": "Explain idempotency in one sentence."}
]
}
}
])
(job.submit_file()
.submit_batch_job(metadata={"project":"demo"})
.wait_for_completion(poll_seconds=5))
out_path = job.download_result()
print("Results file:", out_path)
print(job.map_by_custom_id())
Resume an existing batch job and continue polling:
job = helper.resume_job("batch_123")
job.wait_for_completion()
job.download_result()
CLI
python -m openai_batch_helper --input requests.jsonl --endpoint /v1/chat/completions --out results.jsonl \
--poll-seconds 5 --metadata project=demo env=dev --completion-window 24h
The package also installs a console script so you can run openai-batch-helper with the same flags, or python -m openai_batch_helper ....
Documentation
- Latest docs: https://openai-batch-helper.readthedocs.io
- Build locally:
pip install -e .[docs]
sphinx-build -b html doc/ doc/_build/html
Development
pip install -e .[dev]
pytest -q
mypy openai_batch_helper
ruff check .
To cut a PyPI release:
python -m build
twine check dist/*
# then twine upload dist/*
Refer to AGENTS.md and BATCH_API.md for design and API background.
CI/CD hooks
- Tests: GitHub Actions runs lint + unit tests on pushes/PRs (
.github/workflows/tests.yml). - Releases: Publishing is automated from GitHub releases via
.github/workflows/release.yml; setPYPI_API_TOKENsecret in the repo to upload to PyPI. - Docs:
.github/workflows/docs.ymlbuilds docs locally and triggers Read the Docs; setRTD_TOKENsecret and ensure the RTD project slug isopenai-batch-helper.
Examples
examples/chat_batch_minimal.py— Chat batch usingadd_linein a loop.- Run:
python examples/chat_batch_minimal.py
- Run:
examples/embeddings_batch_minimal.py— Embeddings batch usingadd_linein a loop.- Run:
python examples/embeddings_batch_minimal.py
- Run:
examples/chat_batch_add_task.py— Chat batch usingadd_taskconvenience.- Run:
python examples/chat_batch_add_task.py
- Run:
examples/embeddings_batch_add_task.py— Embeddings batch usingadd_task.- Run:
python examples/embeddings_batch_add_task.py
- Run:
examples/chat_batch_add_lines_list.py— Chat batch usingadd_lines([...]).- Run:
python examples/chat_batch_add_lines_list.py
- Run:
All examples require OPENAI_API_KEY in your environment.
Project details
Release history Release notifications | RSS feed
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 openai_batch_helper-0.1.0.tar.gz.
File metadata
- Download URL: openai_batch_helper-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04f3e4b7a1201bc8ce1d2eedcf012eb454e45d648aae1d813c8d2833c06d5e8b
|
|
| MD5 |
764e3ac5400fe0ec4267567acc368c71
|
|
| BLAKE2b-256 |
78dd82738fbd380bb72bfc2b88296f222f266376d0c5c0683b286ec56847d0d8
|
File details
Details for the file openai_batch_helper-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openai_batch_helper-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abee3017dfbca044f0cb01e2a631b619b95c76719880cc86b88643bca1d78d9e
|
|
| MD5 |
c723227d065bf6ddaa57891355ddd09b
|
|
| BLAKE2b-256 |
22a73a07b7192e7c708b17ae9da57801b2f62e748d6f9420a8727c22d9708ed8
|