A Swift package for calling OpenAI's public API across Apple platforms and Linux, with support for many OpenAI-compatible providers.
MacPaw/OpenAI
Community-maintained Swift package wrapping the OpenAI public API, covering chat, responses, images, audio, embeddings and assistants.
- Stars
- 2,961
- Forks
- 517
- Open issues
- 50
- Last commit
- 3 days ago
What is it?
This is a Swift client library for the OpenAI REST API, installable through Swift Package Manager. It provides typed request and response models for endpoints including Responses, Chat Completions, image generation and editing, speech synthesis and transcription, embeddings, moderations, files, models and the Assistants beta.
Requests can be made with async/await, closure callbacks or Combine, and in-flight calls can be cancelled through the task, the returned cancellable request, or the Combine subscription. Streaming is supported for chat and speech output. The library also includes support for MCP (Model Context Protocol) tools and structured outputs defined either by hand, from a Swift type, or as a dictionary schema.
The package can also be pointed at other providers that expose an OpenAI-compatible API, using a relaxed parsing option in the configuration. The README notes that API keys should stay on a backend server rather than in client-side apps.
Key features
- 01Typed models for Responses, Chat Completions, images, audio, embeddings and moderations.
- 02Async/await, closure and Combine call styles with request cancellation.
- 03Streaming for chat completions and speech generation.
- 04Structured outputs from hand-written, Swift-derived or dictionary JSON schemas.
- 05MCP tool integration for Chat Completions requests.
- 06Configurable host, timeout, organization ID and custom headers.
Use cases
- Adding OpenAI chat or image generation to an iOS or macOS app through a backend proxy.
- Building a Swift server-side tool that transcribes audio or generates speech via the API.
- Calling OpenAI-compatible providers from Swift code using the same client interface.
- Extracting structured JSON from text using typed Swift schemas.
In collections
Topics
FAQ
- What is OpenAI?
- Community-maintained Swift package wrapping the OpenAI public API, covering chat, responses, images, audio, embeddings and assistants. This is a Swift client library for the OpenAI REST API, installable through Swift Package Manager. It provides typed request and response models for endpoints including Responses, Chat Completions, image generation and editing, speech synthesis and transcription, embeddings, moderations, files, models and the Assistants beta.
- Is OpenAI free to use? What license does it have?
- OpenAI is open source under the MIT license. Check the license terms before using it in commercial products.
- Is OpenAI still maintained?
- Actively maintained. The last commit to OpenAI was on Nov 5, 2026.
- What can I use OpenAI for?
- Adding OpenAI chat or image generation to an iOS or macOS app through a backend proxy. Building a Swift server-side tool that transcribes audio or generates speech via the API. Calling OpenAI-compatible providers from Swift code using the same client interface. Extracting structured JSON from text using typed Swift schemas.
- Where can I get OpenAI?
- The source code and installation instructions are on GitHub: https://github.com/MacPaw/OpenAI
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A community-maintained PHP client for the OpenAI REST API, with streaming support and no third-party runtime dependencies.
Unofficial Dart and Flutter SDK for the OpenAI API, with typed clients for Responses, Chat, Realtime, Batch and more.
Official TypeScript SDK for calling Anthropic's Claude API from server-side JavaScript and TypeScript applications.
A Python library giving one interface for chat, streaming, tool calls, and structured output across AI providers.
The official Python library for the OpenAI REST API, with sync and async clients and typed request and response models.