openai

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

type APIKeyProvider func(ctx context.Context) (string, error)

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

func New(cfg Config) *Client

New creates a Responses API chat.Client. It panics when cfg.Model is empty.

func (*Client) DeleteFile added in v0.2.1

func (c *Client) DeleteFile(ctx context.Context, id string) error

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) Info

func (c *Client) Info() chat.ModelInfo

Info returns the model info.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req chat.Request) iter.Seq[chat.Event]

Stream sends a streaming request.

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.

Jump to

Keyboard shortcuts

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