openai

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
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.

View Source
const (
	EnvOpenAIAPIKey = "OPENAI_API_KEY"
	EnvOpenAIKey    = "OPENAI_KEY" // Alternative env var name
)

Environment variable names for OpenAI configuration.

View Source
const (

	// DefaultModel is the recommended default model (fast and capable).
	DefaultModel = "gpt-4o-mini"
)

Variables

View Source
var ErrUnknownModel = fmt.Errorf("unknown model")

ErrUnknownModel is returned when a model ID is not in the registry.

View Source
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

func DefaultOptions() []llm.Option

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

func MaybeRegister(reg *llm.Registry)

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

func New(opts ...llm.Option) *Provider

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

func (p *Provider) FetchModels(ctx context.Context) ([]llm.Model, error)

FetchModels retrieves the live list of models from the OpenAI API.

func (*Provider) GetDefaultModel added in v0.19.0

func (p *Provider) GetDefaultModel() string

GetDefaultModel returns the configured default model ID.

func (*Provider) Models

func (p *Provider) Models() []llm.Model

Models returns a curated list of well-known OpenAI models.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider identifier.

func (*Provider) WithDefaultModel

func (p *Provider) WithDefaultModel(modelID string) *Provider

WithDefaultModel returns a copy of the provider using the given default model.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL