Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultOptions() []llm.Option
- func MaybeRegister(reg *llm.Registry)
- type Provider
- func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)
- func (p *Provider) FetchModels(ctx context.Context) ([]llm.Model, error)
- func (p *Provider) GetDefaultModel() string
- func (p *Provider) Models() []llm.Model
- func (p *Provider) Name() string
- func (p *Provider) WithDefaultModel(modelID string) *Provider
Constants ¶
const ( // GPT-5.4 series (flagship, latest) ModelGPT54 = "gpt-5.4" ModelGPT54Mini = "gpt-5.4-mini" ModelGPT54Nano = "gpt-5.4-nano" ModelGPT54Pro = "gpt-5.4-pro" // GPT-5.3 series ModelGPT53Codex = "gpt-5.3-codex" // GPT-5.2 series ModelGPT52 = "gpt-5.2" ModelGPT52Pro = "gpt-5.2-pro" ModelGPT52Codex = "gpt-5.2-codex" // GPT-5.1 series ModelGPT51 = "gpt-5.1" ModelGPT51Codex = "gpt-5.1-codex" ModelGPT51CodexMax = "gpt-5.1-codex-max" ModelGPT51CodexMini = "gpt-5.1-codex-mini" // GPT-5 series ModelGPT5 = "gpt-5" ModelGPT5Mini = "gpt-5-mini" ModelGPT5Nano = "gpt-5-nano" ModelGPT5Pro = "gpt-5-pro" ModelGPT5Codex = "gpt-5-codex" // GPT-4o series ModelGPT4o = "gpt-4o" ModelGPT4oMini = "gpt-4o-mini" // GPT-4.1 series ModelGPT41 = "gpt-4.1" ModelGPT41Mini = "gpt-4.1-mini" ModelGPT41Nano = "gpt-4.1-nano" // Legacy models ModelGPT4Turbo = "gpt-4-turbo" ModelGPT4 = "gpt-4" ModelGPT35 = "gpt-3.5-turbo" // o-series reasoning models ModelO4Mini = "o4-mini" ModelO3 = "o3" ModelO3Mini = "o3-mini" ModelO3Pro = "o3-pro" ModelO1 = "o1" ModelO1Mini = "o1-mini" ModelO1Pro = "o1-pro" )
Model ID constants for programmatic use.
const ( EnvOpenAIAPIKey = "OPENAI_API_KEY" EnvOpenAIKey = "OPENAI_KEY" // Alternative env var name )
Environment variable names for OpenAI configuration.
const (
// DefaultModel is the recommended default model (fast and capable).
DefaultModel = "gpt-4o-mini"
)
Variables ¶
var ErrUnknownModel = fmt.Errorf("unknown model")
ErrUnknownModel is returned when a model ID is not in the registry.
var ModelAliases = map[string]string{ "flagship": ModelGPT54, "mini": ModelGPT54Mini, "nano": ModelGPT54Nano, "pro": ModelGPT54Pro, "codex": ModelGPT53Codex, "o4": ModelO4Mini, "o3": ModelO3, }
ModelAliases maps short alias names to full model IDs. These are used by the auto package for provider-prefixed resolution (e.g., "openai/mini").
Functions ¶
func DefaultOptions ¶ added in v0.12.0
DefaultOptions returns the default options for the OpenAI provider. The API key is read from OPENAI_API_KEY or OPENAI_KEY environment variables.
func MaybeRegister ¶ added in v0.13.0
MaybeRegister registers the OpenAI provider if an API key is available. Checks OPENAI_API_KEY and OPENAI_KEY environment variables.
Types ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the OpenAI LLM backend. It dispatches to the Responses API for Codex models and to Chat Completions for everything else.
func New ¶
New creates a new OpenAI provider with the given options applied on top of DefaultOptions.
func (*Provider) CreateStream ¶
func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)
Stream dispatches to the Responses API for Codex models, and to Chat Completions for everything else.
Reasoning effort is validated and mapped before the request is forwarded. Unknown models (not in the registry) default to Chat Completions so that newly released non-Codex models work without a registry update.
func (*Provider) FetchModels ¶ added in v0.19.0
FetchModels retrieves the live list of models from the OpenAI API.
func (*Provider) GetDefaultModel ¶ added in v0.19.0
GetDefaultModel returns the configured default model ID.
func (*Provider) WithDefaultModel ¶
WithDefaultModel returns a copy of the provider using the given default model.