Project

swift-ai

maintenance

SwiftPM port of Pi's AI API — typed streaming, tools and model registries; development paused at v1.0.1.

Overview

swift-ai brings the @earendil-works/pi-ai API to Swift applications without requiring the TypeScript runtime. It provides typed streaming, tool calls, OAuth helpers and registries for chat, image and classifier models.

Development has stopped. The main branch retains the published v1.0.1 package, following pi-ai v1.0.1. Unfinished v1.1.0 work is preserved on the release branch; pin v1.0.1 for the released package.

How it works

SwiftAI.bootstrap() registers models and providers in actor-backed registries. Requests resolve a model, credentials and provider implementation, then use the asynchronous stream or complete API.

Provider clients translate wire responses into typed events using Swift value types, Codable and AsyncStream. Shared helpers handle SSE parsing, tool-argument validation, retries and prompt-cache metadata. A model's presence in the catalogue does not mean every transport is bundled.

Features
→
Typed Swift API

Common chat, image, classifier, message, tool, usage and diagnostic types, with actor-backed registries.

→
Streaming providers

OpenAI Chat Completions and Responses, Azure Responses, Codex SSE, Anthropic, Gemini/Vertex, Gemini CLI, Mistral and Pi Messages implementations.

→
Tools and reasoning

Streamed tool arguments, JSON Schema validation, reasoning events, prompt-cache helpers and context-overflow handling.

→
Images and catalogues

OpenRouter image generation and generated chat, image and classifier registries from the pinned upstream release.

→
OAuth and request hooks

Provider-specific sign-in, retry/backoff helpers, diagnostics and request/response interception.

→
Frozen release

The SwiftPM package is released at v1.0.1. The paused v1.1.0 branch has unfinished, unverified changes and is not a completed upgrade.

Architecture
Swift application stream · complete · tools SwiftAI registry actor-backed models + providers Request resolver model · credentials · options Provider transport HTTP · SSE · pluggable Typed event stream text · reasoning · tools · usage Provider-neutral LLM streaming API for Swift
Posts