steadybatch 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. steadybatch-0.2.1/.gitignore +12 -0
  2. steadybatch-0.2.1/CITATION.cff +28 -0
  3. steadybatch-0.2.1/LICENSE +202 -0
  4. steadybatch-0.2.1/PKG-INFO +198 -0
  5. steadybatch-0.2.1/README.md +158 -0
  6. steadybatch-0.2.1/docs/FINDINGS.md +209 -0
  7. steadybatch-0.2.1/docs/GUIDE.md +86 -0
  8. steadybatch-0.2.1/docs/ROADMAP.md +15 -0
  9. steadybatch-0.2.1/examples/make_synthetic.py +63 -0
  10. steadybatch-0.2.1/examples/prices.example.json +9 -0
  11. steadybatch-0.2.1/examples/support_ticket.instructions.txt +6 -0
  12. steadybatch-0.2.1/examples/support_ticket.schema.json +14 -0
  13. steadybatch-0.2.1/k8s/job.yaml +46 -0
  14. steadybatch-0.2.1/pyproject.toml +55 -0
  15. steadybatch-0.2.1/src/steadybatch/__init__.py +7 -0
  16. steadybatch-0.2.1/src/steadybatch/bench.py +317 -0
  17. steadybatch-0.2.1/src/steadybatch/chunking.py +39 -0
  18. steadybatch-0.2.1/src/steadybatch/ids.py +32 -0
  19. steadybatch-0.2.1/src/steadybatch/models.py +85 -0
  20. steadybatch-0.2.1/src/steadybatch/providers/__init__.py +35 -0
  21. steadybatch-0.2.1/src/steadybatch/providers/anthropic_batch.py +95 -0
  22. steadybatch-0.2.1/src/steadybatch/providers/base.py +60 -0
  23. steadybatch-0.2.1/src/steadybatch/providers/fake.py +104 -0
  24. steadybatch-0.2.1/src/steadybatch/providers/gemini_batch.py +126 -0
  25. steadybatch-0.2.1/src/steadybatch/providers/openai_batch.py +127 -0
  26. steadybatch-0.2.1/src/steadybatch/providers/vllm_offline.py +86 -0
  27. steadybatch-0.2.1/src/steadybatch/runner.py +216 -0
  28. steadybatch-0.2.1/src/steadybatch/store.py +193 -0
  29. steadybatch-0.2.1/src/steadybatch/validate.py +39 -0
  30. steadybatch-0.2.1/tests/test_bench.py +77 -0
  31. steadybatch-0.2.1/tests/test_capacity.py +119 -0
  32. steadybatch-0.2.1/tests/test_core.py +61 -0
  33. steadybatch-0.2.1/tests/test_providers.py +270 -0
  34. steadybatch-0.2.1/tests/test_runner.py +128 -0
@@ -0,0 +1,12 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ runs/
8
+ *.sqlite
9
+ .pytest_cache/
10
+ examples/support_tickets.jsonl
11
+ *.log
12
+ examples/support_tickets_*.jsonl
@@ -0,0 +1,28 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software or its benchmark results, please cite it as below."
3
+ title: "steadybatch: reliable batch LLM inference"
4
+ type: software
5
+ authors:
6
+ - family-names: Kotwal
7
+ given-names: Ankur Partap
8
+ orcid: "https://orcid.org/0009-0009-4790-6866"
9
+ repository-code: "https://github.com/kotwal-itpro/steadybatch"
10
+ doi: "10.5281/zenodo.23221956"
11
+ identifiers:
12
+ - type: doi
13
+ value: "10.5281/zenodo.23221956"
14
+ description: "All versions (concept DOI)"
15
+ - type: doi
16
+ value: "10.5281/zenodo.23231614"
17
+ description: "v0.2.0"
18
+ - type: doi
19
+ value: "10.5281/zenodo.23221957"
20
+ description: "v0.1.0"
21
+ license: Apache-2.0
22
+ version: 0.2.1
23
+ date-released: "2026-10-09"
24
+ keywords:
25
+ - large language models
26
+ - batch inference
27
+ - reliability
28
+ - benchmarking
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,198 @@
1
+ Metadata-Version: 2.5
2
+ Name: steadybatch
3
+ Version: 0.2.1
4
+ Summary: Run millions of LLM requests through batch APIs without silent failures.
5
+ Project-URL: Homepage, https://github.com/kotwal-itpro/steadybatch
6
+ Project-URL: Documentation, https://github.com/kotwal-itpro/steadybatch/blob/main/docs/GUIDE.md
7
+ Project-URL: Findings, https://github.com/kotwal-itpro/steadybatch/blob/main/docs/FINDINGS.md
8
+ Project-URL: Issues, https://github.com/kotwal-itpro/steadybatch/issues
9
+ Project-URL: DOI, https://doi.org/10.5281/zenodo.23221956
10
+ Author-email: Ankur Partap Kotwal <kotwal.itpro@gmail.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: anthropic,batch,benchmark,gemini,inference,llm,openai,reliability,vllm
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
+ Classifier: Topic :: System :: Distributed Computing
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: jsonschema>=4.0
27
+ Provides-Extra: anthropic
28
+ Requires-Dist: anthropic>=1.0; extra == 'anthropic'
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=8; extra == 'dev'
31
+ Provides-Extra: gemini
32
+ Requires-Dist: google-genai>=1.20; extra == 'gemini'
33
+ Provides-Extra: openai
34
+ Requires-Dist: openai>=1.40; extra == 'openai'
35
+ Provides-Extra: report
36
+ Requires-Dist: matplotlib>=3.7; extra == 'report'
37
+ Provides-Extra: vllm
38
+ Requires-Dist: vllm>=0.6; extra == 'vllm'
39
+ Description-Content-Type: text/markdown
40
+
41
+ # steadybatch
42
+
43
+ [![tests](https://github.com/kotwal-itpro/steadybatch/actions/workflows/tests.yml/badge.svg)](https://github.com/kotwal-itpro/steadybatch/actions/workflows/tests.yml)
44
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23221956.svg)](https://doi.org/10.5281/zenodo.23221956)
45
+
46
+ Run millions of LLM requests through batch APIs, and know that every one of them came back right.
47
+
48
+ Batch APIs are the cheapest way to run a model over a lot of data. You upload a file, wait a few hours, and pay about half the normal price. They also fail in quiet ways:
49
+
50
+ - A batch says "completed", but some of your lines never came back. No error, they're just gone.
51
+ - A line comes back, but it isn't the JSON you asked for, or it was cut off halfway.
52
+ - You re-run the same batch and get different answers.
53
+ - Your job crashes halfway through, and you can't tell what you already paid for.
54
+
55
+ If you're turning a million documents into structured data, each of those turns into a wrong number somewhere downstream. steadybatch handles them for you.
56
+
57
+ ## What it does
58
+
59
+ - **Checks off every request.** Each request gets a stable ID. When a batch finishes, steadybatch checks that every ID came back. Anything missing is marked and retried.
60
+ - **Checks every answer.** Each response is parsed and validated against your JSON Schema before it counts as done.
61
+ - **Retries one line, not the whole batch.** A bad line goes back on its own. Good lines are never paid for twice.
62
+ - **Survives restarts.** Progress is saved to a small SQLite file after every step. If the process dies, run it again: open batches are picked up, not resubmitted, and finished work is skipped.
63
+ - **Gives results back in your order.** Whatever order the provider returns things in, you get them back in the order you sent them.
64
+ - **Stays under provider limits.** Work is split so each batch stays under the provider's count and size caps.
65
+
66
+ It works with the OpenAI Batch API, Gemini API batch mode, the Anthropic Message Batches API, and self-hosted vLLM. AWS Bedrock is next (see [docs/ROADMAP.md](https://github.com/kotwal-itpro/steadybatch/blob/main/docs/ROADMAP.md)).
67
+
68
+ ## Quick start
69
+
70
+ Install from PyPI. Pick the providers you need in the brackets:
71
+
72
+ ```bash
73
+ pip install "steadybatch[openai,gemini,anthropic]"
74
+ # other extras: vllm (self-hosted), report (charts)
75
+ ```
76
+
77
+ ```python
78
+ from steadybatch import Request, Runner
79
+ from steadybatch.providers.openai_batch import OpenAIBatch
80
+
81
+ schema = {
82
+ "type": "object",
83
+ "properties": {"sentiment": {"type": "string", "enum": ["negative", "neutral", "positive"]}},
84
+ "required": ["sentiment"],
85
+ "additionalProperties": False,
86
+ }
87
+
88
+ requests = [
89
+ Request(key=row_id, messages=[{"role": "user", "content": f"Sentiment of: {text}"}])
90
+ for row_id, text in my_rows
91
+ ]
92
+
93
+ runner = Runner(OpenAIBatch(), "gpt-4.1-mini", response_schema=schema, checkpoint="job.sqlite")
94
+ report = runner.run(requests)
95
+
96
+ print(report.ok, "ok,", report.failed, "failed")
97
+ for r in report.results: # same order as `requests`
98
+ print(r.key, r.outcome.value, r.data)
99
+ ```
100
+
101
+ Run the same script again after a crash and it carries on from `job.sqlite`.
102
+
103
+ Before a big job, read [docs/GUIDE.md](https://github.com/kotwal-itpro/steadybatch/blob/main/docs/GUIDE.md): ten steps for running a batch job you can trust, each one learned from a real run.
104
+
105
+ ## The benchmark
106
+
107
+ This repo also holds the harness for an open study comparing batch APIs on cost, turnaround, failure modes and reproducibility. It uses one structured-extraction workload across providers.
108
+
109
+ ```bash
110
+ # make a synthetic dataset with known answers (no private data)
111
+ python examples/make_synthetic.py --n 1000 > examples/support_tickets.jsonl
112
+
113
+ # try the whole pipeline for free with the built-in fake provider
114
+ steadybatch-bench run --provider fake --model fake \
115
+ --data examples/support_tickets.jsonl --schema examples/support_ticket.schema.json \
116
+ --out runs/fake-1 --prices examples/prices.example.json --poll-every 0
117
+
118
+ # run it for real, twice, then compare the two runs
119
+ steadybatch-bench run --provider openai --model gpt-4.1-mini ... --out runs/openai-1
120
+ steadybatch-bench run --provider openai --model gpt-4.1-mini ... --out runs/openai-2
121
+ steadybatch-bench compare runs/openai-1 runs/openai-2
122
+ ```
123
+
124
+ Each run writes `results.jsonl` (one line per record, in input order) and `summary.json` with:
125
+ - success and failure counts, including lines that went missing, errored or failed the schema
126
+ - how many records needed a retry
127
+ - token use and cost
128
+ - batch turnaround times
129
+ - field-by-field accuracy against the known answers
130
+
131
+ `compare` reports how often two runs of the same workload agree, both exactly and field by field.
132
+
133
+ To turn any set of runs into one table, a CSV and charts:
134
+
135
+ ```bash
136
+ pip install matplotlib # optional, for the charts
137
+ steadybatch-bench report runs/openai-1 runs/gemini-1 --out results/latest
138
+ ```
139
+
140
+ Published results go in [results/](https://github.com/kotwal-itpro/steadybatch/blob/main/results/), one folder per run.
141
+
142
+ Useful `run` options for real jobs:
143
+ - `--instructions FILE` adds plain-language field definitions to the prompt (see finding 3 below for why this matters)
144
+ - `--batch-size N` and `--max-open-batches N` keep a big job under a provider's queue limit. If a provider still says its queue is full, the runner waits for its own batches or halves the batch size and retries, without using up any request's retries (finding 7)
145
+ - `--thinking disabled|adaptive` (Anthropic) sets thinking explicitly instead of using the model default
146
+
147
+ ### Results so far
148
+
149
+ 1,000 synthetic support tickets with known answers, the same schema and field definitions on every provider, batch prices taken on 2026-10-07. Full tables: [results/latest/summary.md](https://github.com/kotwal-itpro/steadybatch/blob/main/results/latest/summary.md).
150
+
151
+ | Model | Returned | Retries | Sentiment accuracy | Median batch time | Cost per 1,000 records |
152
+ |---|---|---|---|---|---|
153
+ | gpt-4.1-mini (OpenAI) | 1,000 / 1,000 | 0 | 92.9% | 4 min | $0.085 |
154
+ | gemini-3.5-flash-lite (Gemini) | 1,000 / 1,000 | 0 | 82.1% | 3 min | $0.088 |
155
+ | claude-haiku-5-5, default settings (Anthropic) | 999 / 1,000 | 10 | 89.1% | 10 min | $0.053 |
156
+ | claude-haiku-5-5, thinking disabled (Anthropic) | 1,000 / 1,000 | 0 | 91.0% | 5 min | $0.048 |
157
+ | Qwen2.5-7B-Instruct, self-hosted (vLLM, 1x L4) | 1,000 / 1,000 | 0 | 85.4% | 29 s | $0.004* |
158
+
159
+ \* GPU time for the run at $0.50/hour on demand. The whole rented-GPU session, including installing vLLM, downloading the model and one-time compilation, cost about $0.05. For vLLM the time is the whole run, since there is no queue.
160
+
161
+ All five got product and issue type 100% right. At 10,000 records, OpenAI and Gemini again returned every line with no retries. **At 100,000 records, all three hosted providers returned 100,000 of 100,000 with no retries**, at the same accuracy; what changed was turnaround (Gemini 45 minutes in 10 batches, Claude 2 h 44 min as one batch, OpenAI's batches slowing from 14 to 84 minutes through the day). Sending the same records again changed 0.7% of OpenAI's answers, 3% of Claude's and 6% of Gemini's (finding 10). What we learned along the way, including our own mistakes, is in [docs/FINDINGS.md](https://github.com/kotwal-itpro/steadybatch/blob/main/docs/FINDINGS.md). The short version:
162
+ - A model listed as available can still be refused when the batch is created.
163
+ - Undefined fields look like model errors: one plain sentence per field took follow-up accuracy from 31% to 98-100%.
164
+ - Models fail in different directions under the same instructions, and one setting (Claude's thinking) flipped the direction on the same model.
165
+ - A model that decides for itself when to think can use up the whole `max_tokens` budget and return nothing.
166
+ - A big job can be refused with a misleading "quota exceeded" error, and a dropped connection can stop an eight-hour run; the checkpoint resumed it without resending anything.
167
+ - Temperature 0 doesn't mean the same answer twice.
168
+
169
+ Write-up: [I Gave Two AI Models the Same Instructions. They Got It Wrong in Opposite Ways.](https://kotwal-itpro.github.io/2026/10/07/same-instructions-opposite-mistakes/)
170
+
171
+ Fill in `examples/prices.example.json` from each provider's pricing page on the day you run, and record the date with your results. Prices change.
172
+
173
+ ## Running on Kubernetes
174
+
175
+ A batch job fits well as a Kubernetes Job. Keep the checkpoint on a persistent volume so a rescheduled pod picks up where the last one stopped. See [k8s/job.yaml](https://github.com/kotwal-itpro/steadybatch/blob/main/k8s/job.yaml).
176
+
177
+ ## Testing
178
+
179
+ ```bash
180
+ git clone https://github.com/kotwal-itpro/steadybatch.git
181
+ cd steadybatch
182
+ pip install -e ".[dev]"
183
+ pytest
184
+ ```
185
+
186
+ The tests use a fake provider that drops lines, returns errors, sends malformed JSON and changes its answers between runs. You can check all the retry and recovery logic without an API key or a bill.
187
+
188
+ ## Status
189
+
190
+ Early, and moving. The core is tested against a fake provider that misbehaves on purpose. The OpenAI, Gemini and Anthropic adapters have run real jobs of 1,000 to 10,000 records against the live services (100,000 is in progress). The vLLM adapter has run on a rented NVIDIA L4. Issues and pull requests are welcome.
191
+
192
+ ## Citing
193
+
194
+ If you use steadybatch or the benchmark results in your work, please cite it: Kotwal, A. P. *steadybatch: reliable batch LLM inference*. Zenodo. https://doi.org/10.5281/zenodo.23221956 (see [CITATION.cff](https://github.com/kotwal-itpro/steadybatch/blob/main/CITATION.cff)).
195
+
196
+ ## License
197
+
198
+ Apache-2.0.
@@ -0,0 +1,158 @@
1
+ # steadybatch
2
+
3
+ [![tests](https://github.com/kotwal-itpro/steadybatch/actions/workflows/tests.yml/badge.svg)](https://github.com/kotwal-itpro/steadybatch/actions/workflows/tests.yml)
4
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23221956.svg)](https://doi.org/10.5281/zenodo.23221956)
5
+
6
+ Run millions of LLM requests through batch APIs, and know that every one of them came back right.
7
+
8
+ Batch APIs are the cheapest way to run a model over a lot of data. You upload a file, wait a few hours, and pay about half the normal price. They also fail in quiet ways:
9
+
10
+ - A batch says "completed", but some of your lines never came back. No error, they're just gone.
11
+ - A line comes back, but it isn't the JSON you asked for, or it was cut off halfway.
12
+ - You re-run the same batch and get different answers.
13
+ - Your job crashes halfway through, and you can't tell what you already paid for.
14
+
15
+ If you're turning a million documents into structured data, each of those turns into a wrong number somewhere downstream. steadybatch handles them for you.
16
+
17
+ ## What it does
18
+
19
+ - **Checks off every request.** Each request gets a stable ID. When a batch finishes, steadybatch checks that every ID came back. Anything missing is marked and retried.
20
+ - **Checks every answer.** Each response is parsed and validated against your JSON Schema before it counts as done.
21
+ - **Retries one line, not the whole batch.** A bad line goes back on its own. Good lines are never paid for twice.
22
+ - **Survives restarts.** Progress is saved to a small SQLite file after every step. If the process dies, run it again: open batches are picked up, not resubmitted, and finished work is skipped.
23
+ - **Gives results back in your order.** Whatever order the provider returns things in, you get them back in the order you sent them.
24
+ - **Stays under provider limits.** Work is split so each batch stays under the provider's count and size caps.
25
+
26
+ It works with the OpenAI Batch API, Gemini API batch mode, the Anthropic Message Batches API, and self-hosted vLLM. AWS Bedrock is next (see [docs/ROADMAP.md](https://github.com/kotwal-itpro/steadybatch/blob/main/docs/ROADMAP.md)).
27
+
28
+ ## Quick start
29
+
30
+ Install from PyPI. Pick the providers you need in the brackets:
31
+
32
+ ```bash
33
+ pip install "steadybatch[openai,gemini,anthropic]"
34
+ # other extras: vllm (self-hosted), report (charts)
35
+ ```
36
+
37
+ ```python
38
+ from steadybatch import Request, Runner
39
+ from steadybatch.providers.openai_batch import OpenAIBatch
40
+
41
+ schema = {
42
+ "type": "object",
43
+ "properties": {"sentiment": {"type": "string", "enum": ["negative", "neutral", "positive"]}},
44
+ "required": ["sentiment"],
45
+ "additionalProperties": False,
46
+ }
47
+
48
+ requests = [
49
+ Request(key=row_id, messages=[{"role": "user", "content": f"Sentiment of: {text}"}])
50
+ for row_id, text in my_rows
51
+ ]
52
+
53
+ runner = Runner(OpenAIBatch(), "gpt-4.1-mini", response_schema=schema, checkpoint="job.sqlite")
54
+ report = runner.run(requests)
55
+
56
+ print(report.ok, "ok,", report.failed, "failed")
57
+ for r in report.results: # same order as `requests`
58
+ print(r.key, r.outcome.value, r.data)
59
+ ```
60
+
61
+ Run the same script again after a crash and it carries on from `job.sqlite`.
62
+
63
+ Before a big job, read [docs/GUIDE.md](https://github.com/kotwal-itpro/steadybatch/blob/main/docs/GUIDE.md): ten steps for running a batch job you can trust, each one learned from a real run.
64
+
65
+ ## The benchmark
66
+
67
+ This repo also holds the harness for an open study comparing batch APIs on cost, turnaround, failure modes and reproducibility. It uses one structured-extraction workload across providers.
68
+
69
+ ```bash
70
+ # make a synthetic dataset with known answers (no private data)
71
+ python examples/make_synthetic.py --n 1000 > examples/support_tickets.jsonl
72
+
73
+ # try the whole pipeline for free with the built-in fake provider
74
+ steadybatch-bench run --provider fake --model fake \
75
+ --data examples/support_tickets.jsonl --schema examples/support_ticket.schema.json \
76
+ --out runs/fake-1 --prices examples/prices.example.json --poll-every 0
77
+
78
+ # run it for real, twice, then compare the two runs
79
+ steadybatch-bench run --provider openai --model gpt-4.1-mini ... --out runs/openai-1
80
+ steadybatch-bench run --provider openai --model gpt-4.1-mini ... --out runs/openai-2
81
+ steadybatch-bench compare runs/openai-1 runs/openai-2
82
+ ```
83
+
84
+ Each run writes `results.jsonl` (one line per record, in input order) and `summary.json` with:
85
+ - success and failure counts, including lines that went missing, errored or failed the schema
86
+ - how many records needed a retry
87
+ - token use and cost
88
+ - batch turnaround times
89
+ - field-by-field accuracy against the known answers
90
+
91
+ `compare` reports how often two runs of the same workload agree, both exactly and field by field.
92
+
93
+ To turn any set of runs into one table, a CSV and charts:
94
+
95
+ ```bash
96
+ pip install matplotlib # optional, for the charts
97
+ steadybatch-bench report runs/openai-1 runs/gemini-1 --out results/latest
98
+ ```
99
+
100
+ Published results go in [results/](https://github.com/kotwal-itpro/steadybatch/blob/main/results/), one folder per run.
101
+
102
+ Useful `run` options for real jobs:
103
+ - `--instructions FILE` adds plain-language field definitions to the prompt (see finding 3 below for why this matters)
104
+ - `--batch-size N` and `--max-open-batches N` keep a big job under a provider's queue limit. If a provider still says its queue is full, the runner waits for its own batches or halves the batch size and retries, without using up any request's retries (finding 7)
105
+ - `--thinking disabled|adaptive` (Anthropic) sets thinking explicitly instead of using the model default
106
+
107
+ ### Results so far
108
+
109
+ 1,000 synthetic support tickets with known answers, the same schema and field definitions on every provider, batch prices taken on 2026-10-07. Full tables: [results/latest/summary.md](https://github.com/kotwal-itpro/steadybatch/blob/main/results/latest/summary.md).
110
+
111
+ | Model | Returned | Retries | Sentiment accuracy | Median batch time | Cost per 1,000 records |
112
+ |---|---|---|---|---|---|
113
+ | gpt-4.1-mini (OpenAI) | 1,000 / 1,000 | 0 | 92.9% | 4 min | $0.085 |
114
+ | gemini-3.5-flash-lite (Gemini) | 1,000 / 1,000 | 0 | 82.1% | 3 min | $0.088 |
115
+ | claude-haiku-5-5, default settings (Anthropic) | 999 / 1,000 | 10 | 89.1% | 10 min | $0.053 |
116
+ | claude-haiku-5-5, thinking disabled (Anthropic) | 1,000 / 1,000 | 0 | 91.0% | 5 min | $0.048 |
117
+ | Qwen2.5-7B-Instruct, self-hosted (vLLM, 1x L4) | 1,000 / 1,000 | 0 | 85.4% | 29 s | $0.004* |
118
+
119
+ \* GPU time for the run at $0.50/hour on demand. The whole rented-GPU session, including installing vLLM, downloading the model and one-time compilation, cost about $0.05. For vLLM the time is the whole run, since there is no queue.
120
+
121
+ All five got product and issue type 100% right. At 10,000 records, OpenAI and Gemini again returned every line with no retries. **At 100,000 records, all three hosted providers returned 100,000 of 100,000 with no retries**, at the same accuracy; what changed was turnaround (Gemini 45 minutes in 10 batches, Claude 2 h 44 min as one batch, OpenAI's batches slowing from 14 to 84 minutes through the day). Sending the same records again changed 0.7% of OpenAI's answers, 3% of Claude's and 6% of Gemini's (finding 10). What we learned along the way, including our own mistakes, is in [docs/FINDINGS.md](https://github.com/kotwal-itpro/steadybatch/blob/main/docs/FINDINGS.md). The short version:
122
+ - A model listed as available can still be refused when the batch is created.
123
+ - Undefined fields look like model errors: one plain sentence per field took follow-up accuracy from 31% to 98-100%.
124
+ - Models fail in different directions under the same instructions, and one setting (Claude's thinking) flipped the direction on the same model.
125
+ - A model that decides for itself when to think can use up the whole `max_tokens` budget and return nothing.
126
+ - A big job can be refused with a misleading "quota exceeded" error, and a dropped connection can stop an eight-hour run; the checkpoint resumed it without resending anything.
127
+ - Temperature 0 doesn't mean the same answer twice.
128
+
129
+ Write-up: [I Gave Two AI Models the Same Instructions. They Got It Wrong in Opposite Ways.](https://kotwal-itpro.github.io/2026/10/07/same-instructions-opposite-mistakes/)
130
+
131
+ Fill in `examples/prices.example.json` from each provider's pricing page on the day you run, and record the date with your results. Prices change.
132
+
133
+ ## Running on Kubernetes
134
+
135
+ A batch job fits well as a Kubernetes Job. Keep the checkpoint on a persistent volume so a rescheduled pod picks up where the last one stopped. See [k8s/job.yaml](https://github.com/kotwal-itpro/steadybatch/blob/main/k8s/job.yaml).
136
+
137
+ ## Testing
138
+
139
+ ```bash
140
+ git clone https://github.com/kotwal-itpro/steadybatch.git
141
+ cd steadybatch
142
+ pip install -e ".[dev]"
143
+ pytest
144
+ ```
145
+
146
+ The tests use a fake provider that drops lines, returns errors, sends malformed JSON and changes its answers between runs. You can check all the retry and recovery logic without an API key or a bill.
147
+
148
+ ## Status
149
+
150
+ Early, and moving. The core is tested against a fake provider that misbehaves on purpose. The OpenAI, Gemini and Anthropic adapters have run real jobs of 1,000 to 10,000 records against the live services (100,000 is in progress). The vLLM adapter has run on a rented NVIDIA L4. Issues and pull requests are welcome.
151
+
152
+ ## Citing
153
+
154
+ If you use steadybatch or the benchmark results in your work, please cite it: Kotwal, A. P. *steadybatch: reliable batch LLM inference*. Zenodo. https://doi.org/10.5281/zenodo.23221956 (see [CITATION.cff](https://github.com/kotwal-itpro/steadybatch/blob/main/CITATION.cff)).
155
+
156
+ ## License
157
+
158
+ Apache-2.0.