Documentation
¶
Overview ¶
Package registry provides model definitions and lookup helpers for various AI providers. Static model metadata is stored in model_definitions_static_data.go.
Package registry provides model definitions for various AI service providers. This file stores the static model metadata catalog.
Package registry provides centralized model management for all AI service providers. It implements a dynamic model registry with reference counting to track active clients and automatically hide models when no clients are available or when quota is exceeded.
Index ¶
- func GetAntigravityModelConfig() map[string]*antigravityModelConfig
- func SetModelRefreshCallback(cb ModelRefreshCallback)
- func StartModelsUpdater(ctx context.Context)
- type ModelInfo
- func GetAIStudioModels() []*ModelInfo
- func GetClaudeModels() []*ModelInfo
- func GetGeminiCLIModels() []*ModelInfo
- func GetGeminiModels() []*ModelInfo
- func GetGeminiVertexModels() []*ModelInfo
- func GetIFlowModels() []*ModelInfo
- func GetKimiModels() []*ModelInfo
- func GetOpenAIModels() []*ModelInfo
- func GetQwenModels() []*ModelInfo
- func GetStaticModelDefinitionsByChannel(channel string) []*ModelInfo
- func LookupModelInfo(modelID string, provider ...string) *ModelInfo
- func LookupStaticModelInfo(modelID string) *ModelInfo
- type ModelRefreshCallback
- type ModelRegistry
- func (r *ModelRegistry) CleanupExpiredQuotas()
- func (r *ModelRegistry) ClearModelQuotaExceeded(clientID, modelID string)
- func (r *ModelRegistry) ClientSupportsModel(clientID, modelID string) bool
- func (r *ModelRegistry) GetAvailableModels(handlerType string) []map[string]any
- func (r *ModelRegistry) GetAvailableModelsByProvider(provider string) []*ModelInfo
- func (r *ModelRegistry) GetFirstAvailableModel(handlerType string) (string, error)
- func (r *ModelRegistry) GetModelProviders(modelID string) []string
- func (r *ModelRegistry) GetModelsForClient(clientID string) []*ModelInfo
- func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models []*ModelInfo)
- func (r *ModelRegistry) ResumeClientModel(clientID, modelID string)
- func (r *ModelRegistry) SetHook(hook ModelRegistryHook)
- func (r *ModelRegistry) SetModelQuotaExceeded(clientID, modelID string)
- func (r *ModelRegistry) SuspendClientModel(clientID, modelID, reason string)
- func (r *ModelRegistry) UnregisterClient(clientID string)
- type ModelRegistryHook
- type ThinkingSupport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetAntigravityModelConfig ¶
func GetAntigravityModelConfig() map[string]*antigravityModelConfig
GetAntigravityModelConfig returns static configuration for antigravity models. Keys use upstream model names returned by the Antigravity models' endpoint.
func SetModelRefreshCallback ¶
func SetModelRefreshCallback(cb ModelRefreshCallback)
SetModelRefreshCallback registers a callback that is invoked when startup or periodic model refresh detects changes. Only one callback is supported; subsequent calls replace the previous callback. noinspection GoUnusedExportedFunction — public API for external integrations.
func StartModelsUpdater ¶
StartModelsUpdater starts a background updater that fetches models immediately on startup and then refreshes the model catalog every 3 hours. Safe to call multiple times; only one updater will run.
Types ¶
type ModelInfo ¶
type ModelInfo struct {
// ID is the unique identifier for the model
ID string `json:"id"`
// Object type for the model (typically "model")
Object string `json:"object"`
// Created timestamp when the model was created
Created int64 `json:"created"`
// OwnedBy indicates the organization that owns the model
OwnedBy string `json:"owned_by"`
// Type indicates the model type (e.g., "claude", "gemini", "openai")
Type string `json:"type"`
// DisplayName is the human-readable name for the model
DisplayName string `json:"display_name,omitempty"`
// Name is used for Gemini-style model names
Name string `json:"name,omitempty"`
// Version is the model version
Version string `json:"version,omitempty"`
// Description provides detailed information about the model
Description string `json:"description,omitempty"`
// InputTokenLimit is the maximum input token limit
InputTokenLimit int `json:"inputTokenLimit,omitempty"`
// OutputTokenLimit is the maximum output token limit
OutputTokenLimit int `json:"outputTokenLimit,omitempty"`
// SupportedGenerationMethods lists supported generation methods
SupportedGenerationMethods []string `json:"supportedGenerationMethods,omitempty"`
// ContextLength is the context window size
ContextLength int `json:"context_length,omitempty"`
// MaxCompletionTokens is the maximum completion tokens
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
// SupportedParameters lists supported parameters
SupportedParameters []string `json:"supported_parameters,omitempty"`
// SupportedInputModalities lists supported input modalities (e.g., TEXT, IMAGE, VIDEO, AUDIO)
SupportedInputModalities []string `json:"supportedInputModalities,omitempty"`
// SupportedOutputModalities lists supported output modalities (e.g., TEXT, IMAGE)
SupportedOutputModalities []string `json:"supportedOutputModalities,omitempty"`
// Thinking holds provider-specific reasoning/thinking budget capabilities.
// This is optional and currently used for Gemini thinking budget normalization.
Thinking *ThinkingSupport `json:"thinking,omitempty"`
// UserDefined indicates this model was defined through config file's models[]
// array (e.g., openai-compatibility.*.models[], *-api-key.models[]).
// UserDefined models have thinking configuration passed through without validation.
UserDefined bool `json:"-"`
}
ModelInfo represents information about an available model
func GetAIStudioModels ¶
func GetAIStudioModels() []*ModelInfo
GetAIStudioModels returns the Gemini model definitions for AI Studio integrations
func GetClaudeModels ¶
func GetClaudeModels() []*ModelInfo
GetClaudeModels returns the standard Claude model definitions
func GetGeminiCLIModels ¶
func GetGeminiCLIModels() []*ModelInfo
GetGeminiCLIModels returns the standard Gemini model definitions
func GetGeminiModels ¶
func GetGeminiModels() []*ModelInfo
GetGeminiModels returns the standard Gemini model definitions
func GetGeminiVertexModels ¶
func GetGeminiVertexModels() []*ModelInfo
func GetIFlowModels ¶
func GetIFlowModels() []*ModelInfo
GetIFlowModels returns supported models for iFlow OAuth accounts.
func GetKimiModels ¶
func GetKimiModels() []*ModelInfo
GetKimiModels returns the standard Kimi (Moonshot AI) model definitions
func GetOpenAIModels ¶
func GetOpenAIModels() []*ModelInfo
GetOpenAIModels returns the standard OpenAI model definitions
func GetQwenModels ¶
func GetQwenModels() []*ModelInfo
GetQwenModels returns the standard Qwen model definitions
func GetStaticModelDefinitionsByChannel ¶
GetStaticModelDefinitionsByChannel returns static model definitions for a given channel/provider. It returns nil when the channel is unknown.
Supported channels:
- claude
- gemini
- vertex
- gemini-cli
- aistudio
- codex
- qwen
- iflow
- kimi
- antigravity (returns static overrides only)
func LookupModelInfo ¶
LookupModelInfo searches dynamic registry (provider-specific > global) then static definitions.
func LookupStaticModelInfo ¶
LookupStaticModelInfo searches all static model definitions for a model by ID. Returns nil if no matching model is found.
type ModelRefreshCallback ¶
type ModelRefreshCallback func(changedProviders []string)
ModelRefreshCallback is invoked when startup or periodic model refresh detects changes. changedProviders contains the provider names whose model definitions changed.
type ModelRegistry ¶
type ModelRegistry struct {
// contains filtered or unexported fields
}
ModelRegistry manages the global registry of available models
func GetGlobalRegistry ¶
func GetGlobalRegistry() *ModelRegistry
GetGlobalRegistry returns the global model registry instance
func (*ModelRegistry) CleanupExpiredQuotas ¶
func (r *ModelRegistry) CleanupExpiredQuotas()
CleanupExpiredQuotas removes expired quota tracking entries.
func (*ModelRegistry) ClearModelQuotaExceeded ¶
func (r *ModelRegistry) ClearModelQuotaExceeded(clientID, modelID string)
ClearModelQuotaExceeded removes quota exceeded status for a model and client Parameters:
- clientID: The client to clear quota status for
- modelID: The model to clear quota status for
func (*ModelRegistry) ClientSupportsModel ¶
func (r *ModelRegistry) ClientSupportsModel(clientID, modelID string) bool
ClientSupportsModel reports whether the client registered support for modelID.
func (*ModelRegistry) GetAvailableModels ¶
func (r *ModelRegistry) GetAvailableModels(handlerType string) []map[string]any
GetAvailableModels returns all models that have at least one available client Parameters:
- handlerType: The handler type to filter models for (e.g., "openai", "claude", "gemini")
Returns:
- []map[string]any: List of available models in the requested format
func (*ModelRegistry) GetAvailableModelsByProvider ¶
func (r *ModelRegistry) GetAvailableModelsByProvider(provider string) []*ModelInfo
GetAvailableModelsByProvider returns models available for the given provider identifier. Parameters:
- provider: Provider identifier (e.g., "codex", "gemini", "antigravity")
Returns:
- []*ModelInfo: List of available models for the provider
func (*ModelRegistry) GetFirstAvailableModel ¶
func (r *ModelRegistry) GetFirstAvailableModel(handlerType string) (string, error)
GetFirstAvailableModel returns the first available model for the given handler type. It prioritizes models by their creation timestamp (newest first) and checks if they have available clients that are not suspended or over quota.
Parameters:
- handlerType: The API handler type (e.g., "openai", "claude", "gemini")
Returns:
- string: The model ID of the first available model, or empty string if none available
- error: An error if no models are available
func (*ModelRegistry) GetModelProviders ¶
func (r *ModelRegistry) GetModelProviders(modelID string) []string
GetModelProviders returns provider identifiers that currently supply the given model Parameters:
- modelID: The model ID to check
Returns:
- []string: Provider identifiers ordered by availability count (descending)
func (*ModelRegistry) GetModelsForClient ¶
func (r *ModelRegistry) GetModelsForClient(clientID string) []*ModelInfo
GetModelsForClient returns the models registered for a specific client. Parameters:
- clientID: The client identifier (typically auth file name or auth ID)
Returns:
- []*ModelInfo: List of models registered for this client, nil if client not found
func (*ModelRegistry) RegisterClient ¶
func (r *ModelRegistry) RegisterClient(clientID, clientProvider string, models []*ModelInfo)
RegisterClient registers a client and its supported models Parameters:
- clientID: Unique identifier for the client
- clientProvider: Provider name (e.g., "gemini", "claude", "openai")
- models: List of models that this client can provide
func (*ModelRegistry) ResumeClientModel ¶
func (r *ModelRegistry) ResumeClientModel(clientID, modelID string)
ResumeClientModel clears a previous suspension so the client counts toward availability again. Parameters:
- clientID: The client to resume
- modelID: The model being resumed
func (*ModelRegistry) SetHook ¶
func (r *ModelRegistry) SetHook(hook ModelRegistryHook)
SetHook sets an optional hook for observing model registration changes.
func (*ModelRegistry) SetModelQuotaExceeded ¶
func (r *ModelRegistry) SetModelQuotaExceeded(clientID, modelID string)
SetModelQuotaExceeded marks a model as quota exceeded for a specific client Parameters:
- clientID: The client that exceeded quota
- modelID: The model that exceeded quota
func (*ModelRegistry) SuspendClientModel ¶
func (r *ModelRegistry) SuspendClientModel(clientID, modelID, reason string)
SuspendClientModel marks a client's model as temporarily unavailable until explicitly resumed. Parameters:
- clientID: The client to suspend
- modelID: The model affected by the suspension
- reason: Optional description for observability
func (*ModelRegistry) UnregisterClient ¶
func (r *ModelRegistry) UnregisterClient(clientID string)
UnregisterClient removes a client and decrements counts for its models Parameters:
- clientID: Unique identifier for the client to remove
type ModelRegistryHook ¶
type ModelRegistryHook interface {
OnModelsRegistered(ctx context.Context, provider, clientID string, models []*ModelInfo)
OnModelsUnregistered(ctx context.Context, provider, clientID string)
}
ModelRegistryHook provides optional callbacks for external integrations to track model list changes. Hook implementations must be non-blocking and resilient; calls are executed asynchronously and panics are recovered.
type ThinkingSupport ¶
type ThinkingSupport struct {
// Min is the minimum allowed thinking budget (inclusive).
Min int `json:"min,omitempty"`
// Max is the maximum allowed thinking budget (inclusive).
Max int `json:"max,omitempty"`
// ZeroAllowed indicates whether 0 is a valid value (to disable thinking).
ZeroAllowed bool `json:"zero_allowed,omitempty"`
// DynamicAllowed indicates whether -1 is a valid value (dynamic thinking budget).
DynamicAllowed bool `json:"dynamic_allowed,omitempty"`
// Levels defines discrete reasoning effort levels (e.g., "low", "medium", "high").
// When set, the model uses level-based reasoning instead of token budgets.
Levels []string `json:"levels,omitempty"`
}
ThinkingSupport describes a model family's supported internal reasoning budget range. Values are interpreted in provider-native token units.