Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Add Batch API support

Open
#465 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
swift
Domain
api

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: BatchesEndpointProtocol with create(query:), retrieve(id:), list(query: ListBatchesQuery) plus a list() overload, and cancel(id:).
  • Each method comes in completion-handler (@discardableResult), async and Combine flavours, in the same four-protocol layout as ResponsesEndpoint.
  • Names follow the official Java and Python SDKs (client.batches.create/retrieve/list/cancel).
Types
  • Use the generated Components.Schemas.Batch, CreateBatchRequest and ListBatchesResponse directly, 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}/cancel to openapi-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_v1ChatCompletions or ._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 Encodable body, so it isn't tied to ChatQuery.
  • 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 bare JSONDecoder, so .relaxed keeps 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:

  • wait must also download error_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 schemas
  • 1f40dc4: the batches endpoint, protocols, ListBatchesQuery and unit tests
  • d88dfc8: 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from MacPaw/OpenAI

All issues in MacPaw/OpenAI

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.