provider

package
v1.139.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package provider defines the provider contracts and builds providers from explicit factory registries.

The package deliberately does not import concrete SDK-backed providers. Applications that need Docker Agent's built-in provider set should import pkg/model/provider/providers and use its NewDefaultRegistry. Embedders can instead build a smaller registry with NewRegistry. EmptyRegistry is available for components that support running without model providers.

Index

Constants

This section is empty.

Variables

View Source
var Aliases = map[string]Alias{
	"requesty": {
		APIType:     "openai",
		BaseURL:     "https://router.requesty.ai/v1",
		TokenEnvVar: "REQUESTY_API_KEY",
	},
	"azure": {
		APIType:     "openai",
		TokenEnvVar: "AZURE_API_KEY",
	},
	"xai": {
		APIType:     "openai",
		BaseURL:     "https://api.x.ai/v1",
		TokenEnvVar: "XAI_API_KEY",
	},
	"nebius": {
		APIType:     "openai",
		BaseURL:     "https://api.studio.nebius.com/v1",
		TokenEnvVar: "NEBIUS_API_KEY",
	},
	"nvidia": {
		APIType:     "openai",
		BaseURL:     "https://integrate.api.nvidia.com/v1",
		TokenEnvVar: "NVIDIA_API_KEY",
	},
	"openrouter": {
		APIType:     "openai",
		BaseURL:     "https://openrouter.ai/api/v1",
		TokenEnvVar: "OPENROUTER_API_KEY",
	},
	"mistral": {
		APIType:     "openai",
		BaseURL:     "https://api.mistral.ai/v1",
		TokenEnvVar: "MISTRAL_API_KEY",
	},
	"ollama": {
		APIType: "openai",
		BaseURL: "http://localhost:11434/v1",
	},
	"minimax": {
		APIType:     "openai",
		BaseURL:     "https://api.minimax.io/v1",
		TokenEnvVar: "MINIMAX_API_KEY",
	},
	"baseten": {
		APIType:     "openai",
		BaseURL:     "https://inference.baseten.co/v1",
		TokenEnvVar: "BASETEN_API_KEY",
	},
	"ovhcloud": {
		APIType:     "openai",
		BaseURL:     "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1",
		TokenEnvVar: "OVH_AI_ENDPOINTS_ACCESS_TOKEN",
	},
	"groq": {
		APIType:     "openai",
		BaseURL:     "https://api.groq.com/openai/v1",
		TokenEnvVar: "GROQ_API_KEY",
	},
	"fireworks": {
		APIType:     "openai",
		BaseURL:     "https://api.fireworks.ai/inference/v1",
		TokenEnvVar: "FIREWORKS_API_KEY",
	},
	"deepseek": {
		APIType:     "openai",
		BaseURL:     "https://api.deepseek.com/v1",
		TokenEnvVar: "DEEPSEEK_API_KEY",
	},
	"cerebras": {
		APIType:     "openai",
		BaseURL:     "https://api.cerebras.ai/v1",
		TokenEnvVar: "CEREBRAS_API_KEY",
	},
	"together": {
		APIType:     "openai",
		BaseURL:     "https://api.together.xyz/v1",
		TokenEnvVar: "TOGETHER_API_KEY",
	},
	"huggingface": {
		APIType:     "openai",
		BaseURL:     "https://router.huggingface.co/v1",
		TokenEnvVar: "HF_TOKEN",
	},
	"moonshot": {
		APIType:     "openai",
		BaseURL:     "https://api.moonshot.ai/v1",
		TokenEnvVar: "MOONSHOT_API_KEY",
	},
	"vercel": {
		APIType:     "openai",
		BaseURL:     "https://ai-gateway.vercel.sh/v1",
		TokenEnvVar: "AI_GATEWAY_API_KEY",
	},

	"cloudflare-workers-ai": {
		APIType:     "openai",
		BaseURL:     "https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/ai/v1",
		TokenEnvVar: "CLOUDFLARE_API_TOKEN",
	},
	"cloudflare-ai-gateway": {
		APIType:     "openai",
		BaseURL:     "https://gateway.ai.cloudflare.com/v1/${CLOUDFLARE_ACCOUNT_ID}/${CLOUDFLARE_GATEWAY_ID}/compat",
		TokenEnvVar: "CLOUDFLARE_API_TOKEN",
	},
	"github-copilot": {
		APIType:     "openai",
		BaseURL:     "https://api.githubcopilot.com",
		TokenEnvVar: "GITHUB_TOKEN",
	},

	"chatgpt": {
		APIType:     "openai",
		BaseURL:     chatgpt.BaseURL,
		TokenEnvVar: chatgpt.TokenEnvVar,
	},
	"opencode-go": {
		APIType:     "openai",
		BaseURL:     "https://opencode.ai/zen/go/v1",
		TokenEnvVar: "OPENCODE_API_KEY",
	},
	"opencode-zen": {
		APIType:     "openai",
		BaseURL:     "https://opencode.ai/zen/v1",
		TokenEnvVar: "OPENCODE_API_KEY",
	},
}

Aliases maps provider names to their corresponding configurations.

Most consumers should call LookupAlias for a single lookup or EachAlias to iterate, both of which keep the rest of the codebase decoupled from this concrete map. Direct mutation of Aliases is not supported.

View Source
var CoreProviders = []string{
	"openai",
	"anthropic",
	"google",
	"dmr",
	"amazon-bedrock",
}

CoreProviders lists all natively implemented provider types. These are the provider types that have direct implementations (not aliases).

Functions

func AllProviders

func AllProviders() []string

AllProviders returns all known provider names (core providers + aliases), sorted for deterministic output.

func CatalogProviders

func CatalogProviders() []string

CatalogProviders returns the list of provider names that should be shown in the model catalog. This includes core providers and aliases that have a defined BaseURL (self-contained endpoints). Aliases without a BaseURL (like azure) require user configuration and are excluded.

func EachAlias added in v1.53.0

func EachAlias() iter.Seq2[string, Alias]

EachAlias returns an iterator over every registered (name, Alias) pair. Iteration order is not guaranteed; callers that need a deterministic order should sort by name.

func IsCatalogProvider

func IsCatalogProvider(name string) bool

IsCatalogProvider returns true if the provider name is valid for the model catalog.

func IsKnownProvider

func IsKnownProvider(name string) bool

IsKnownProvider returns true if the provider name is a core provider or an alias.

func ResolveType added in v1.132.0

func ResolveType(cfg *latest.ModelConfig, customProviders map[string]latest.ProviderConfig) string

ResolveType returns the registry key a model config is served by once custom providers (providers: section), built-in aliases and an explicit api_type are applied — i.e. the factory Registry.New will look up for it. A routing model resolves to its fallback provider/model. The config is not mutated.

Types

type Alias

type Alias struct {
	APIType string // The actual API type to use (openai, anthropic, etc.)
	// BaseURL is the default base URL for the provider. It may contain
	// ${VAR}/${env.VAR} references (e.g. ${CLOUDFLARE_ACCOUNT_ID}) that are
	// resolved from the runtime environment when the provider is built.
	BaseURL     string
	TokenEnvVar string // Environment variable name for the API token
}

Alias defines the configuration for a provider alias.

func LookupAlias added in v1.53.0

func LookupAlias(name string) (Alias, bool)

LookupAlias returns the Alias registered for the given name (if any). Lookup is case-sensitive; callers that need case-insensitive matching should normalise the name first (e.g. strings.ToLower).

type BatchEmbeddingProvider

type BatchEmbeddingProvider interface {
	EmbeddingProvider
	// CreateBatchEmbedding generates embedding vectors for multiple texts with usage tracking.
	// Returns embeddings in the same order as input texts.
	CreateBatchEmbedding(ctx context.Context, texts []string) (*base.BatchEmbeddingResult, error)
}

BatchEmbeddingProvider defines the interface for providers that support batch embeddings.

type EmbeddingProvider

type EmbeddingProvider interface {
	Provider
	// CreateEmbedding generates an embedding vector for the given text with usage tracking.
	CreateEmbedding(ctx context.Context, text string) (*base.EmbeddingResult, error)
}

EmbeddingProvider defines the interface for providers that support embeddings.

type Factory added in v1.84.0

type Factory func(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)

func Adapt added in v1.132.0

func Adapt[P Provider](newClient func(context.Context, *latest.ModelConfig, environment.Provider, ...options.Opt) (P, error)) Factory

Adapt turns a provider package's concrete constructor (e.g. anthropic.NewClient, which returns *anthropic.Client) into a Factory so it can be registered without a hand-written closure:

provider.NewRegistry(map[string]provider.Factory{"anthropic": provider.Adapt(anthropic.NewClient)})

type Provider

type Provider interface {
	// ID returns the provider-qualified model identity. Returning a
	// [modelsdev.ID] (rather than a bare string) prevents callers from
	// silently forgetting to namespace the model when it crosses an API
	// boundary; use [modelsdev.ID.String] when a textual representation
	// is required.
	ID() modelsdev.ID
	// CreateChatCompletionStream creates a streaming chat completion request.
	// It returns a stream that can be iterated over to get completion chunks.
	CreateChatCompletionStream(
		ctx context.Context,
		messages []chat.Message,
		tools []tools.Tool,
	) (chat.MessageStream, error)
	// BaseConfig returns the base configuration of this provider.
	BaseConfig() base.Config
}

Provider defines the interface for model providers.

func CloneWithOptions

func CloneWithOptions(ctx context.Context, baseProvider Provider, opts ...options.Opt) Provider

CloneWithOptions returns a new Provider instance using the same provider/model as the base provider, applying the provided options. If cloning fails, the original base provider is returned.

func New deprecated

New creates a provider with an empty registry and therefore returns an unknown-provider error for every concrete provider.

Deprecated: construct a Registry explicitly and call Registry.New.

func NewWithModels deprecated

func NewWithModels(ctx context.Context, cfg *latest.ModelConfig, models map[string]latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)

NewWithModels creates a provider with an empty registry and therefore returns an unknown-provider error for every concrete provider.

Deprecated: construct a Registry explicitly and call Registry.NewWithModels.

type Registry added in v1.84.0

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

func DefaultRegistry deprecated added in v1.84.0

func DefaultRegistry() *Registry

DefaultRegistry returns an empty registry because this package deliberately does not import concrete provider implementations.

Deprecated: use EmptyRegistry or construct a Registry explicitly.

func EmptyRegistry added in v1.139.0

func EmptyRegistry() *Registry

EmptyRegistry returns a registry with no provider factories. It is useful for components that support running without models; it cannot construct a concrete provider until factories are explicitly supplied to NewRegistry.

func NewRegistry added in v1.84.0

func NewRegistry(factories map[string]Factory) *Registry

func (*Registry) Has added in v1.132.0

func (r *Registry) Has(providerType string) bool

Has reports whether a factory is registered for providerType, a key as returned by ResolveType.

func (*Registry) New added in v1.84.0

func (r *Registry) New(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)

func (*Registry) NewWithModels added in v1.84.0

func (r *Registry) NewWithModels(ctx context.Context, cfg *latest.ModelConfig, models map[string]latest.ModelConfig, env environment.Provider, opts ...options.Opt) (Provider, error)

func (*Registry) Types added in v1.132.0

func (r *Registry) Types() []string

Types returns the registered provider types, sorted.

type RerankingProvider

type RerankingProvider interface {
	Provider
	// Rerank scores documents by relevance to the query.
	// Returns relevance scores in the same order as input documents.
	// Scores are typically in [0, 1] range where higher means more relevant.
	// criteria: Optional domain-specific guidance for relevance scoring (appended to base prompt)
	// documents: Array of types.Document with content and metadata
	Rerank(ctx context.Context, query string, documents []types.Document, criteria string) ([]float64, error)
}

RerankingProvider defines the interface for providers that support reranking. Reranking models score query-document pairs to assess relevance.

Directories

Path Synopsis
federation
Package federation builds the Anthropic Workload Identity Federation pieces (identity-token providers and SDK request options) from a typed latest.AuthConfig.
Package federation builds the Anthropic Workload Identity Federation pieces (identity-token providers and SDK request options) from a typed latest.AuthConfig.
vertex
Package vertex provides an Anthropic client for Claude models hosted on Google Cloud's Vertex AI.
Package vertex provides an Anthropic client for Claude models hosted on Google Cloud's Vertex AI.
dmr
dmrmodels
Package dmrmodels handles Docker Model Runner endpoint discovery and model listing.
Package dmrmodels handles Docker Model Runner endpoint discovery and model listing.
Package providers wires every built-in model provider into a provider.Registry.
Package providers wires every built-in model provider into a provider.Registry.
Package rulebased provides a rule-based model router that selects the appropriate model based on text similarity using a lightweight in-memory BM25 ranker.
Package rulebased provides a rule-based model router that selects the appropriate model based on text similarity using a lightweight in-memory BM25 ranker.
Package vertexai provides support for non-Gemini models hosted on Google Cloud's Vertex AI Model Garden.
Package vertexai provides support for non-Gemini models hosted on Google Cloud's Vertex AI Model Garden.

Jump to

Keyboard shortcuts

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