English | 日本語
One Swift API for Claude, GPT, Gemini, Grok, Groq, Mistral and DeepSeek, so changing model or provider never means rewriting the code that calls it.
- Provider agnostic — swap providers without touching call-site code
- Structured output — decode straight into your own type via the
@Structuredmacro and JSON Schema - Tool calling — declare tools with the
@Toolmacro; arguments stay type-safe on both sides - Streaming — text, reasoning and tool-argument deltas over
AsyncThrowingStream - Token accounting — usage, prompt-cache tiers, cost and live context-window occupancy
Describe the shape you want, and get it back decoded:
import LLMClient
@Structured("City information")
struct CityInfo {
@StructuredField("City name")
var name: String
@StructuredField("Population, in units of ten thousand")
var population: Int
}
let city: CityInfo = try await client.generate(
input: "Tokyo has a population of roughly 14 million.",
model: .claude(.sonnet)
)
print(city.name) // "Tokyo"
print(city.population) // 1400Declare a tool the same way, and let the model call it:
import LLMTool
@Tool("Get the current weather for a city")
struct GetWeather {
@ToolArgument("City name")
var city: String
func call() async throws -> String {
"\(city): sunny, 25°C"
}
}
let plan = try await client.planToolCalls(
prompt: "Compare the weather in Tokyo and Osaka.",
model: .claude(.sonnet),
tools: ToolSet { GetWeather() }
)client is any type conforming to StructuredLLMClient / ToolCallableClient; provider
implementations live in separate packages.
The full API reference and guides are hosted at no-problem-dev.github.io/swift-llm-client. Start with Getting Started, and read Module Layout to decide which of the nine libraries to import.
// Package.swift
dependencies: [
.package(url: "https://github.com/no-problem-dev/swift-llm-client.git", from: "5.0.0")
]Then add the libraries you need — LLMClient and LLMTool cover most uses:
.target(
name: "MyApp",
dependencies: [
.product(name: "LLMClient", package: "swift-llm-client"),
.product(name: "LLMTool", package: "swift-llm-client"),
]
)- iOS 17.0+ / macOS 14.0+
- Swift 6.2+
- Xcode 16.0+
MIT License — see LICENSE.