Skip to main content

Tiny, production-friendly helper for the OpenAI Batch API

Project description

OpenAI Batch Helper

Tests PyPI Docs

Running the OpenAI Batch API can cut per-request costs by roughly 50%. But the process through the default OpenAI Python SDK is very cumbersome. It requires users to manage JSONL uploads, poll for status updates, download results in JSONL format again, and parse them. This quickly turns messy. The package openai_batch_helper helper keeps the batch flow tidy, typed, and production-friendly.

Install

pip install openai-batch-helper

Quickstart (add_task)

from openai_batch_helper import BatchHelper, status_progress_logger

helper = BatchHelper(endpoint="/v1/chat/completions", completion_window="24h")
job = helper.init_job()

job.add_task(
    "t1",
    body={
        "model": "gpt-4o-mini",
        "messages": [
            {"role": "system", "content": "Be concise."},
            {"role": "user", "content": "Explain idempotency in one sentence."},
        ],
    },
)
job.add_task(
    "t2",
    body={
        "model": "gpt-4o-mini",
        "messages": [
            {"role": "system", "content": "Be concise."},
            {"role": "user", "content": "List 3 benefits of unit tests."},
        ],
    },
)

(job
 .submit_file()
 .submit_batch_job(metadata={"project": "demo"})
 .wait_for_completion(poll_seconds=5.0, on_update=status_progress_logger()))

print(job.download_result())
print(job.map_by_custom_id())

Learn more

Check the docs for CLI usage, additional helpers, and troubleshooting: https://openai-batch-helper.readthedocs.io .

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.1.tar.gz (13.0 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.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file openai_batch_helper-0.1.1.tar.gz.

File metadata

  • Download URL: openai_batch_helper-0.1.1.tar.gz
  • Upload date:
  • Size: 13.0 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.1.tar.gz
Algorithm Hash digest
SHA256 6b98d974fdf713753c680c576b240fde2062e893b28cb01cdc75e65b543a125d
MD5 071d04312a3a677a75d0b970657f90bc
BLAKE2b-256 11aa6f26958449dafba6e1333820ddaf4f67f688bce89856d788d42efacfee41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openai_batch_helper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80ff8aaaa75128186f67d27817364da279112a60f13769db3b62268f6475d8fe
MD5 6eb46690d9ece15362c3aaf6da783a95
BLAKE2b-256 1d3c804187f216a8d450a15e9385a48cd0d7043786accb7cf8d820731d2ec902

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