Documentation
¶
Overview ¶
Package openai implements chat.Client with the OpenAI Responses API; it also works with endpoints compatible with the Responses API (such as DeepSeek).
Index ¶
- Constants
- type APIKeyProvider
- type Client
- func (c *Client) DeleteFile(ctx context.Context, id string) error
- func (c *Client) Info() chat.ModelInfo
- func (c *Client) Stream(ctx context.Context, req chat.Request) iter.Seq[chat.Event]
- func (c *Client) UploadFile(ctx context.Context, name, mimeType string, r io.Reader, ttl time.Duration) (chat.ContentBlock, error)
- type Compat
- type Config
- type Endpoint
- type Model
Constants ¶
const (
// API is the protocol this client speaks, see chat.ModelInfo.API.
API = "openai-responses"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyProvider ¶
APIKeyProvider resolves the API key dynamically, for short-lived tokens.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Responses API of the OpenAI SDK.
func New ¶
New creates a Responses API chat.Client. It returns an error when cfg.Model.Name is empty.
func (*Client) DeleteFile ¶
DeleteFile deletes an uploaded file. Messages in history that still refer to it fail on the OpenAI side, so drop or replace those references first, or keep a fallback on the blocks.
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, name, mimeType string, r io.Reader, ttl time.Duration) (chat.ContentBlock, error)
UploadFile uploads a file to the Files API with purpose user_data and returns a media block referring to it, ready to put in a message. A ttl of 0 keeps the file until it is deleted; otherwise it must be between one hour and 30 days. The returned block has no fallback: to keep the session usable on other models, set its URL or data too.
type Compat ¶
type Compat struct {
// NoMedia means media input is not accepted; media is replaced with a note before the request is sent.
NoMedia bool
// NoReasoning means the model is not a reasoning model and rejects the reasoning parameters: requests ask for no
// reasoning.summary and no encrypted reasoning content, and chat.Options.Reasoning is ignored.
NoReasoning bool
// NoStoreParams means the store / include parameters are not recognized, so they are not sent.
NoStoreParams bool
// NoStructuredOutput means the json_schema output format is not supported; the format requirements go into the
// system prompt instead.
NoStructuredOutput bool
// NoToolSearch means there is no hosted tool search (it needs gpt-5.4 or later), so deferred tools
// (chat.ToolDef.Deferred) are sent up front.
NoToolSearch bool
}
Compat lists what is missing compared with the full OpenAI Responses API, as its current models speak it. The zero value lacks nothing. It is set on an Endpoint for what holds for every model of the service and on a Model for what holds for that model only; a Client lacks whatever either of them lacks.
type Config ¶
type Config struct {
// Endpoint is the service the client talks to: the zero value is OpenAI's own, and a compatible
// endpoint is described by filling one in.
Endpoint Endpoint
// Model is the model the client talks to; its Name must be set. Another model is another Client.
Model Model
APIKey string
APIKeyProvider APIKeyProvider
Timeout time.Duration
MaxRetries int
Headers map[string]string
HTTPClient *http.Client
// ImageGeneration enables the built-in image_generation tool so the model can generate images in its replies.
// Images in assistant messages in history (including those generated by other models) are replayed as input_image in a user message regardless of this setting.
ImageGeneration bool
// FileScope names the Files API store this key reads, see chat.FileRef.Scope. It defaults to "openai" for the
// official endpoint and to none for a custom BaseURL; set it per project when keys of several projects are in use.
FileScope string
// HTTPHooks are debugging hooks at the raw HTTP layer.
HTTPHooks chat.HTTPHooks
}
Config configures the Responses API Client.
type Endpoint ¶
type Endpoint struct {
// Provider names the vendor in messages, usage and errors; "openai" by default.
Provider string
// BaseURL is the address of the API; empty for OpenAI's.
BaseURL string
// Compat says where every model of the endpoint differs from the full protocol; see Compat.
Compat Compat
}
Endpoint is a service that speaks the OpenAI Responses API: OpenAI itself (the zero value) or a compatible one. It says where the service is; the model served from it is described by Model.
type Model ¶ added in v0.3.0
type Model struct {
// Name is the model name sent to the API.
Name string
// MaxInputTokens is the context limit of the model; 0 declares none, and the runner then never compacts history.
MaxInputTokens int
// MaxOutputTokens is the output limit of the model. It is used as max_output_tokens when a request sets no MaxTokens;
// 0 declares none and the request then sends no limit.
MaxOutputTokens int
// Compat says where this model differs from the full protocol; see Compat.
Compat Compat
}
Model is the model a Client talks to. Beyond the zero value only Name must be set: a model is taken to support the whole protocol, and one that does not says what it lacks in Compat.