jamesrochabrun/SwiftOpenAI

The most complete open-source Swift package for interacting with OpenAI's public API.

What it solves

SwiftOpenAI provides a streamlined, open-source Swift package for developers to integrate OpenAI's public API into their applications. It removes the need to write manual network requests and data parsing for a wide array of OpenAI services, supporting Apple platforms (iOS, macOS, watchOS) and Linux.

How it works

The package acts as a wrapper around OpenAI's API endpoints. It uses OpenAIServiceFactory to initialize a service with an API key and provides structured parameters and response objects for various modalities. It supports standard HTTP requests via URLSession (or AsyncHTTPClient on Linux) and WebSockets for low-latency, bidirectional voice conversations via the Realtime API.

Who it’s for

Swift developers building AI-powered apps for Apple devices or Linux servers who want a type-safe, easy-to-install library to access LLMs, image generation, and audio processing.

Highlights

  • Comprehensive Endpoint Support: Covers Chat (including Vision and Structured Outputs), Audio (Transcriptions, Translations, Speech), Embeddings, Fine-tuning, Batch, Files, Images, and Moderations.
  • ** uma Broad Compatibility**: Works with OpenAI and other OpenAI-compatible providers like Azure, Anthropic, Gemini, Ollama, Groq, xAI, OpenRouter, and DeepSeek.
  • Realtime API Integration: Supports low-latency bidirectional voice conversations with audio-to-audio interaction and voice activity detection.
  • Assistant Beta Support: Includes integration for Assistants, Threads, Messages, Runs, and Vector Stores.
  • Cross-Platform: Compatible with iOS 15+, macOS 13+, watchOS 9+, and Linux (Vapor compatible).

Related

  • Project
  • Project
  • Dispatch
  • Project
  • Project