Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add Batch API support

Aperta
#465 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift
Ambito
api

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Swift
Stelle
2.9k
Fork
519
Merge medio
4g 9h
PR unite (30g)
13

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MacPaw/OpenAI

Tutte le issue di MacPaw/OpenAI

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.