Documentation
¶
Overview ¶
Package model provides model constants for all supported AI providers.
This package exposes typed model constants with pricing information. Models know their provider, enabling automatic routing in the client.
Chat Models ¶
Use chat models with ai.WithModel() or as client defaults:
import (
ai "github.com/spetersoncode/gains"
"github.com/spetersoncode/gains/client"
"github.com/spetersoncode/gains/model"
)
c := client.New(client.Config{
APIKeys: client.APIKeys{
Anthropic: os.Getenv("ANTHROPIC_API_KEY"),
OpenAI: os.Getenv("OPENAI_API_KEY"),
},
Defaults: client.Defaults{
Chat: model.ClaudeSonnet45,
},
})
// Override with different model (routes to OpenAI)
resp, err := c.Chat(ctx, messages, ai.WithModel(model.GPT52))
Image Models ¶
Use image models for generation:
c := client.New(client.Config{
APIKeys: client.APIKeys{OpenAI: os.Getenv("OPENAI_API_KEY")},
Defaults: client.Defaults{
Image: model.GPTImage1,
},
})
Embedding Models ¶
Use embedding models for vector embeddings:
c := client.New(client.Config{
APIKeys: client.APIKeys{OpenAI: os.Getenv("OPENAI_API_KEY")},
Defaults: client.Defaults{
Embedding: model.TextEmbedding3Small,
},
})
Pricing Information ¶
All models include pricing methods for cost estimation:
pricing := model.GPT52.Pricing() inputCost := float64(inputTokens) / 1_000_000 * pricing.InputPerMillion outputCost := float64(outputTokens) / 1_000_000 * pricing.OutputPerMillion
Provider-Specific Pricing Features ¶
Some pricing fields are provider-specific. Use helper methods to check availability:
pricing := model.GPT52.Pricing()
if pricing.HasCachedPricing() {
// OpenAI models support cached input pricing
cachedCost := float64(cachedTokens) / 1_000_000 * pricing.CachedInputPerMillion
}
pricing := model.Gemini3Pro.Pricing()
if pricing.HasLongContextPricing() {
// Google models have tiered pricing for >200K token contexts
longInputCost := float64(tokens) / 1_000_000 * pricing.InputPerMillionLong
}
Available Providers ¶
Models are available for three providers:
- Anthropic: Claude models (chat only)
- OpenAI: GPT and O-series models (chat, image, embedding)
- Google: Gemini and Imagen models (chat, image, embedding)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // Claude 4.5 Family (Current) - auto-updating aliases ClaudeOpus45 = ChatModel{/* contains filtered or unexported fields */} ClaudeSonnet45 = ChatModel{/* contains filtered or unexported fields */} ClaudeHaiku45 = ChatModel{/* contains filtered or unexported fields */} // Pinned versions (use for production stability) ClaudeOpus45_20251101 = ChatModel{/* contains filtered or unexported fields */} ClaudeSonnet45_20250929 = ChatModel{/* contains filtered or unexported fields */} ClaudeHaiku45_20251001 = ChatModel{/* contains filtered or unexported fields */} // DefaultClaudeModel is the recommended default Anthropic model. DefaultClaudeModel = ClaudeSonnet45 )
Anthropic Claude Models Model pricing last verified: December 14, 2025
var ( // GPT-5.2 Series (Latest - December 2025) GPT52 = ChatModel{/* contains filtered or unexported fields */} GPT52Pro = ChatModel{/* contains filtered or unexported fields */} // GPT-5.1 Series GPT51 = ChatModel{/* contains filtered or unexported fields */} GPT51Mini = ChatModel{/* contains filtered or unexported fields */} GPT51Codex = ChatModel{/* contains filtered or unexported fields */} // GPT-5 Series GPT5 = ChatModel{/* contains filtered or unexported fields */} GPT5Mini = ChatModel{/* contains filtered or unexported fields */} GPT5Nano = ChatModel{/* contains filtered or unexported fields */} GPT5Pro = ChatModel{/* contains filtered or unexported fields */} // O-Series Reasoning Models O3 = ChatModel{/* contains filtered or unexported fields */} O3Mini = ChatModel{/* contains filtered or unexported fields */} O4Mini = ChatModel{/* contains filtered or unexported fields */} // DefaultGPTModel is the recommended default OpenAI model. DefaultGPTModel = GPT52 )
OpenAI GPT and O-Series Models Model pricing last verified: December 14, 2025
var ( // Gemini 3.0 (Latest - November 2025) Gemini3Pro = ChatModel{/* contains filtered or unexported fields */} Gemini3FlashPreview = ChatModel{/* contains filtered or unexported fields */} Gemini3DeepThink = ChatModel{/* contains filtered or unexported fields */} // Gemini 2.5 Series Gemini25Pro = ChatModel{/* contains filtered or unexported fields */} Gemini25Flash = ChatModel{/* contains filtered or unexported fields */} Gemini25FlashLite = ChatModel{/* contains filtered or unexported fields */} // DefaultGeminiModel is the recommended default Google model. DefaultGeminiModel = Gemini25Flash // Gemini Image Models (chat models that support image output via ResponseModalities) // Use these with WithImageOutput() to generate images in chat responses. Gemini25FlashImage = ChatModel{/* contains filtered or unexported fields */} Gemini3ProImagePreview = ChatModel{/* contains filtered or unexported fields */} )
Google Gemini Models Model pricing last verified: December 19, 2025
var ( // Vertex Gemini 3.0 (Latest - November 2025) VertexGemini3Pro = ChatModel{/* contains filtered or unexported fields */} VertexGemini3FlashPreview = ChatModel{/* contains filtered or unexported fields */} VertexGemini3DeepThink = ChatModel{/* contains filtered or unexported fields */} // Vertex Gemini 2.5 Series VertexGemini25Pro = ChatModel{/* contains filtered or unexported fields */} VertexGemini25Flash = ChatModel{/* contains filtered or unexported fields */} VertexGemini25FlashLite = ChatModel{/* contains filtered or unexported fields */} // DefaultVertexModel is the recommended default Vertex AI model. DefaultVertexModel = VertexGemini25Flash // Vertex Gemini Image Models (chat models that support image output via ResponseModalities) // Use these with WithImageOutput() to generate images in chat responses. VertexGemini25FlashImage = ChatModel{/* contains filtered or unexported fields */} VertexGemini3ProImagePreview = ChatModel{/* contains filtered or unexported fields */} )
Google Vertex AI Models (same models as Gemini, but via Vertex AI backend) Vertex AI uses Application Default Credentials instead of API keys. Model pricing last verified: December 19, 2025
var ( // Text Embedding 3 Series TextEmbedding3Large = EmbeddingModel{/* contains filtered or unexported fields */} TextEmbedding3Small = EmbeddingModel{/* contains filtered or unexported fields */} // DefaultOpenAIEmbeddingModel is the recommended default OpenAI embedding model. DefaultOpenAIEmbeddingModel = TextEmbedding3Small )
OpenAI Embedding Models Model pricing last verified: December 14, 2025
var ( // Gemini Embedding GeminiEmbedding001 = EmbeddingModel{/* contains filtered or unexported fields */} // DefaultGoogleEmbeddingModel is the recommended default Google embedding model. DefaultGoogleEmbeddingModel = GeminiEmbedding001 )
Google Embedding Models Model pricing last verified: December 14, 2025
var ( // Vertex Gemini Embedding VertexGeminiEmbedding001 = EmbeddingModel{/* contains filtered or unexported fields */} // DefaultVertexEmbeddingModel is the recommended default Vertex AI embedding model. DefaultVertexEmbeddingModel = VertexGeminiEmbedding001 )
Google Vertex AI Embedding Models (via Vertex AI backend) Vertex AI uses Application Default Credentials instead of API keys. Model pricing last verified: December 14, 2025
var ( // GPT Image 1.5 Series GPTImage15 = ImageModel{/* contains filtered or unexported fields */} // GPT Image 1 Series GPTImage1 = ImageModel{/* contains filtered or unexported fields */} GPTImage1Mini = ImageModel{/* contains filtered or unexported fields */} // DefaultGPTImageModel is the recommended default OpenAI image model. DefaultGPTImageModel = GPTImage15 )
OpenAI Image Models Model pricing last verified: December 19, 2025
var ( // Imagen 4 Series Imagen4 = ImageModel{/* contains filtered or unexported fields */} Imagen4Fast = ImageModel{/* contains filtered or unexported fields */} Imagen4Ultra = ImageModel{/* contains filtered or unexported fields */} // DefaultImagenModel is the recommended default Google image model. DefaultImagenModel = Imagen4 )
Google Imagen Models (use GenerateImages API) Note: Gemini native image models (gemini-*-image) use Chat with WithImageOutput() instead. Model pricing last verified: December 19, 2025
var ( // Vertex Imagen 4 Series VertexImagen4 = ImageModel{/* contains filtered or unexported fields */} VertexImagen4Fast = ImageModel{/* contains filtered or unexported fields */} VertexImagen4Ultra = ImageModel{/* contains filtered or unexported fields */} // DefaultVertexImageModel is the recommended default Vertex AI image model. DefaultVertexImageModel = VertexImagen4 )
Google Vertex AI Imagen Models (use GenerateImages API via Vertex AI backend) Vertex AI uses Application Default Credentials instead of API keys. Note: Gemini native image models (gemini-*-image) use Chat with WithImageOutput() instead. Model pricing last verified: December 19, 2025
Functions ¶
func CalculateCost ¶ added in v0.2.5
func CalculateCost(usage ai.Usage, pricing ChatPricing) float64
CalculateCost computes the cost in USD for the given token usage and pricing. Uses standard per-million token rates; does not account for cached input tokens or long context tiers.
Types ¶
type ChatModel ¶
type ChatModel struct {
// contains filtered or unexported fields
}
ChatModel represents a chat/completion model from any provider.
func (ChatModel) Cost ¶ added in v0.2.5
Cost calculates the cost in USD for the given token usage. Uses standard per-million token rates; does not account for cached input tokens or long context tiers which require extended usage tracking.
func (ChatModel) Pricing ¶
func (m ChatModel) Pricing() ChatPricing
Pricing returns the pricing for this model.
func (ChatModel) SupportsImageOutput ¶ added in v0.2.10
SupportsImageOutput returns true if this model can generate images in chat responses when WithImageOutput() is enabled.
type ChatPricing ¶
type ChatPricing struct {
// InputPerMillion is the standard input token pricing (all providers).
InputPerMillion float64
// OutputPerMillion is the standard output token pricing (all providers).
OutputPerMillion float64
// CachedInputPerMillion is for cached/prompt-cached input tokens (OpenAI only).
// Check HasCachedPricing() before using.
CachedInputPerMillion float64
// InputPerMillionLong is for long context >200K tokens (Google only).
// Check HasLongContextPricing() before using.
InputPerMillionLong float64
// OutputPerMillionLong is for long context >200K tokens (Google only).
// Check HasLongContextPricing() before using.
OutputPerMillionLong float64
}
ChatPricing contains pricing per million tokens (USD) for chat models. Fields are zero if not applicable to a specific provider's model.
func (ChatPricing) HasCachedPricing ¶
func (p ChatPricing) HasCachedPricing() bool
HasCachedPricing returns true if the model supports cached input pricing.
func (ChatPricing) HasLongContextPricing ¶
func (p ChatPricing) HasLongContextPricing() bool
HasLongContextPricing returns true if the model has tiered pricing for long context.
type EmbeddingModel ¶
type EmbeddingModel struct {
// contains filtered or unexported fields
}
EmbeddingModel represents an embedding model from any provider.
func (EmbeddingModel) Dimensions ¶
func (m EmbeddingModel) Dimensions() int
Dimensions returns the output vector dimensions for this model.
func (EmbeddingModel) Pricing ¶
func (m EmbeddingModel) Pricing() EmbeddingPricing
Pricing returns the pricing for this model.
func (EmbeddingModel) Provider ¶
func (m EmbeddingModel) Provider() ai.Provider
Provider returns which provider this model belongs to.
func (EmbeddingModel) String ¶
func (m EmbeddingModel) String() string
String returns the API identifier for this model.
type EmbeddingPricing ¶
type EmbeddingPricing struct {
// PerMillion is the price per million tokens.
PerMillion float64
}
EmbeddingPricing contains embedding pricing per million tokens (USD).
type ImageModel ¶
type ImageModel struct {
// contains filtered or unexported fields
}
ImageModel represents an image generation model from any provider.
func (ImageModel) Pricing ¶
func (m ImageModel) Pricing() ImagePricing
Pricing returns the pricing for this model.
func (ImageModel) Provider ¶
func (m ImageModel) Provider() ai.Provider
Provider returns which provider this model belongs to.
func (ImageModel) String ¶
func (m ImageModel) String() string
String returns the API identifier for this model.
type ImagePricing ¶
type ImagePricing struct {
// PerImage is a flat per-image price (Google Imagen).
PerImage float64
// LowQuality is the price for low quality images (OpenAI).
LowQuality float64
// MediumQuality is the price for medium quality images (OpenAI).
MediumQuality float64
// HighQuality is the price for high quality images (OpenAI).
HighQuality float64
}
ImagePricing contains image generation pricing (USD). Different providers use different pricing models.
func (ImagePricing) HasFlatPricing ¶
func (p ImagePricing) HasFlatPricing() bool
HasFlatPricing returns true if the model uses flat per-image pricing.
func (ImagePricing) HasQualityTiers ¶
func (p ImagePricing) HasQualityTiers() bool
HasQualityTiers returns true if the model has quality-based pricing tiers.