Add Batch API support
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
Research direction
Start by reviewing the Batch API design and prior work listed in the issue, especially PR #401 and commits 7d33a55, 1f40dc4, and d88dfc8. Then inspect openapi-generator-config.yaml and the existing Files and Responses endpoint patterns. Done means implementing the specified Batch endpoints, JSONL helpers, tests, README and CHANGELOG updates, and building the Demo app.
Written by the indexing model from the issue text.
Description
Add the Batch API. #401 started as a Batch API PR and is being turned into a Files API PR, so Batch builds on the openAI.files namespace introduced there. In particular, files.content(id:) is how batch output and error files are downloaded.
Depends on #401.
Design decided while reviewing #401
Namespace
openAI.batches: BatchesEndpointProtocolwithcreate(query:),retrieve(id:),list(query: ListBatchesQuery)plus alist()overload, andcancel(id:).- Each method comes in completion-handler (
@discardableResult), async and Combine flavours, in the same four-protocol layout asResponsesEndpoint. - Names follow the official Java and Python SDKs (
client.batches.create/retrieve/list/cancel).
Types
- Use the generated
Components.Schemas.Batch,CreateBatchRequestandListBatchesResponsedirectly, with no top-level typealiases. Adding a typealias later is additive; removing one would be a break. - Generate them by adding
/batches,/batches/{batch_id}and/batches/{batch_id}/canceltoopenapi-generator-config.yaml. - The closed generated enums, such as
Batch.StatusPayload, are accepted for now; #464 tracks reconsidering that. - Add public static aliases on the generated enums so callers don't have to write
._sol_v1ChatCompletionsor._24h:.chatCompletions,.responses, and so on for all 8 endpoints, plus.twentyFourHours.
JSONL line types
The spec has no schema for these, so they're hand-written.
- Request line: generic over an
Encodablebody, so it isn't tied toChatQuery. - Response line: exposes the body as JSON with a typed
decodeBody(as:)helper, so embeddings, Responses and the other endpoints work without new types. - Decoding: use the project's response decoder with
configuration.parsingOptions, not a bareJSONDecoder, so.relaxedkeeps working.
Convenience helpers
Add submit (JSONL encode, upload, create) and wait (poll, then download) in an extension with a default implementation, not as protocol requirements. Decide where submit lives, since it needs both files and batches.
Problems in the original implementation to fix:
waitmust also downloaderror_file_id, because failed requests aren't in the output file.- Don't discard partial output from cancelled or expired batches.
- Name the client-side polling error so it doesn't clash in meaning with the spec's per-request
BatchError. - The timeout check shouldn't overshoot by a whole polling interval.
Tests
Integration tests (skipped without OPENAI_API_KEY) must not silently pass on timeout.
Prior work
The PR branch's history has a full implementation of the above, removed again when the branch was narrowed to Files:
7d33a55: generator config and generated Batch schemas1f40dc4: thebatchesendpoint, protocols,ListBatchesQueryand unit testsd88dfc8: the original author's JSONL types, convenience methods, README text and integration tests
Finishing
- The API breakage check should report one break:
var OpenAIProtocol.batches has been added as a protocol requirement. Add it to the allowlist and describe it in the CHANGELOG. - Add a README section and build the Demo app.
- Dominant language
- Swift
- Stars
- 2.9k
- Forks
- 519
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 13
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MacPaw/OpenAI
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
Enable batch promptsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MacPaw/OpenAI#73 · 1 comment · 1 reaction ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
Maintainers usually reply within 3 days
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 3 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
capawesome-team/capacitor-plugins#1134 ·
Maintainers usually reply within 1 day
-
enhancement help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
kabirvashisht4-glitch/Vet#22 ·
-
Custom sidebars in the right sidebar get an empty groups listPossibly taken A pull request linked to this issue is open or already merged. Openarea: sidebar bug S2: major
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
manaflow-ai/cmux#20281 · 1 comment ·
Maintainers usually reply within 1 day
-
If a snippet replacement starts with a newline, it truncates the first parts of the replacement.Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
margelo/react-native-vision-camera#4216 ·
Maintainers usually reply within 4 days