Documentation
¶
Overview ¶
Package openaiwire is the OpenAI Responses API adapter — the ONE implementation of the Responses dialect (request encoding, streaming decode, reasoning-item round-trip, tool calls, usage parsing), shared by the hosted gateway (which injects its own or the user's BYOK key) and the CLI's direct endpoint mode (api.openai.com / api.x.ai). Extracted verbatim from the gateway's internal provider package; transport encoding only — no routing policy, no metering.
Index ¶
- Constants
- type Grok
- type OpenAI
- func (o *OpenAI) BaseURL() string
- func (o *OpenAI) Complete(ctx context.Context, r wire.Request) (wire.Response, error)
- func (o *OpenAI) Model() string
- func (o *OpenAI) SetBaseURL(u string)
- func (o *OpenAI) Stream(ctx context.Context, r wire.Request, h wire.StreamHandler) (wire.Response, error)
- func (o *OpenAI) WebFetch(ctx context.Context, url string) (string, wire.Response, error)
- func (o *OpenAI) WebSearch(ctx context.Context, query string) (string, wire.Response, error)
Constants ¶
const EnvGrokKey = "XAI_API_KEY"
EnvGrokKey is the environment variable holding the xAI API key.
const EnvOpenAIKey = "OPENAI_API_KEY"
EnvOpenAIKey is the environment variable holding the OpenAI API key.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Grok ¶
type Grok struct {
*OpenAI
}
Grok is the ModelProvider for xAI's Grok API — the OpenAI adapter pointed at api.x.ai. xAI's /v1/responses endpoint is OpenAI-Responses-compatible and its documented Go path is exactly this (xAI ships Python/TS SDKs, no Go SDK), so Grok embeds the OpenAI adapter with vendor fields overridden instead of duplicating the dialect. That puts the Agent Tools web_search built-in INSIDE agentic serving turns (xAI retired Live Search — search_parameters → 410, 2026-07-18 — and Agent Tools on /v1/responses is its replacement), plus the same for the WebSearch/WebFetch side channel.
Vendor differences carried by the embedded adapter's fields:
- backend "grok" — its own wire/ledger tag, distinct from "openai".
- reasoning.effort clamped to low|high (xAI's vocabulary; xhigh 400s).
- no encrypted-reasoning includable (OpenAI-only round-trip).
Search-fee metering rides the embedded adapter too: Agent Tools bills web_search PER INVOCATION ($5/1k, docs.x.ai/developers/pricing), and each invocation surfaces as a web_search_call output item — so the shared SearchCount counter prices grok turns via models.json search_fees["grok"]. (Live Search's per-source num_sources_used card is dead alongside search_parameters; there is nothing per-source left to read.)
type OpenAI ¶
type OpenAI struct {
// contains filtered or unexported fields
}
OpenAI is the strong-tier ModelProvider backed by the OpenAI Responses API (GPT-5.6 family). It implements ModelProvider + Streamer + WebSearcher + WebFetcher — the same capability surface as the Anthropic provider. It maps wire.Request onto the Responses API (instructions + input items + flat function tools + reasoning.effort + prompt-cache breakpoints) and Responses output back to wire.Response.
The Responses API is item-structured (not message-structured): the conversation is a flat list of input items (messages, function calls, function outputs, reasoning), and the response is a flat list of output items. Reasoning items carry an encrypted_content blob that must be round-tripped on the next turn for stateless multi-turn tool use (store=false; we manage conversation state ourselves).
func NewOpenAI ¶
NewOpenAI returns a client using the given API key. baseURL is left empty so the SDK defaults; tests override it via o.baseURL = srv.URL before use (same pattern as Anthropic).
func (*OpenAI) Complete ¶
Complete satisfies the non-streamed contract by streaming under the hood and assembling the full Response — same rationale as Anthropic.Complete (the Responses API has the same long-operation streaming requirement for large max_tokens).
func (*OpenAI) Model ¶
Model returns the default model id (for display). The OpenAI provider serves whatever model resolve.go chose; this is the strong-tier default.
func (*OpenAI) SetBaseURL ¶
SetBaseURL points the adapter at a different Responses-API host (tests, proxies, enterprise gateways). "" restores the SDK default.
func (*OpenAI) Stream ¶
func (o *OpenAI) Stream(ctx context.Context, r wire.Request, h wire.StreamHandler) (wire.Response, error)
Stream sends a streaming Responses request, forwarding text/usage to h as they arrive, and returns the fully assembled Response (so the agent loop is identical to the non-streaming path).