auto

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package auto provides zero-config multi-provider setup for LLM providers.

Index

Constants

View Source
const (
	ProviderClaude     = "claude"
	ProviderBedrock    = "bedrock"
	ProviderOpenAI     = "openai"
	ProviderOpenRouter = "openrouter"
	ProviderAnthropic  = "anthropic"
)

Provider type names.

View Source
const (
	EnvOpenAIKey     = "OPENAI_API_KEY"
	EnvOpenAIKeyAlt  = "OPENAI_KEY"
	EnvOpenRouterKey = "OPENROUTER_API_KEY"
	EnvAnthropicKey  = "ANTHROPIC_API_KEY"
)

Environment variable names.

View Source
const (
	AliasFast     = "fast"
	AliasDefault  = "default"
	AliasPowerful = "powerful"
	AliasCodex    = "codex"
)

Global model aliases.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, opts ...Option) (*router.Provider, error)

New creates an aggregate provider with auto-detected or explicitly configured providers.

Without options, it auto-detects available providers:

  • Claude local (~/.claude credentials)
  • AWS Bedrock (always included)
  • Anthropic direct API (if ANTHROPIC_API_KEY is set)
  • OpenAI (if OPENAI_API_KEY or OPENAI_KEY is set)
  • OpenRouter (if OPENROUTER_API_KEY is set)

With explicit options, you can configure specific providers:

auto.New(ctx,
    auto.WithName("myapp"),
    auto.WithClaude(tokenStore),  // Claude accounts from store
    auto.WithClaudeLocal(),       // Claude local credentials
    auto.WithBedrock(),           // AWS Bedrock
)

Types

type Option

type Option func(*config)

Option configures the auto provider.

func WithAnthropic

func WithAnthropic() Option

WithAnthropic adds direct Anthropic API provider. Requires ANTHROPIC_API_KEY environment variable.

func WithBedrock

func WithBedrock() Option

WithBedrock adds AWS Bedrock provider.

func WithClaude

func WithClaude(store claude.TokenStore) Option

WithClaude adds all Claude OAuth accounts from a TokenStore. Each account key becomes a separate provider instance with name equal to the key.

func WithClaudeAccount

func WithClaudeAccount(name string, store claude.TokenStore) Option

WithClaudeAccount adds a specific Claude OAuth account.

func WithClaudeLocal

func WithClaudeLocal() Option

WithClaudeLocal adds the local Claude credentials (~/.claude).

func WithGlobalAlias added in v0.19.0

func WithGlobalAlias(alias string, targets ...string) Option

WithGlobalAlias adds a user-defined global alias that resolves to one or more targets. Targets should be provider-prefixed model references (e.g., "openai/o3", "openrouter/openai/o3"). Multiple targets enable failover - if the first target fails, the next is tried.

Example:

auto.WithGlobalAlias("o3", "openai/o3", "openrouter/openai/o3")

func WithGlobalAliases added in v0.19.0

func WithGlobalAliases(aliases map[string][]string) Option

WithGlobalAliases adds multiple user-defined global aliases. Each key is an alias name, and the value is a slice of targets.

Example:

auto.WithGlobalAliases(map[string][]string{
    "o3":    {"openai/o3", "openrouter/openai/o3"},
    "codex": {"openai/codex"},
})

func WithHTTPClient added in v0.23.0

func WithHTTPClient(client *http.Client) Option

WithHTTPClient sets a custom HTTP client used by all providers created by this auto provider. Useful for injecting a logging or tracing transport.

func WithLLMOptions added in v0.23.0

func WithLLMOptions(opts ...llm.Option) Option

WithLLMOptions sets shared llm.Option values applied to all providers that support them (e.g. llm.WithLogger for Bedrock eventstream logging).

func WithName

func WithName(name string) Option

WithName sets the aggregate provider name.

func WithOpenAI

func WithOpenAI() Option

WithOpenAI adds OpenAI provider. Requires OPENAI_API_KEY or OPENAI_KEY environment variable.

func WithOpenRouter

func WithOpenRouter() Option

WithOpenRouter adds OpenRouter provider. Requires OPENROUTER_API_KEY environment variable.

func WithoutAutoDetect

func WithoutAutoDetect() Option

WithoutAutoDetect disables auto-detection of providers. Use this when you want to explicitly configure all providers.

Jump to

Keyboard shortcuts

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