modelsgateway

package
v1.118.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package modelsgateway discovers the models served by an OpenAI-compatible models gateway by querying its /v1/models endpoint.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListModels

func ListModels(ctx context.Context, gatewayURL string, env environment.Provider) ([]string, error)

ListModels queries <gatewayURL>/v1/models and returns the IDs of the models the gateway serves. Query parameters present in gatewayURL are forwarded. When the gateway targets a trusted Docker domain, the Docker Desktop token is required and sent as a Bearer token, mirroring how provider clients authenticate gateway traffic.

An error is returned when the gateway is unreachable, responds with a non-200 status (e.g. it doesn't implement /v1/models), or returns a body that isn't a valid OpenAI-style model list. Callers are expected to fall back to their non-discovery behavior in that case.

Types

type Metadata added in v1.118.0

type Metadata struct {
	// Family is the model family from the catalog (e.g. "text-embedding").
	Family string
	// OutputModalities lists the output modalities the catalog declares.
	OutputModalities []string
}

Metadata is the subset of catalog information NormalizeIDs consults to filter out models unsuitable for chat.

type MetadataFunc added in v1.118.0

type MetadataFunc func(ctx context.Context, provider, model string) (Metadata, bool)

MetadataFunc looks up catalog metadata for a provider/model pair. It returns ok=false when the model is unknown to the catalog, in which case NormalizeIDs keeps the model (no signal to exclude it). Callers typically back it with a models.dev store; a nil MetadataFunc skips metadata-based filtering entirely.

type Ref added in v1.118.0

type Ref struct {
	Provider string
	Model    string
}

Ref is a normalized provider/model reference served by a models gateway. It is deliberately a small neutral type so both the runtime (ModelChoice) and the CLI (modelRow) can adapt it without depending on each other.

func NormalizeIDs added in v1.118.0

func NormalizeIDs(ctx context.Context, ids []string, lookup MetadataFunc) []Ref

NormalizeIDs transforms the raw model IDs returned by a gateway's /v1/models endpoint into provider/model references:

  • IDs already prefixed with a provider ("anthropic/claude-x") keep it; bare IDs are routed through the openai provider, matching how the gateway serves them over its OpenAI-compatible endpoint.
  • Providers are lowercased ("OpenAI/gpt-4o" → "openai/gpt-4o") so a gateway's casing matches the canonical provider IDs used for catalog lookups and deduplication; the model part keeps its case.
  • Malformed references (empty provider or model) are dropped.
  • Embedding models are excluded, identified by the model ID or by the catalog family when metadata is available.
  • Models whose catalog metadata declares output modalities without "text" are excluded (not suitable for chat); models without metadata or without declared modalities are kept.
  • Duplicates are removed; the first occurrence wins, so the result order deterministically follows the gateway's order.

func (Ref) String added in v1.118.0

func (r Ref) String() string

String renders the reference in the "provider/model" form used across the codebase.

Jump to

Keyboard shortcuts

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