auto

package
v0.33.1 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 13 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"
	ProviderMiniMax    = "minimax"
)

Provider type names.

View Source
const (
	EnvOpenAIKey     = "OPENAI_API_KEY"
	EnvOpenAIKeyAlt  = "OPENAI_KEY"
	EnvOpenRouterKey = "OPENROUTER_API_KEY"
	EnvAnthropicKey  = "ANTHROPIC_API_KEY"
	EnvMiniMaxKey    = "MINIMAX_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 in priority order:

  • Claude local (~/.claude credentials)
  • Anthropic direct API (if ANTHROPIC_API_KEY is set)
  • AWS Bedrock (if AWS_ACCESS_KEY_ID, AWS_PROFILE, or container credentials are 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 WithCodexLocal added in v0.32.0

func WithCodexLocal() Option

WithCodexLocal adds the OpenAI provider using local Codex CLI credentials (~/.codex/auth.json). The OAuth access token is refreshed automatically when it approaches expiry, so no OPENAI_API_KEY is needed.

Requests are routed to https://chatgpt.com/backend-api (not api.openai.com) because the ChatGPT Plus OAuth token lacks the api.responses.write scope required by the standard developer API.

Returns a no-op option if the credentials file is absent or unreadable.

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.

func WithoutBedrock added in v0.26.0

func WithoutBedrock() Option

WithoutBedrock is a convenience shorthand for WithoutProvider(ProviderBedrock). It prevents AWS Bedrock from being auto-detected even when AWS credentials are present in the environment.

func WithoutProvider added in v0.26.0

func WithoutProvider(providerType string) Option

WithoutProvider excludes a provider type from auto-detection. Auto-detection remains enabled for all other provider types. Use the Provider* constants (e.g. ProviderBedrock, ProviderOpenAI).

Example:

auto.New(ctx, auto.WithoutProvider(auto.ProviderBedrock))

Jump to

Keyboard shortcuts

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