Skip to main content

gpt-batch-manager

The OpenAI Batch API is great for submitting batch jobs, but it has some strict limits:

  • gpt-4o: 90,000 tokens (Tier 1), 1.35M (Tier 2)
  • gpt-4o-mini: 2,000,000 tokens (Tier 1), 20M (Tier 2)

If you want to submit larger batches than your current tier allows, you'll have to split the work into multiple batches. This project helps you do that by providing two tools:

  1. gpt-batch-splitter: Take one or more JSONL files and split them into shards that fit within your tier batch queue limit.
  2. gpt-batch-manager: Submit multiple batches to OpenAI, one at a time.

Usage

Install:

pip install gpt-batch-manager

To use the batch manager, you'll need to set an OPENAI_API_KEY environment variable. The best way to do this is by creating a .env file in your working directory. See the OpenAI Python API docs for details.

Batch Splitter

Say your tasks are in largefile1.jsonl and largefile2.jsonl. You want to submit them to the OpenAI batch API for gpt-4o-mini and you're on Tier 1, so you need to make them fit within a 2M token limit.

To produce shards with fewer than 2M tokens, run:

gpt-batch-splitter 1900000 largefile1.jsonl largefile2.jsonl

This will estimate the number of tokens in each request and divvy them up accordingly. It will produce output files like:

shard-000-of-079.jsonl
shard-001-of-079.jsonl
...
shard-078-of-079.jsonl

Since the splitter has to estimate the number of tokens in each request, it's best to use a number somewhat below the limit.

Batch Manager

To stay within your batch limit, you have to submit batch files one-by-one. This is what gpt-batch-manager does. Pass it a set of JSONL files:

gpt-batch-manager shard-???-of-???.jsonl

Make sure you have an OPENAI_API_KEY environment variable set (see above). This will report the status of each batch as it progresses. Output will eventually appear in:

shard-000-of-079.output.jsonl
shard-001-of-079.output.jsonl
...

This process is fully resumable. You can Ctrl-C it at any time and it will pick up where it left off. It stores state in /tmp/batch-status.json. If something goes wrong, you could try deleting that file to reset.

Metadata

Release files for gpt-batch-manager 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gpt-batch-manager 1.0.1
File Size Uploaded Provenance Actions
gpt_batch_manager-1.0.1.tar.gz 9.5 kB Without provenance Details for gpt_batch_manager-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gpt-batch-manager 1.0.1
File Interpreter ABI Platform Actions
gpt_batch_manager-1.0.1-py3-none-any.whl Python 3 none any Details for gpt_batch_manager-1.0.1-py3-none-any.whl

Total release size: 20.0 kB

Release files / gpt_batch_manager-1.0.1.tar.gz

Download URL gpt_batch_manager-1.0.1.tar.gz
Size 9.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e3dd418432e1ad9410fac6644039a09cea83f342c6b1a58bbf3bce5c2b457556
BLAKE2b-256 checksum
How to use checksums
96f5fa0a5c581f0dc1418550224245c3cf1d07117e5c3630c37792c148b7f113
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.9 Darwin/23.6.0

Release files / gpt_batch_manager-1.0.1-py3-none-any.whl

Download URL gpt_batch_manager-1.0.1-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ad09eb7900ccdab2c64387ef099ec1ddb4a5756d04eb9843a65bb5449c38f5c
BLAKE2b-256 checksum
How to use checksums
bda9ce24dab897fbea35817179701a82d3fc77479f0779814780ed4f830eef26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.11.9 Darwin/23.6.0

Security for gpt-batch-manager 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page