Swift SDK for xAI's Powerful Language Models
Built with Swift's latest features including async/await, structured concurrency, and type-safe APIs for the best developer experience.
Support for streaming responses enables you to build interactive experiences with real-time AI feedback.
Leverage Swift's powerful type system to catch errors at compile time and write more reliable code.
Works seamlessly across all Apple platforms - iOS, macOS, tvOS, watchOS, and visionOS.
Access xAI's advanced Grok models with their powerful reasoning and conversation capabilities.
Comprehensive documentation and interactive tutorials help you get started quickly and efficiently.
iOS 16+ • macOS 13+ • tvOS 16+ • watchOS 9+ • visionOS 1+ • Linux
import xAIKit
// Initialize the client
let client = xAIClient(apiKey: "your-api-key")
// Create a chat completion
let response = try await client.chat.completions(
messages: [
ChatMessage(role: .user, content: "Explain quantum computing")
],
model: "grok-3-mini-fast-latest"
)
// Print the response
print(response.choices.first?.message.content ?? "")