English | 日本語
One Swift interface for Anthropic Claude, OpenAI GPT, Google Gemini, and five more LLM providers.
- Eight providers, one shape — Anthropic, OpenAI, Gemini, DeepSeek, xAI, Groq, Mistral, and OpenRouter behind a common protocol
- Typed model selection — a Claude model will not compile against an OpenAI client
- Structured output — annotate a type with
@Structuredand get it back decoded; the JSON Schema is generated and adapted to each provider's accepted subset - Tool calling — supported on every provider, with the per-vendor id and argument-encoding differences absorbed
- Token-by-token streaming — on all eight, over each vendor's own streaming endpoint
- Retry that reads the response — a server-supplied rate-limit wait beats computed backoff
import LLMCloudAnthropic
let client = AnthropicClient(apiKey: "sk-ant-...")
@Structured("Product info")
struct Product {
@StructuredField("Product name")
var name: String
@StructuredField("Price in USD", .minimum(0))
var price: Double
}
let result: Product = try await client.generate(
input: "The iPhone 16 Pro costs $999 and is a smartphone.",
model: .sonnet
)
print(result.name) // "iPhone 16 Pro"
print(result.price) // 999.0Switching providers is an import and a client:
import LLMCloudOpenAI
let openai = OpenAIClient(apiKey: "sk-...")
let a: Product = try await openai.generate(input: prompt, model: .gpt4o)
import LLMCloudGemini
let gemini = GeminiClient(apiKey: "AIza...")
let b: Product = try await gemini.generate(input: prompt, model: .flash25)- API reference — every public symbol, per module
- Module architecture — how the package is split and which module to import
// Package.swift
dependencies: [
.package(url: "https://github.com/no-problem-dev/swift-llm-cloud.git", from: "6.0.0")
]Then depend on the provider you use, not the umbrella:
.target(name: "MyApp", dependencies: [
.product(name: "LLMCloudAnthropic", package: "swift-llm-cloud"),
])- iOS 17.0+ / macOS 14.0+
- Swift 6.2+
- Xcode 16.0+
MIT License — See LICENSE for details