Skip to content

Repository files navigation

English | 日本語

LLMCloud

One Swift interface for Anthropic Claude, OpenAI GPT, Google Gemini, and five more LLM providers.

Swift Platforms License

Features

  • 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 @Structured and 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

Quick Start

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.0

Switching 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)

Documentation

Installation

// 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"),
])

Requirements

  • iOS 17.0+ / macOS 14.0+
  • Swift 6.2+
  • Xcode 16.0+

License

MIT License — See LICENSE for details

About

Multi-provider LLM cloud client for Anthropic Claude, OpenAI, and Google Gemini — unified streaming, tool calling, and structured output

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages