openai

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 14 Imported by: 2

Documentation

Overview

Package openai connects to the OpenAI API, or any endpoint that implements it exactly (such as Azure OpenAI), through Chat Completions or Responses. Use provider/compat for other OpenAI-compatible servers.

Index

Constants

View Source
const (
	ProviderOptionFrequencyPenalty     = "frequency_penalty"
	ProviderOptionPresencePenalty      = "presence_penalty"
	ProviderOptionLogitBias            = "logit_bias"
	ProviderOptionN                    = "n"
	ProviderOptionLogprobs             = "logprobs"
	ProviderOptionTopLogprobs          = "top_logprobs"
	ProviderOptionStore                = "store"
	ProviderOptionModeration           = "moderation"
	ProviderOptionStreamOptions        = "stream_options"
	ProviderOptionPromptCacheKey       = "prompt_cache_key"
	ProviderOptionPromptCacheOptions   = "prompt_cache_options"
	ProviderOptionPromptCacheRetention = "prompt_cache_retention"
	ProviderOptionPrediction           = "prediction"
	ProviderOptionMetadata             = "metadata"
	ProviderOptionModalities           = "modalities"
	ProviderOptionAudio                = "audio"
	ProviderOptionServiceTier          = "service_tier"
	ProviderOptionSafetyIdentifier     = "safety_identifier"
	ProviderOptionUser                 = "user"
	ProviderOptionVerbosity            = "verbosity"
	ProviderOptionWebSearchOptions     = "web_search_options"
	ProviderOptionParallelToolCalls    = "parallel_tool_calls"
	ProviderOptionSeed                 = "seed"
)

ProviderOptions are native request fields of the selected API, copied into the body as is. An option naming a generated object or array (such as Responses "text", "reasoning" or "tools") is merged into or appended to it.

View Source
const (
	ProviderOptionPreviousResponseID = "previous_response_id"
	ProviderOptionConversation       = "conversation"
	ProviderOptionInclude            = "include"
	ProviderOptionTruncation         = "truncation"
	ProviderOptionMaxToolCalls       = "max_tool_calls"
	ProviderOptionBackground         = "background"
	ProviderOptionContextManagement  = "context_management"
	ProviderOptionPrompt             = "prompt"
	// ProviderOptionText is merged into the generated text object, e.g.
	// {"verbosity": "low"}.
	ProviderOptionText = "text"
	// ProviderOptionReasoning is merged into the generated reasoning object,
	// e.g. {"summary": "auto"}.
	ProviderOptionReasoning = "reasoning"
	// ProviderOptionTools is appended to the generated tools, e.g. hosted
	// tools such as [{"type": "web_search"}].
	ProviderOptionTools = "tools"
)

Responses API options (Config.API = APIResponses) not listed above.

View Source
const (
	APIChat      = "chat"
	APIResponses = "responses"
)

Config.API values.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// API selects Chat Completions (APIChat, the default) or APIResponses.
	API string
	// APIKey authenticates requests; APIKeyFunc, when set, resolves it per
	// request instead.
	APIKey     string
	APIKeyFunc func(context.Context) (string, error)
	// BaseURL is the API root, https://api.openai.com/v1 by default.
	BaseURL string
	// HTTPClient sends requests; nil uses http.DefaultClient. Wrap it with
	// retry.NewHTTPClient to retry.
	HTTPClient litellm.HTTPClient
	UserAgent  string
	// Headers are set after the defaults, so they can override them.
	Headers map[string]string
}

Config configures the OpenAI client. An API key is required.

type Provider

type Provider struct {
	// contains filtered or unexported fields
}

Provider implements litellm.Provider, litellm.CapabilityProvider and litellm.ModelLister.

func New

func New(cfg Config) (*Provider, error)

New returns a Provider for cfg.

func (*Provider) Capabilities added in v1.8.1

func (p *Provider) Capabilities() litellm.Capabilities

Capabilities reports the static protocol facts of the selected API.

func (*Provider) Chat

func (p *Provider) Chat(ctx context.Context, req *litellm.Request) (*litellm.Response, error)

Chat sends the request through the selected API.

func (*Provider) ListModels

func (p *Provider) ListModels(ctx context.Context) ([]litellm.ModelInfo, error)

ListModels calls GET /models.

func (*Provider) Name

func (p *Provider) Name() string

Name returns "openai".

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req *litellm.Request) (litellm.Stream, error)

Stream sends a streaming request through the selected API.

Jump to

Keyboard shortcuts

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