config

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package config loads and validates the claude-code-router YAML configuration. The config describes:

  • listed providers (each: upstream URL, optional token, list of model-name glob patterns)
  • which provider to route to when no glob matches (default_provider)

Routing is per-request: the model-router inspects the JSON body's `model` field and forwards to the matching provider's reverse proxy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Router    Router              `yaml:"router"`
	Providers map[string]Provider `yaml:"providers"`
	// Aliases maps a short operator-typed model name to the full
	// model string the upstream expects. Resolved single-hop before
	// glob-routing: a request body `{"model":"qwen"}` becomes
	// `{"model":"qwen3.6:35b-a3b-coding-nvfp4"}` before the router
	// walks providers' models globs. Nil / empty map = no-op.
	Aliases map[string]string `yaml:"aliases,omitempty"`
}

Config is the parsed YAML root.

func Load

func Load(rawPath string) (*Config, error)

Load reads, parses, and validates the config at path. Tilde-prefix (~/) is expanded to the user's home directory.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks that the parsed config is internally consistent.

type Provider

type Provider struct {
	// Upstream is the base URL, e.g. https://api.anthropic.com.
	Upstream string `yaml:"upstream"`
	// Token, if set, replaces the client's Authorization header with
	// "Bearer <Token>". If empty, the client's Authorization is
	// forwarded verbatim — used for the subscription-OAuth case.
	Token string `yaml:"token,omitempty"`
	// Models is the list of glob patterns (filepath.Match syntax) the
	// router uses to match request body's `model` field. Examples:
	// "claude-opus-*", "MiniMax-*", "qwen*".
	Models []string `yaml:"models"`
}

Provider describes one upstream LLM API.

type Router

type Router struct {
	// DefaultProvider is the provider key used when no model glob matches.
	// Must reference a key in Providers; validated on Load.
	DefaultProvider string `yaml:"default_provider"`
}

Router holds router-wide settings.

Jump to

Keyboard shortcuts

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