SwiftyAISwiftyAI

Search documentation

Find a docs page by title or section

1

Provider Registry

ProviderRegistry is a local resolver for custom model strings. It is separate from AI.configure, so it works well in tests, previews, multi-tenant apps, and libraries that should not touch shared global state.

Registry APIResolves
model / languageModelAIModel for full text generation
streamModelAIStreamModel for streaming
toolCallingModelAIToolCallingModel for tool loops
imageModelAIImageModel for images
transcriptionModelAITranscriptionModel for audio transcription
speechModelAISpeechModel for speech output
videoModelAIVideoModel for video generation

Register Models By Capability

let registry = createProviderRegistry([
    "demo": customProvider(
        languageModels: [
            "summary": summaryModel
        ],
        streamModels: [
            "chat": chatModel
        ],
        toolCallingModels: [
            "agent": agentModel
        ],
        imageModels: [
            "image": imageModel
        ],
        transcriptionModels: [
            "transcribe": transcriptionModel
        ],
        speechModels: [
            "speech": speechModel
        ],
        videoModels: [
            "video": videoModel
        ]
    )
])

The provider id is the part before the slash. The model id is the part after it.

Use Registry Helpers

let response = try await generateText(
    model: "demo/summary",
    registry: registry,
    prompt: "Summarize this support ticket."
)

Streaming and tool helpers follow the same pattern:

for try await chunk in streamText(
    model: "demo/chat",
    registry: registry,
    prompt: "Write a typing indicator message."
) {
    print(chunk.text, terminator: "")
}
let result = try await generateWithTools(
    model: "demo/agent",
    registry: registry,
    prompt: "Look up the order and explain the status.",
    tools: [lookupOrderTool]
)

Media APIs accept the same registry: form:

let image = try await generateImage(
    model: "demo/image",
    registry: registry,
    prompt: "A clean SwiftyAI app icon."
)
 
let transcript = try await transcribe(
    model: "demo/transcribe",
    registry: registry,
    audio: audio
)
 
let speech = try await generateSpeech(
    model: "demo/speech",
    registry: registry,
    text: "Your export is ready."
)
 
let video = try await generateVideo(
    model: "demo/video",
    registry: registry,
    prompt: "A short product walkthrough."
)

streamWithTools(model:registry:…) is also available with the same signature.

Resolve Manually

Manual resolution is useful when you need to pass a model into another object.

let streamModel = try registry.streamModel("demo/chat")
let chat = AIChat(model: streamModel, systemPrompt: "Be brief.")

Resolution methods are capability-specific: model, languageModel, streamModel, toolCallingModel, imageModel, transcriptionModel, speechModel, and videoModel.

Error Behavior

The registry validates model strings and capabilities. "demo" is invalid because it has no slash. "missing/chat" throws provider-not-configured. "demo/image" throws unsupported-feature if you ask for it as a stream model.

FailureMeaning
Invalid model stringThe string is not shaped like "provider/model"
Provider not configuredThe provider prefix is not present in this registry
Unsupported featureThe provider exists, but the requested model is not registered for that capability
Related docs

Use custom providers to build models and provider setup for built-in provider configuration.