openai

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package openai provides an OpenAI API client implementing the ai.Provider interface. It supports both Chat Completions API and Responses API (for codex models).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIType

type APIType string

APIType indicates which OpenAI API to use.

const (
	// APIChatCompletions uses the /v1/chat/completions endpoint.
	APIChatCompletions APIType = "chat"

	// APIResponses uses the /v1/responses endpoint (for codex models).
	APIResponses APIType = "responses"
)

type Client

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

Client implements ai.Provider for OpenAI's APIs. It supports both Chat Completions and Responses APIs.

func NewClient

func NewClient(apiKey string, opts ...ClientOption) *Client

NewClient creates a new OpenAI client.

func (*Client) Generate

func (c *Client) Generate(ctx context.Context, req *ai.Request) (*ai.Response, error)

Generate implements ai.Provider. It routes to either Chat Completions or Responses API based on the model.

func (*Client) Name

func (c *Client) Name() string

Name implements ai.Provider.

func (*Client) NewHandler

func (c *Client) NewHandler(model string, opts ...ai.HandlerOption) *ai.Handler

NewHandler creates an ai.Handler wrapping this client.

type ClientOption

type ClientOption func(*Client)

ClientOption configures a Client.

func WithAPIType

func WithAPIType(apiType APIType) ClientOption

WithAPIType forces a specific API type (chat or responses).

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL sets a custom base URL (useful for testing).

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient sets a custom HTTP client.

Jump to

Keyboard shortcuts

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