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
- func FetchCatalog(ctx context.Context, client *http.Client, baseURL, token, accountID string) (map[string]bool, error)
- func ParseCatalog(body []byte) (map[string]bool, error)
- type CatalogCache
- type OpenAI
- func (o *OpenAI) Stream(ctx context.Context, req core.Request) (<-chan core.AssistantEvent, error)
- func (o *OpenAI) SupportsDeferredTools(modelID string) bool
- func (o *OpenAI) SupportsDocuments() bool
- func (o *OpenAI) Transcribe(ctx context.Context, audio io.Reader, filename string, ...) (string, error)
- func (o *OpenAI) WithHTTPClient(c *http.Client) *OpenAI
- type PlanCredentials
- type PlanTranscriber
Constants ¶
const ( // CatalogTTL is how long a catalog read is trusted before it is read again. CatalogTTL = time.Hour )
const CodexBaseURL = codexBaseURL
CodexBaseURL is the plan backend's base URL.
Variables ¶
This section is empty.
Functions ¶
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 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 ¶
NewWithBaseURL creates an OpenAI provider with a custom base URL (for testing).
func (*OpenAI) SupportsDeferredTools ¶ added in v0.48.0
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 ¶
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.
type PlanCredentials ¶ added in v0.47.0
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.