Documentation
¶
Index ¶
- Constants
- Variables
- func EnableClaudeMidConvoEffort(model ChatModel)
- func EnableOpenAIGrammarTools(model ChatModel)
- func EnableOpenAIMidConvoSystemMessages(model ChatModel, proxy bool)
- func IsKimiK3FamilyID(modelID string) bool
- func MergeCompat(model ChatModel, compat *Obj)
- func MergeThinking(model ChatModel, levels *Obj)
- func NormalizeNvidiaModelID(modelID string) string
- func OpenAIStandardCosts() map[string]*Obj
- func ParseFloat(text string) float64
- func ParseJSON(data []byte) (any, error)
- func Quote(text string) string
- func RoundCost(value float64) float64
- func Stringify(value any, indent string) []byte
- func Strings(values ...string) []any
- func SupportsClaudeMidConvoEffort(modelID string) bool
- func SupportsClaudeMidConvoSystemMessages(modelID string) bool
- func SupportsOpenAIXhigh(modelID string) bool
- func WithInputLimits(model ChatModel, limits *Obj)
- type AiGatewayCatalog
- type ApiCompatDefaults
- type CatalogSources
- type ChatModel
- type CompatFunc
- type ModelsDevAPI
- type ModelsDevCost
- type ModelsDevCostTier
- type ModelsDevDecisionMetadata
- type ModelsDevModel
- type ModelsDevOptions
- type ModelsDevReasoningOption
- type Obj
- func Claude55ThinkingLevels(modelID string) *Obj
- func CloneAll(objects []*Obj) []*Obj
- func DeepSeekCompat() *Obj
- func DeepSeekV4FlashThinkingLevelMap() *Obj
- func DeepSeekV4ThinkingLevelMap() *Obj
- func GetAiGatewayCost(pricing *Obj) *Obj
- func GetEffortThinkingLevelMap(options []ModelsDevReasoningOption) *Obj
- func GetOpenRouterThinkingLevelMap(reasoning *OpenRouterReasoningMetadata) *Obj
- func GoogleThinkingLevels(modelID string, reasoningOptions []ModelsDevReasoningOption) *Obj
- func KimiK3Cost() *Obj
- func KimiK3OpenAICompat() *Obj
- func KimiOpenAICompat() *Obj
- func ModelsDevToCost(cost ModelsDevCost) *Obj
- func NewObj() *Obj
- func O(pairs ...any) *Obj
- func OpenAIStandardCost(id string) *Obj
- func OpenRouterCost(pricing *Obj) *Obj
- func Spread(parts ...*Obj) *Obj
- func WithOpenAILongContextPricing(cost *Obj) *Obj
- func (o *Obj) Bool(key string) bool
- func (o *Obj) Clone() *Obj
- func (o *Obj) Delete(key string)
- func (o *Obj) Get(key string) (any, bool)
- func (o *Obj) Has(key string) bool
- func (o *Obj) Includes(key, value string) bool
- func (o *Obj) Keys() []string
- func (o *Obj) Len() int
- func (o *Obj) List(key string) []any
- func (o *Obj) MarshalJSON() ([]byte, error)
- func (o *Obj) Num(key string) float64
- func (o *Obj) Object(key string) *Obj
- func (o *Obj) Set(key string, value any) *Obj
- func (o *Obj) Str(key string) string
- func (o *Obj) StringList(key string) []string
- type OpenRouterCatalog
- type OpenRouterReasoningMetadata
- type ProviderCatalog
- type ProviderContext
- type ProviderDefinition
Constants ¶
const ( ModelsDevURL = "https://models.dev/experimental/v2.0/api.json" // v2 has no provider-agnostic decision metadata endpoint; v1 still serves it. ModelsDevDecisionsURL = "https://models.dev/models.json?type=decision" )
The models.dev v2 catalog. The schema is published as experimental, so everything the catalog reads goes through NormalizeModelsDevModel.
const DefaultRadiusGateway = "https://radius.pi.dev"
DefaultRadiusGateway is the unauthenticated public Radius gateway.
const KimiK3MaxTokens = 131072
KimiK3MaxTokens is the K3 family's canonical output limit.
const NvidiaBaseURL = "https://integrate.api.nvidia.com/v1"
NvidiaBaseURL is the NVIDIA NIM endpoint.
const OpenAILongContextInputThreshold = 272000
OpenAILongContextInputThreshold is the prompt size above which OpenAI bills the long-context tier.
Variables ¶
var OpenAIMidConvoModelIDs = func() map[string]bool { ids := map[string]bool{"gpt-5.4": true, "gpt-5.4-mini": true, "gpt-5.4-pro": true, "gpt-5.5": true} for id := range OpenAIToolSearchModelIDs { ids[id] = true } return ids }()
OpenAIMidConvoModelIDs are the models that accept mid-conversation developer messages.
var OpenAIToolSearchModelIDs = map[string]bool{ "gpt-5.6-sol": true, "gpt-5.6-terra": true, "gpt-5.6-luna": true, "gpt-6-astra": true, "gpt-6-sol": true, "gpt-6-luna": true, "gpt-6.1-sol": true, "gpt-6.1-terra": true, }
OpenAIToolSearchModelIDs are the models that accept tool search and `additional_tools`.
Functions ¶
func EnableClaudeMidConvoEffort ¶
func EnableClaudeMidConvoEffort(model ChatModel)
EnableClaudeMidConvoEffort enables per-message effort changes. Models that cannot disable thinking with it lose "off".
func EnableOpenAIGrammarTools ¶
func EnableOpenAIGrammarTools(model ChatModel)
EnableOpenAIGrammarTools enables OpenAI custom grammar tools on Responses endpoints. OpenAI rejects `type: "custom"` tools for pre-GPT-5 models (gpt-4.x, gpt-4o, o-series).
func EnableOpenAIMidConvoSystemMessages ¶
EnableOpenAIMidConvoSystemMessages: newer OpenAI Responses models accept developer messages after the conversation has started. Proxies that pass them through also pass `additional_tools` items through unchanged, for the models that accept them.
func IsKimiK3FamilyID ¶
IsKimiK3FamilyID: Kimi K3 and its point releases (kimi-k3.1-pro, kimi-k3.1-pro-highspeed) share K3's request format. https://api.moonshot.ai/v1/models reports effort levels and dynamic tool loading for all of them.
func MergeCompat ¶
MergeCompat shallow-merges compat flags into a model.
func MergeThinking ¶
MergeThinking shallow-merges thinking level mappings into a model. Later values win.
func NormalizeNvidiaModelID ¶
NormalizeNvidiaModelID is the id form models.dev lists NIM models under.
func OpenAIStandardCosts ¶
OpenAIStandardCosts keeps current OpenAI prices authoritative until models.dev and passthrough catalogs catch up. https://developers.openai.com/api/docs/pricing
func ParseFloat ¶
ParseFloat is Number.parseFloat(text): NaN when text has no decimal prefix.
func ParseJSON ¶
ParseJSON is JSON.parse for catalog sources: objects become *Obj in document order (a repeated key keeps its first position and takes its last value), numbers become float64.
func Quote ¶
Quote is JSON.stringify(string): it escapes control characters, quotes and backslashes only.
func Stringify ¶
Stringify is JSON.stringify(value, null, indent) for catalog values; indent is "" or the per-level indent.
func SupportsClaudeMidConvoEffort ¶
SupportsClaudeMidConvoEffort reports models that accept per-message `output_config` effort changes.
func SupportsClaudeMidConvoSystemMessages ¶
SupportsClaudeMidConvoSystemMessages reports models that accept system messages and tool changes after the conversation starts.
func SupportsOpenAIXhigh ¶
SupportsOpenAIXhigh reports ids with the xhigh effort.
func WithInputLimits ¶
WithInputLimits sets provider input limits for image-capable models. Limits the model already carries take precedence.
Types ¶
type AiGatewayCatalog ¶
type AiGatewayCatalog struct {
Chat, Classifiers []*Obj
}
AiGatewayCatalog is the tool-capable chat models and the evaluation (classifier) models of the Vercel AI Gateway.
func BuildAiGatewayCatalog ¶
func BuildAiGatewayCatalog(items []*Obj) AiGatewayCatalog
BuildAiGatewayCatalog converts the listing: an evaluation model is a classifier served through the TypeSafe-compatible System One endpoint, and any other model becomes a chat model when it carries the tool-use tag.
func FetchAiGatewayCatalog ¶
func FetchAiGatewayCatalog() (AiGatewayCatalog, error)
FetchAiGatewayCatalog fetches tool-capable chat models and evaluation (classifier) models.
type ApiCompatDefaults ¶
type ApiCompatDefaults map[string]CompatFunc
ApiCompatDefaults are compat defaults per API. They sit under each model's own compat, so model values win.
type CatalogSources ¶
type CatalogSources struct {
ModelsDev *Obj
ModelsDevDecisions map[string]ModelsDevDecisionMetadata
OpenRouter OpenRouterCatalog
AIGateway AiGatewayCatalog
// NvidiaModelIDs are the live NVIDIA NIM ids, keyed by both the raw and the normalized id.
NvidiaModelIDs map[string]string
Radius []*Obj
}
CatalogSources is everything fetched from upstream before the catalog is built.
func LoadCatalogSources ¶
func LoadCatalogSources(strict bool) (*CatalogSources, error)
LoadCatalogSources fetches every upstream source. In strict mode any failure aborts generation; otherwise a failed source contributes nothing.
type ChatModel ¶
type ChatModel = *Obj
ChatModel is a chat model entry: a pi `Model` object, member order as the catalog constructs it.
func AddMissing ¶
AddMissing adds models only when upstream has not listed them (yet).
func ModelsDevModels ¶
func ModelsDevModels(ctx *ProviderContext, sourceProvider string, options ModelsDevOptions) ([]ChatModel, error)
ModelsDevModels maps one models.dev provider's tool-capable chat models onto pi models.
type CompatFunc ¶
CompatFunc returns the compat defaults for one model of an API. A fixed default returns a fresh copy for every model.
func FixedCompat ¶
func FixedCompat(compat *Obj) CompatFunc
FixedCompat is compat defaults that do not vary by model.
type ModelsDevAPI ¶
type ModelsDevAPI struct {
Protocol, BaseURL, AISDK string
}
ModelsDevAPI is one API a model is served on, in the order models.dev lists them.
type ModelsDevCost ¶
type ModelsDevCost struct {
Input, Output, CacheRead, CacheWrite *float64
// Tiers are context-size tiers. Unlisted rates fall back to the base rates.
Tiers []ModelsDevCostTier
}
ModelsDevCost is the prices as models.dev lists them. Missing prices stay nil.
type ModelsDevCostTier ¶
ModelsDevCostTier is one context-size tier.
type ModelsDevDecisionMetadata ¶
type ModelsDevDecisionMetadata struct {
ID, Type, Name string
// ContextLimit is limit.context, 0 when absent.
ContextLimit float64
}
ModelsDevDecisionMetadata is provider-agnostic decision model metadata from models.dev.
type ModelsDevModel ¶
type ModelsDevModel struct {
ID, Name, Type, Status string
ToolCall bool
StructuredOutput bool
Reasoning bool
// ReasoningOptions is empty when the model does not reason.
ReasoningOptions []ModelsDevReasoningOption
ImageInput bool
TextInput bool
TextOutput bool
// ContextWindow and MaxTokens are 0 when models.dev lists none.
ContextWindow, MaxTokens float64
Cost ModelsDevCost
APIs []ModelsDevAPI
// Source is the full v2 entry, for fields not normalized above.
Source *Obj
}
ModelsDevModel is a models.dev model normalized for the catalog.
func ModelsDevChatModels ¶
func ModelsDevChatModels(catalog *Obj, provider string) []*ModelsDevModel
ModelsDevChatModels returns the chat models of one models.dev provider. Specialized types (image, speech, realtime, decision, ...) only appear in v2 and are left out here.
func NormalizeModelsDevModel ¶
func NormalizeModelsDevModel(model *Obj) *ModelsDevModel
NormalizeModelsDevModel reads the subset of a models.dev v2 model the catalog uses.
func (*ModelsDevModel) HasEffortOption ¶
func (m *ModelsDevModel) HasEffortOption() bool
HasEffortOption is `reasoningOptions?.some((option) => option.type === "effort")`.
func (*ModelsDevModel) HasToggleOption ¶
func (m *ModelsDevModel) HasToggleOption() bool
HasToggleOption is `reasoningOptions?.some((option) => option.type === "toggle")`.
type ModelsDevOptions ¶
type ModelsDevOptions struct {
API string
BaseURL string
Compat *Obj
Headers *Obj
// Protocol keeps only models models.dev lists on this API protocol (e.g. "responses").
Protocol string
// SkipDeprecated skips models models.dev marks deprecated.
SkipDeprecated bool
// NoRecordReasoning is `recordReasoning: false`: models.dev effort levels are not exposed through the shared rules.
NoRecordReasoning bool
// DefaultContextWindow and DefaultMaxTokens are fallback limits when models.dev has none; 4096 each when zero.
DefaultContextWindow, DefaultMaxTokens float64
// Include is an extra filter. Models without tool support are always skipped.
Include func(source *ModelsDevModel) bool
// Map adjusts or replaces the mapped model. Returning nil skips the model.
Map func(model ChatModel, source *ModelsDevModel) (ChatModel, error)
}
ModelsDevOptions configures ModelsDevModels.
type ModelsDevReasoningOption ¶
type ModelsDevReasoningOption struct {
Type string `json:"type"`
Values []*string `json:"values,omitempty"`
Min *float64 `json:"min,omitempty"`
Max *float64 `json:"max,omitempty"`
}
ModelsDevReasoningOption describes a raw models.dev reasoning control: a toggle, effort values (a value is null in JSON when models.dev lists no verified value) or a token budget.
type Obj ¶
type Obj struct {
// contains filtered or unexported fields
}
Obj is a JavaScript plain object: string keys in insertion order. Values are nil (JSON null), string, bool, float64, []any and *Obj; Set normalizes int and []string. An absent key is JavaScript's undefined.
func Claude55ThinkingLevels ¶
Claude55ThinkingLevels: models.dev may list Opus 5.5, Sonnet 5.5, and Haiku 5.5 before their effort metadata is complete. Haiku 5.5 accepts disabled thinking; Opus 5.5 and Sonnet 5.5 reject it.
func DeepSeekCompat ¶
func DeepSeekCompat() *Obj
DeepSeekCompat is the compat of DeepSeek V4 on its own API and on hosts that take DeepSeek's thinking format.
func DeepSeekV4FlashThinkingLevelMap ¶
func DeepSeekV4FlashThinkingLevelMap() *Obj
DeepSeekV4FlashThinkingLevelMap is the V4 Flash level map: V4 Pro's with low.
func DeepSeekV4ThinkingLevelMap ¶
func DeepSeekV4ThinkingLevelMap() *Obj
DeepSeekV4ThinkingLevelMap is the V4 Pro level map.
func GetAiGatewayCost ¶
GetAiGatewayCost converts AI Gateway pricing ($/token) to $/million tokens. Each rate lists its own prompt-length brackets; every bracket start above zero becomes a request-wide tier with the rates in effect there.
func GetEffortThinkingLevelMap ¶
func GetEffortThinkingLevelMap(options []ModelsDevReasoningOption) *Obj
GetEffortThinkingLevelMap converts models.dev verified effort values into Pi's selectable thinking levels. Values without a Pi equivalent (`default` and JSON `null`) are intentionally omitted. The map is nil when no level is verified: toggle, budget, default and null values imply no selectable effort.
func GetOpenRouterThinkingLevelMap ¶
func GetOpenRouterThinkingLevelMap(reasoning *OpenRouterReasoningMetadata) *Obj
GetOpenRouterThinkingLevelMap converts OpenRouter's reasoning metadata into Pi model capabilities; nil when it says nothing.
func GoogleThinkingLevels ¶
func GoogleThinkingLevels(modelID string, reasoningOptions []ModelsDevReasoningOption) *Obj
GoogleThinkingLevels returns Gemini effort levels from models.dev, with a Gemma 4 fallback; nil when neither applies.
func KimiK3OpenAICompat ¶
func KimiK3OpenAICompat() *Obj
KimiK3OpenAICompat: Kimi K3-style models take reasoning_effort and need earlier reasoning sent back.
func KimiOpenAICompat ¶
func KimiOpenAICompat() *Obj
KimiOpenAICompat is the Kimi Chat Completions settings shared by Moonshot and Kimi Coding.
func ModelsDevToCost ¶
func ModelsDevToCost(cost ModelsDevCost) *Obj
ModelsDevToCost converts models.dev prices to pi's cost shape. Missing rates are free.
func OpenAIStandardCost ¶
OpenAIStandardCost is the standard price of an OpenAI model with long-context pricing.
func OpenRouterCost ¶
OpenRouterCost converts OpenRouter's $/token prices to pi's $/1M tokens. Missing, invalid and negative base prices are 0. Prompt-length overrides become request-wide tiers; a rate a tier does not list keeps the base price. Time-of-day overrides are skipped because ModelCost cannot express them.
func Spread ¶
Spread is `{ ...parts[0], ...parts[1], ... }`: a key keeps the position of its first appearance and takes the last value. A nil part contributes nothing, as spreading undefined does. Values are shared, not copied, as in JavaScript.
func WithOpenAILongContextPricing ¶
WithOpenAILongContextPricing: OpenAI bills prompts above 272K input tokens at 2x input and 1.5x output rates.
func (*Obj) Has ¶
Has reports whether the key is present (`key in object`; an undefined value never occurs here).
func (*Obj) Keys ¶
Keys returns the keys in JavaScript enumeration order: canonical array indices ascending, then the others in insertion order.
func (*Obj) MarshalJSON ¶
MarshalJSON is JSON.stringify(object).
func (*Obj) StringList ¶
StringList returns the strings of an array member.
type OpenRouterCatalog ¶
type OpenRouterCatalog struct {
Chat, Images, Classifiers []*Obj
}
OpenRouterCatalog is the tool-capable chat, image and decision models of OpenRouter.
func BuildOpenRouterCatalog ¶
func BuildOpenRouterCatalog(listed, imageListed, decisionListed []*Obj) OpenRouterCatalog
BuildOpenRouterCatalog builds the OpenRouter catalog from the default listing and the `output_modalities=image` and `output_modalities=decisions` listings. The default listing omits image-only and decision models, so those come from the other listings. An upstream model may appear in several results; it then gets separate entries per operation.
func FetchOpenRouterCatalog ¶
func FetchOpenRouterCatalog() (OpenRouterCatalog, error)
FetchOpenRouterCatalog fetches the tool-capable chat, image, and decision listings.
type OpenRouterReasoningMetadata ¶
type OpenRouterReasoningMetadata struct {
Mandatory bool `json:"mandatory,omitempty"`
DefaultEnabled bool `json:"default_enabled,omitempty"`
SupportedEfforts []*string `json:"supported_efforts,omitempty"`
DefaultEffort *string `json:"default_effort,omitempty"`
}
OpenRouterReasoningMetadata is OpenRouter's reasoning metadata of a model.
type ProviderCatalog ¶
ProviderCatalog is one provider's built models by type. Chat entries carry `type: "chat"` last.
func BuildCatalog ¶
func BuildCatalog(definitions []ProviderDefinition, sources *CatalogSources, strict bool) ([]ProviderCatalog, error)
BuildCatalog runs every provider's definition, in the order given, against the fetched sources.
type ProviderContext ¶
type ProviderContext struct {
// ProviderID is the provider being built.
ProviderID string
Sources *CatalogSources
// Strict fails instead of degrading when upstream data is unexpected.
Strict bool
// contains filtered or unexported fields
}
ProviderContext is passed to every provider hook.
func (*ProviderContext) ModelsDevSource ¶
func (c *ProviderContext) ModelsDevSource(model ChatModel) *ModelsDevModel
ModelsDevSource returns the models.dev entry a model was built from, if it was recorded.
func (*ProviderContext) ProviderModels ¶
func (c *ProviderContext) ProviderModels(providerID string) ([]ChatModel, error)
ProviderModels returns copies of another provider's chat models before shared rules run.
func (*ProviderContext) RecordModelsDevSource ¶
func (c *ProviderContext) RecordModelsDevSource(model ChatModel, source *ModelsDevModel)
RecordModelsDevSource records the models.dev entry so shared rules can use its reasoning metadata.
type ProviderDefinition ¶
type ProviderDefinition struct {
ID string
Models func(ctx *ProviderContext) ([]ChatModel, error)
Images func(ctx *ProviderContext) ([]*Obj, error)
Classifiers func(ctx *ProviderContext) ([]*Obj, error)
Compat ApiCompatDefaults
Finalize func(model ChatModel, ctx *ProviderContext)
FinalizeAll func(models []ChatModel, ctx *ProviderContext)
}
ProviderDefinition is one built-in provider's catalog. The build runs, in order:
- Models: upstream models plus authored ones, with data corrections.
- Compat defaults and the shared model-family rules in the families files.
- Finalize: provider-specific behavior that must win over shared rules.
- Shared normalization (image input limits), then FinalizeAll.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package providers holds every built-in provider catalog: one file per provider of packages/ai/catalog/providers, registered in All in the order of providers/index.ts.
|
Package providers holds every built-in provider catalog: one file per provider of packages/ai/catalog/providers, registered in All in the order of providers/index.ts. |