router

package
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrProviderNotFound is returned when a referenced provider is not found.
	ErrProviderNotFound = errors.New("provider not found")
	// ErrAmbiguousModel is returned when a short model ID matches multiple providers.
	ErrAmbiguousModel = errors.New("ambiguous model ID")

	// ErrUnknownModel and ErrNoProviders are re-exported from the llm package
	// for backwards compatibility with callers that import from this package.
	ErrUnknownModel = llm.ErrUnknownModel
	ErrNoProviders  = llm.ErrNoProviders
)

Functions

This section is empty.

Types

type AliasTarget

type AliasTarget struct {
	Provider string // Provider instance name
	Model    string // Model ID or local alias for that provider
}

AliasTarget points to a provider instance and model.

type Config

type Config struct {
	Name      string                   // Router provider name (defaults to "router")
	Providers []ProviderInstanceConfig // Named provider instances
	Aliases   map[string][]AliasTarget // Global alias -> ordered targets
}

Config is the complete aggregate configuration.

type Factory

type Factory func(opts ...llm.Option) llm.Provider

Factory creates a provider instance from options.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider is an aggregate provider that routes requests to configured providers.

func New

func New(cfg Config, factories map[string]Factory) (*Provider, error)

New creates an aggregate provider from configuration. factories maps provider type keys to constructor functions.

func (*Provider) CountTokens added in v0.24.0

CountTokens implements llm.TokenCounter by delegating to the first resolved target provider for the given model alias or ToolCallID.

The model alias is resolved using the same alias map as CreateStream, and the underlying provider's native model ToolCallID is used for encoding selection. If the resolved provider does not implement llm.TokenCounter, an error is returned.

func (*Provider) CreateStream

func (p *Provider) CreateStream(ctx context.Context, src llm.Buildable) (llm.Stream, error)

CreateStream creates a stream by routing to the appropriate provider. It tries each target in order until one succeeds or all fail.

func (*Provider) Models

func (p *Provider) Models() llm.Models

func (*Provider) Name

func (p *Provider) Name() string

func (*Provider) Resolve

func (p *Provider) Resolve(modelID string) (llm.Model, error)

Resolve implements llm.Resolver.

type ProviderInstanceConfig

type ProviderInstanceConfig struct {
	Name         string            // Unique instance name
	Type         string            // Provider type key (passed to factory)
	Options      []llm.Option      // Options passed to factory
	ModelAliases map[string]string // Local aliases: "sonnet" -> "claude-sonnet-4-5"
}

ProviderInstanceConfig configures a single provider instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL