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 Config
Constants ¶
const ( // API is the protocol this client speaks, see chat.ModelInfo.API. API = "openai-responses" ModelGPT6Luna = "gpt-6-luna" )
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 (*Client) DeleteFile ¶ added in v0.2.1
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 ¶ added in v0.2.1
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 Config ¶
type Config struct {
// Provider names the vendor in messages, usage and errors; "openai" by default. Set it for compatible endpoints.
Provider string
APIKey string
APIKeyProvider APIKeyProvider
BaseURL string
Model string
MaxInputTokens int
MaxOutputTokens int
Timeout time.Duration
MaxRetries int
Headers map[string]string
HTTPClient *http.Client
// Reasoning means the model is a reasoning model: requests ask for reasoning.summary and for encrypted reasoning content,
// so history can be replayed statelessly. Regular models reject these parameters, so it is off by default.
Reasoning bool
// 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
// DisableStoreParams means the endpoint does not recognize the store / include parameters (such as DeepSeek), so they are not sent.
DisableStoreParams bool
// TextOnly means the endpoint accepts no media input.
TextOnly bool
// NoStructuredOutput means the endpoint does not support the json_schema output format; the format requirements go into the system prompt instead.
NoStructuredOutput 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.