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
- type Config
- type Provider
- func (p *Provider) Capabilities() litellm.Capabilities
- func (p *Provider) Chat(ctx context.Context, req *litellm.Request) (*litellm.Response, error)
- func (p *Provider) ListModels(ctx context.Context) ([]litellm.ModelInfo, error)
- func (p *Provider) Name() string
- func (p *Provider) Stream(ctx context.Context, req *litellm.Request) (litellm.Stream, error)
Constants ¶
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.
const ( ProviderOptionPreviousResponseID = "previous_response_id" ProviderOptionConversation = "conversation" ProviderOptionInclude = "include" ProviderOptionTruncation = "truncation" ProviderOptionMaxToolCalls = "max_tool_calls" // ProviderOptionBackground is supported by Stream only; Chat has no job // polling interface and rejects background=true. 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.
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 (*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) ListModels ¶
ListModels calls GET /models.