Documentation
¶
Index ¶
Constants ¶
const ( SceneDefault = "default" SceneLongContext = "longContext" SceneBackground = "background" SceneWebSearch = "websearch" SceneThink = "think" SceneImage = "image" )
Variables ¶
This section is empty.
Functions ¶
func BuildUpstreamURL ¶
BuildUpstreamURL constructs the full upstream URL from base_url and api_path. Handles both cases: base_url with or without /v1 suffix.
func CountTokens ¶ added in v0.1.4
CountTokens counts the approximate token count of an Anthropic request body. It extracts text from messages, system prompts, and tools. Returns 0 if encoding fails or body is invalid JSON.
func DetectScene ¶
func DetectScene(body []byte, cfg SceneConfig) string
DetectScene detects the Claude Code scenario from an Anthropic request body. Detection priority (matching cc-router): 1. longContext — token count exceeds threshold (> 0 to enable) 2. background — model name contains "haiku" 3. websearch — tools contain web_search_* type 4. think — thinking field present 5. image — user messages contain image content blocks 6. default — fallback
func FormatToPath ¶ added in v0.1.4
FormatToPath returns the default upstream API path for a given protocol format.
Types ¶
type ConfigRouter ¶
type ConfigRouter struct {
// contains filtered or unexported fields
}
ConfigRouter implements Router using config-based routing rules.
func NewConfigRouter ¶
func NewConfigRouter(provider *config.Provider) *ConfigRouter
NewConfigRouter creates a new ConfigRouter.
func (*ConfigRouter) Route ¶
func (r *ConfigRouter) Route(clientProtocol, apiKey string, body []byte) (*RouteResult, error)
Route resolves a request to an upstream provider + model.
type RouteResult ¶
type RouteResult struct {
ProviderKey string // config provider key
BaseURL string // upstream base_url
APIKey string // upstream api_key
Format string // upstream format (chat/anthropic/responses)
Model string // resolved model name to send upstream
Path string // upstream API path (resolved from format or overridden by config)
ThinkTag string // optional: strip <tag>...</tag> from responses
}
RouteResult holds the resolved routing decision.
type Router ¶
type Router interface {
// Route makes a routing decision. clientProtocol is "anthropic"/"responses"/"chat".
// apiKey is from the client's auth header. body is the raw request JSON.
Route(clientProtocol, apiKey string, body []byte) (*RouteResult, error)
}
Router resolves a request to an upstream provider + model.
type SceneConfig ¶
type SceneConfig struct {
LongContextThreshold int
}
SceneConfig holds configuration for scene detection.