openai

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 20 Imported by: 1 module, 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 the text and function-tool subset of the OpenAI-compatible streaming Chat Completions protocol.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrProtocol    = errors.New("openai: invalid or unsupported streaming response")
	ErrIncomplete  = errors.New("openai: incomplete model response")
	ErrRemote      = errors.New("openai: provider reported an error")
	ErrLimit       = errors.New("openai: response exceeds protocol limits")
	ErrTransport   = errors.New("openai: request or stream transport failed")
	ErrUnsupported = errors.New("openai: model requires an unsupported response mode")
)

Functions

This section is empty.

Types

type Client

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

Client is immutable after construction and supports concurrent completions provided its supplied HTTP transport supports concurrent use.

func New

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

New configures one provider endpoint. Redirects and automatic retries are deliberately not enabled. A supplied HTTP client is shallow-copied.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, req agent.ModelRequest, emit func(string) error) (agent.ModelResponse, error)

Complete sends one request and assembles a complete response from SSE events. No partial tool calls are returned as executable results after failure.

type Config

type Config struct {
	BaseURL      string
	Model        string
	APIKey       string
	HTTPClient   *http.Client
	IncludeUsage bool
}

Config is explicit: no environment lookup or default remote destination. BaseURL includes the API prefix, such as https://api.openai.com/v1. HTTP is accepted only for loopback hosts. IncludeUsage requests the optional streaming usage extension; disable it for endpoints that do not implement it.

type HTTPError

type HTTPError struct{ StatusCode int }

HTTPError reports a non-success status without exposing the provider's body.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type ResponsesClient

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

ResponsesClient implements Model for the Responses API without server-side conversation IDs. Native history is an explicit same-context opt-in.

func NewResponses

func NewResponses(cfg ResponsesConfig) (*ResponsesClient, error)

func (*ResponsesClient) Complete

func (c *ResponsesClient) Complete(ctx context.Context, req agent.ModelRequest, emit func(string) error) (agent.ModelResponse, error)

func (*ResponsesClient) NativeHistoryFormat

func (c *ResponsesClient) NativeHistoryFormat() string

type ResponsesConfig

type ResponsesConfig struct {
	BaseURL         string
	Model           string
	APIKey          string
	MaxOutputTokens int64
	HTTPClient      *http.Client
	// NativeHistoryScope opts into native output items for one trusted provider
	// account/context. Use a non-secret label; never reuse it across accounts.
	NativeHistoryScope string
}

ResponsesConfig selects the stateless Responses subset. MaxOutputTokens must be positive. Only caller-registered functions are sent.

Jump to

Keyboard shortcuts

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