openai

package
v0.63.13 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 11 Imported by: 2

Documentation

Overview

ABOUTME: OpenAI Responses API adapter implementing the ProviderAdapter interface. ABOUTME: Handles HTTP communication, SSE stream parsing, and request/response lifecycle.

ABOUTME: SSE stream event types and handlers for the OpenAI Responses API. ABOUTME: Split from adapter.go to keep files under 500 lines.

ABOUTME: Request/response translation between the unified llm types and OpenAI Responses API format. ABOUTME: Handles instructions extraction, flat input array mapping, tool definitions, and finish reasons.

ABOUTME: Translates OpenAI Responses API usage into the unified llm.Usage shape. ABOUTME: Both cache classes and reasoning arrive nested inside the top-level counts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Adapter

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

Adapter implements llm.ProviderAdapter for the OpenAI Responses API.

func New

func New(apiKey string, opts ...Option) *Adapter

New creates a new OpenAI adapter with the given API key and options.

func (*Adapter) Close

func (a *Adapter) Close() error

Close releases resources held by the adapter.

func (*Adapter) Complete

func (a *Adapter) Complete(ctx context.Context, req *llm.Request) (*llm.Response, error)

Complete sends a synchronous request to the OpenAI Responses API.

func (*Adapter) Name

func (a *Adapter) Name() string

Name returns the provider identifier.

func (*Adapter) Stream

func (a *Adapter) Stream(ctx context.Context, req *llm.Request) <-chan llm.StreamEvent

Stream sends a streaming request and returns a channel of events.

type Option

type Option func(*Adapter)

Option configures an Adapter.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the default OpenAI API base URL.

func WithExtraHeaders

func WithExtraHeaders(headers map[string]string) Option

WithExtraHeaders adds custom headers to every request. Useful for gateway authentication (e.g., cf-aig-token for Cloudflare AI Gateway).

func WithHTTPClient

func WithHTTPClient(client *http.Client) Option

WithHTTPClient provides a custom http.Client.

Jump to

Keyboard shortcuts

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