openai

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 23 Imported by: ? 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 core.Provider for the OpenAI Responses API. Supports GPT and Codex models with streaming, tool use, and reasoning effort. Works with both API keys (api.openai.com) and OAuth (chatgpt.com/backend-api).

Index

Constants

View Source
const (

	// CatalogTTL is how long a catalog read is trusted before it is read again.
	CatalogTTL = time.Hour
)
View Source
const CodexBaseURL = codexBaseURL

CodexBaseURL is the plan backend's base URL.

Variables

This section is empty.

Functions

func FetchCatalog added in v0.47.0

func FetchCatalog(ctx context.Context, client *http.Client, baseURL, token, accountID string) (map[string]bool, error)

FetchCatalog reads the account's model catalog from the plan backend with the same identity headers the Responses requests use.

func ParseCatalog added in v0.47.0

func ParseCatalog(body []byte) (map[string]bool, error)

ParseCatalog reads which models the account's catalog offers with Daybreak: models[].slug, and whether models[].available_access_programs.cyber lists core.DaybreakAccessProgram.

Types

type CatalogCache added in v0.47.0

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

CatalogCache keeps the last good catalog read. Snapshot never waits on the network: a stale or missing catalog is read again in the background, and a failed read keeps the previous answer.

func NewCatalogCache added in v0.47.0

func NewCatalogCache(fetch func(context.Context) (map[string]bool, error), transport func() bool, ttl time.Duration) *CatalogCache

NewCatalogCache builds a cache over fetch. transport reports whether the selected credential is the plan's OAuth (nil = never).

func (*CatalogCache) Refresh added in v0.47.0

func (c *CatalogCache) Refresh(ctx context.Context) error

Refresh reads the catalog now. On failure the last good catalog stays.

func (*CatalogCache) Snapshot added in v0.47.0

func (c *CatalogCache) Snapshot() core.DaybreakAvailability

Snapshot returns what is known now and starts a background read when the catalog is missing or stale. Without the plan transport nothing is read.

type OpenAI

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

OpenAI implements core.Provider for the OpenAI Responses API.

func New

func New(apiKey string) *OpenAI

New creates an OpenAI provider using an API key (api.openai.com).

func NewOAuth

func NewOAuth(accessToken, accountID string, refresh func(ctx context.Context, rejectedToken string) (string, error)) *OpenAI

NewOAuth creates an OpenAI provider using ChatGPT subscription OAuth. Uses chatgpt.com/backend-api with the /codex/responses endpoint.

func NewWithBaseURL

func NewWithBaseURL(apiKey, baseURL string) *OpenAI

NewWithBaseURL creates an OpenAI provider with a custom base URL (for testing).

func (*OpenAI) Stream

func (o *OpenAI) Stream(ctx context.Context, req core.Request) (<-chan core.AssistantEvent, error)

Stream sends a request and returns a channel of normalized AssistantEvents.

func (*OpenAI) SupportsDeferredTools added in v0.48.0

func (o *OpenAI) SupportsDeferredTools(modelID string) bool

SupportsDeferredTools reports whether modelID loads deferred tools through tool_search: on the plan transport, where it was probed for every model the plan serves (GPT-5.4 and later), unless a request was already refused for it (see Stream). The paid API was never probed and keeps the full list.

func (*OpenAI) SupportsDocuments

func (o *OpenAI) SupportsDocuments() bool

SupportsDocuments returns true only for the API-key path (/v1/responses): the codex OAuth path (/codex/responses) is unverified for input_file.

func (*OpenAI) Transcribe

func (o *OpenAI) Transcribe(ctx context.Context, audio io.Reader, filename string, opts core.TranscribeOptions) (string, error)

Transcribe sends audio to the OpenAI transcription API and returns the text. filename should include the extension (e.g. "audio.webm") so the API can detect the format. Supported formats: mp3, mp4, mpeg, mpga, m4a, wav, webm, ogg.

opts.Model selects the transcription model; empty falls back to the package default. Note that response_format stays "json": the newer models reject "verbose_json", and we only ever read the text field anyway.

func (*OpenAI) WithHTTPClient added in v0.46.0

func (o *OpenAI) WithHTTPClient(c *http.Client) *OpenAI

WithHTTPClient replaces the HTTP client while keeping the pinned endpoint. It is a server-side seam for tests that route the fixed origin locally.

type PlanCredentials added in v0.47.0

type PlanCredentials func(ctx context.Context) (token, accountID string, err error)

PlanCredentials returns the current ChatGPT OAuth access token and account id. It owns refreshing (the auth store serialises it with every other user of the credential), so the transcriber never rotates tokens itself.

type PlanTranscriber added in v0.47.0

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

PlanTranscriber dictates through the ChatGPT subscription: the endpoint the Codex desktop app uses, reached with the user's OAuth login instead of a billed API key. The service picks the model; opts.Model is ignored.

func NewPlanTranscriber added in v0.47.0

func NewPlanTranscriber(creds PlanCredentials) *PlanTranscriber

func (*PlanTranscriber) Transcribe added in v0.47.0

func (p *PlanTranscriber) Transcribe(parent context.Context, audio io.Reader, filename string, opts core.TranscribeOptions) (string, error)

Transcribe errors are fixed strings with a safe category (see transcribeError): callers log and return them.

Jump to

Keyboard shortcuts

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