Discover models and register providers
Use model discovery to find IDs available to your credentials. Use the registry when application configuration determines which provider to instantiate.
List available models
Providers that expose model-listing APIs (OpenAI, Anthropic, Google GenAI, Ollama, and Google Antigravity) implement llm.ModelLister:
if ml, ok := provider.(llm.ModelLister); ok { // Query all models available to your credentials or local server models, err := ml.ListModels(ctx) if err == nil { for _, m := range models { fmt.Printf("• %s (%s) — ctx=%d\n", m.ID, m.Name, m.Limits.Context) } }
// Fetch live metadata for a single model by ID prof, err := ml.GetModel(ctx, "claude-sonnet-4-6") _ = prof _ = err}- Static-catalog providers (
openai,anthropic,genai): Enrich live API results with static catalog metadata (preservingPricing,TieredLimits,Modalities, andCapabilities) without mutatingprovider.ListProfiles(). Unknown models (such as fine-tunesft:..., tuned Gemini models, or OpenAI-compatible vLLM/LiteLLM servers) receive synthesized profiles from live API metadata. - Dynamic-catalog providers (
ollama,antigravity): Refresh their in-memory discovered model cache while preserving any explicitprovider.OverrideProfile(...)entries.
Register a provider factory
The Registry is useful for decoupling your application from specific provider packages. It allows you to register provider factories and retrieve them by name.
registry := llm.NewRegistry()registry.Register("openai", func() (llm.Provider, error) { return loomopenai.NewDefaultProvider()})provider, err := registry.Get("openai")if err != nil { return err}model, err := llm.NewModel(provider, modelID, nil)if err != nil { return err}Check supported inputs and capabilities
All built-in providers (openai, anthropic, genai, ollama, copilot, claudecode, antigravity, and typesafe) enforce strict validation across llm, embedding, and decision requests so unsupported attachments are never silently dropped:
- Profile & Capability Gate (When Known): When
provider.GetProfile(model)resolves an authoritativeprofile.Profile, Loom validates message/input modalities againstModalities.Inputsand tool definitions againstCapabilities.ToolCall(as well asCompletion,Embedding, orDecisionworkload flags). Unknown or custom model IDs with no catalog profile skip this step automatically. - Wire-Protocol Gate (Always Enforced): Every provider’s message mapper validates
System,User,Assistant,Tool,embedding.Input, anddecision.Inputblocks—rejecting unsupported block types, unsupported roles (e.g., images insideSystemprompts), empty media blocks, or unsupported delivery modes (e.g., URL-only audio where inline bytes are required). Historical*message.ThinkingBlockitems remain lenient on replay.
import ( "errors"
"github.com/masterkeysrd/loom/profile")
resp, err := model.Invoke(ctx, messages)if errors.Is(err, profile.ErrUnsupportedModality) { // Handle unsupported image/audio/video/document modality or URL source}if errors.Is(err, profile.ErrUnsupportedCapability) { // Handle unsupported capability (e.g., tools bound to a non-tool model)}