router

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package router resolves the model name in a request to the adapter that serves it.

Names are namespaced "<adapter>" or "<adapter>:<model>". A bare adapter id means the CLI's own default model; anything after the colon goes to the CLI verbatim, since it is the authority on what it accepts and agent2api keeps no list to go stale. A name naming no served adapter is a 404.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID      string
	Adapter string
}

Entry is one row of GET /v1/models.

type Resolution

type Resolution struct {
	// Model is the canonical name the backend was reached by, e.g.
	// "claude-code:opus" or bare "claude-code".
	Model string
	// Variant is the model name to hand the CLI, empty for its own default.
	Variant string
	Adapter adapter.Adapter
}

Resolution is a routed model.

func (Resolution) EffortLevels added in v0.1.5

func (r Resolution) EffortLevels(ctx context.Context) []ir.Effort

EffortLevels reports the reasoning-effort levels the resolved backend takes, empty when it has no such knob. Frontends ask before accepting a caller's level, so a refusal can name the backend and say what it does take.

func (Resolution) EnforcesSchema added in v0.1.3

func (r Resolution) EnforcesSchema(ctx context.Context) bool

EnforcesSchema reports whether the resolved backend can hold an answer to a JSON Schema. Frontends ask before accepting a caller's schema, so a refusal can name the backend that cannot do it rather than reading as a gateway-wide limitation.

type Router

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

Router maps model names to adapters. It is immutable after construction and safe for concurrent use.

func New

func New(adapters []adapter.Adapter) (*Router, error)

New builds a router over the given adapters.

func (*Router) Adapters

func (r *Router) Adapters() []adapter.Adapter

Adapters returns the routed adapters, ordered by id.

func (*Router) Entries

func (r *Router) Entries() []Entry

Entries lists what GET /v1/models advertises: one row per backend, named by its adapter id. Callers may append ":<model>" to any of them.

func (*Router) ModelIDs

func (r *Router) ModelIDs() []string

ModelIDs lists advertised model names in a stable order.

func (*Router) Resolve

func (r *Router) Resolve(name string) (Resolution, error)

Resolve maps a requested model name to its adapter.

Jump to

Keyboard shortcuts

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