Documentation
¶
Overview ¶
Package model talks to LLM providers using a single OpenAI-shaped message format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var PriceOverride [2]float64
PriceOverride, when non-zero, replaces the price table's input and output prices. The table's cache-read multiplier still applies.
var Prices = map[string][3]float64{
"gpt-4o": {2.50, 10.00},
"gpt-4o-mini": {0.15, 0.60},
"gpt-4.1": {2.00, 8.00},
"gpt-4.1-mini": {0.40, 1.60},
"gpt-4.1-nano": {0.10, 0.40},
"claude-sonnet-4": {3.00, 15.00},
"claude-opus-4": {15.00, 75.00},
"claude-haiku-4-5": {1.00, 5.00},
"claude-3-5-haiku": {0.80, 4.00},
"claude-3-7-sonnet": {3.00, 15.00},
"claude-sonnet-5-5": {2.00, 10.00, 0.05},
"claude-opus-5-5": {4.00, 20.00, 0.05},
"claude-fable-5-1": {10.00, 50.00, 0.025},
}
Prices maps a model name prefix to USD per million input/output tokens and, optionally, the cache-read price as a multiple of the input price (0 means the standard 0.1). The longest matching prefix wins. Unknown models cost 0 unless overridden.
Functions ¶
Types ¶
type Anthropic ¶
type Anthropic struct {
BaseURL string
APIKey string
Model string
MaxTokens int // defaults to 8192
OnText func(string) // if set, stream and report text deltas
}
Anthropic speaks the native Messages API.
type Codex ¶
type Codex struct {
BaseURL string
TokenURL string
AuthFile string
Model string
OnText func(string)
// contains filtered or unexported fields
}
Codex uses a ChatGPT subscription instead of an API key. It signs in with the tokens `codex login` saves in $CODEX_HOME/auth.json, refreshes them when they expire (writing them back so the Codex CLI stays signed in), and speaks the Responses API that the Codex backend serves.
type Cost ¶
type Cost struct {
USD float64 `json:"usd"`
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheReadTokens int `json:"cache_read_tokens,omitempty"`
CacheWriteTokens int `json:"cache_write_tokens,omitempty"`
}
Cost is one response's usage. InputTokens counts every input token, including the cache reads and writes broken out after it.
type FunctionCall ¶
type FunctionSpec ¶
type Model ¶
type OpenAI ¶
type OpenAI struct {
BaseURL string
APIKey string
Model string
OnText func(string) // if set, stream and report text deltas
}
OpenAI speaks the Chat Completions API, which also covers OpenRouter, Ollama, and other OpenAI-compatible endpoints.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function FunctionCall `json:"function"`
}
type ToolResult ¶
type ToolSpec ¶
type ToolSpec struct {
Type string `json:"type"`
Function FunctionSpec `json:"function"`
}
ToolSpec is an OpenAI function-calling tool definition.