A comprehensive Swift SDK for the OpenAI API.
Visit https://guitaripod.github.io/OpenAIKit/ for complete documentation and tutorials.
- 🚀 Type-safe API with Swift's powerful type system
- 🌍 Cross-platform support (iOS 15+, macOS 12+, watchOS 8+, tvOS 15+, visionOS, Linux)
- 📚 Complete API coverage (Chat, Images, Audio, Embeddings, and more)
- ⚡ Modern async/await with streaming support
- 🛡️ Comprehensive error handling
- 📖 Full DocC documentation with interactive tutorials
- ✅ Production-ready with 100% test coverage
- Chat Completions - Text generation with streaming support
- Function Calling - Tool use and multi-function support
- Embeddings - Text vectorization with dimension control
- Audio - Speech-to-text and text-to-speech
- Images - DALL-E 2/3 and GPT Image 1
- Moderation - Content safety checking
- Models - List and retrieve model information
- Files - Upload, download, list, and delete
- Streaming - Real-time responses with usage tracking
- Batch API - Async processing with 50% cost savings
- Error Handling - Comprehensive UI-friendly errors
- DeepResearch - Advanced research with web search, MCP tools, and code interpretation (models:
o3-deep-research,o4-mini-deep-research)
- Assistants API - Beta feature
- Threads API - Part of Assistants (beta)
- Vector Stores - Part of Assistants (beta)
- Fine-tuning - Not implemented
Add OpenAIKit to your Package.swift:
dependencies: [
.package(url: "https://github.com/guitaripod/OpenAIKit.git", from: "1.0.0")
]import OpenAIKit
let openAI = OpenAIKit(configuration: .init(apiKey: "your-api-key"))
let response = try await openAI.chat.completions(
.init(
model: .gpt4o,
messages: [.user("Hello, world\!")]
)
)
print(response.choices.first?.message.content ?? "")run swift run OpenAIKitTester <test>