← all repositories
adamrushy/OpenAISwift

Swift wrapper for OpenAI: typed, async, and mostly complete

A community-maintained Swift library that wraps the OpenAI HTTP API with async/await and completion-handler variants for iOS and macOS developers.

OpenAISwift
Velocity · 7d
+1.3
★ / day
Trend
steady
star history

What it does OpenAISwift is a thin, community-maintained wrapper around OpenAI’s HTTP API. It covers completions, chat (GPT-3.5/GPT-4), DALL·E image generation, edits, moderation, and embeddings. You initialize it with an API key, then call typed methods like sendCompletion or sendChat that return either Result objects or throw via async/await.

The interesting bit The library doesn’t try to be clever — it’s essentially a typed HTTP client — but it does expose every optional API parameter (temperature, top-p, logit bias, etc.) without forcing you to hand-craft JSON. The dual async/await and completion-handler support is a nice concession to Swift’s transitional concurrency landscape.

Key highlights

  • Supports SPM, CocoaPods, or manual file copying
  • Covers six OpenAI endpoints: completions, chat, images, edits, moderation, embeddings
  • Model types are enum-driven (OpenAIModelType.gpt3(.davinci), .chat(.chatgpt), etc.)
  • Chat API supports full conversation threading with ChatMessage arrays
  • MIT licensed; author notes it was “created mainly for fun”

Caveats

  • Streaming message content is explicitly not supported for the chat endpoint
  • The README links to beta.openai.com/docs, which is outdated branding; unclear if the library itself tracks the latest API versions
  • No mention of rate-limit handling, retries, or request cancellation

Verdict Handy if you’re building a Swift app and want typed OpenAI calls without pulling in a heavy networking framework. Skip it if you need streaming responses or sophisticated error handling beyond basic Result types.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.