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 API | Resolves |
|---|---|
model / languageModel | AIModel for full text generation |
streamModel | AIStreamModel for streaming |
toolCallingModel | AIToolCallingModel for tool loops |
imageModel | AIImageModel for images |
transcriptionModel | AITranscriptionModel for audio transcription |
speechModel | AISpeechModel for speech output |
videoModel | AIVideoModel 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.
| Failure | Meaning |
|---|---|
| Invalid model string | The string is not shaped like "provider/model" |
| Provider not configured | The provider prefix is not present in this registry |
| Unsupported feature | The provider exists, but the requested model is not registered for that capability |