Skip to main content

Tiny, production-friendly helper for the OpenAI Batch API

Project description

OpenAI Batch Helper

Tests PyPI Docs

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

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; set PYPI_API_TOKEN secret in the repo to upload to PyPI.
  • Docs: .github/workflows/docs.yml builds docs locally and triggers Read the Docs; set RTD_TOKEN secret and ensure the RTD project slug is openai-batch-helper.

Examples

  • examples/chat_batch_minimal.py — Chat batch using add_line in a loop.
    • Run: python examples/chat_batch_minimal.py
  • examples/embeddings_batch_minimal.py — Embeddings batch using add_line in a loop.
    • Run: python examples/embeddings_batch_minimal.py
  • examples/chat_batch_add_task.py — Chat batch using add_task convenience.
    • Run: python examples/chat_batch_add_task.py
  • examples/embeddings_batch_add_task.py — Embeddings batch using add_task.
    • Run: python examples/embeddings_batch_add_task.py
  • examples/chat_batch_add_lines_list.py — Chat batch using add_lines([...]).
    • Run: python examples/chat_batch_add_lines_list.py

All examples require OPENAI_API_KEY in your environment.

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

openai_batch_helper-0.1.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

openai_batch_helper-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

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

Hashes for openai_batch_helper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 04f3e4b7a1201bc8ce1d2eedcf012eb454e45d648aae1d813c8d2833c06d5e8b
MD5 764e3ac5400fe0ec4267567acc368c71
BLAKE2b-256 78dd82738fbd380bb72bfc2b88296f222f266376d0c5c0683b286ec56847d0d8

See more details on using hashes here.

File details

Details for the file openai_batch_helper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_batch_helper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abee3017dfbca044f0cb01e2a631b619b95c76719880cc86b88643bca1d78d9e
MD5 c723227d065bf6ddaa57891355ddd09b
BLAKE2b-256 22a73a07b7192e7c708b17ae9da57801b2f62e748d6f9420a8727c22d9708ed8

See more details on using hashes here.

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