Yolk SDK
Agent

Providers and OAuth

Provide model layers and keep token storage in your host app.

Provider subpaths translate Yolk messages/tools into vendor requests and normalize stream events back into Yolk protocol.

For the current provider catalog and setup snippets, see Model providers.

Pick a provider subpath

SubpathPurpose
@yolk-sdk/agent/providers/openaiCodex OAuth and token broker helpers
@yolk-sdk/agent/providers/openai/providerOpenAI-compatible chat provider factory
@yolk-sdk/agent/providers/openai/conformanceOpenAI chat, Codex Responses, and Codex usage fixtures and conformance cases
@yolk-sdk/agent/providers/vercel/ai-gateway-providerVercel AI Gateway provider factory and configuration
@yolk-sdk/agent/providers/vercel/ai-gateway-classifierVercel AI Gateway classifier model layer (/v1/evaluate)
@yolk-sdk/agent/providers/vercel/conformanceGateway chat and classifier wire fixtures for replay tests with @yolk-sdk/conformance
@yolk-sdk/agent/providers/opencode/go-providerOpenCode Go API-key provider for three host-selected protocols
@yolk-sdk/agent/providers/opencode/usageBest-effort Go allowance snapshots using an API key
@yolk-sdk/agent/providers/opencode/conformanceOpenCode Go wire fixtures and conformance cases (protocols and usage) for replay
@yolk-sdk/agent/providers/openai/codexCodex request, authorization header, and token broker helpers
@yolk-sdk/agent/providers/openai/codex-usageBest-effort Codex subscription-allowance snapshots
@yolk-sdk/agent/providers/openai/codex-providerOpenAI Codex provider factory
@yolk-sdk/agent/providers/anthropicClaude OAuth and token broker helpers
@yolk-sdk/agent/providers/anthropic/claudeClaude authorization URL, callback parsing, and token broker helpers
@yolk-sdk/agent/providers/anthropic/usageBest-effort Claude subscription-allowance snapshots
@yolk-sdk/agent/providers/anthropic/claude-providerClaude provider factory
@yolk-sdk/agent/providers/anthropic/conformanceAnthropic Messages and Claude usage fixtures and conformance cases for replay tests
@yolk-sdk/agent/providers/xaiGrok subscription OAuth and token broker helpers
@yolk-sdk/agent/providers/xai/grokGrok PKCE/device constants, callback parsing, auth, and broker helpers
@yolk-sdk/agent/providers/xai/grok-providerGrok subscription Responses provider factory
@yolk-sdk/agent/providers/xai/usageBest-effort Grok subscription-allowance snapshots
@yolk-sdk/agent/providers/xai/conformanceGrok Responses and Grok usage fixtures and conformance cases for replay tests
@yolk-sdk/agent/providers/subscription-usageShared allowance snapshot and safe error schemas
@yolk-sdk/agent/oauthProvider-neutral access-token and broker contracts

Provide fresh credentials at runtime

Provider packages may model vendor auth mechanics, but hosts own:

  • refresh token storage
  • encryption and rotation
  • broker routes
  • OAuth callbacks
  • account linking
  • model-specific output-token limits
  • policy and audit

Give provider layers fresh access tokens at execution time. Do not store raw secrets in protocol messages, annotations, tool results, or docs examples.

Vercel AI Gateway accepts either an AI Gateway API key or a Vercel OIDC token as Bearer auth. The host chooses which credential source to use, owns model routing/fallback policy, and treats custom Gateway endpoint URLs as credential-bearing trusted proxies.

OpenCode Go accepts a redacted API key, not OAuthAccessToken. Hosts select the model's protocol and output limit. Messages uses x-api-key; Chat Completions and Responses use Bearer auth. No Claude/Codex subscription fingerprints are added. Only configure a trusted credential-bearing baseUrl override. See Go setup.

Grok subscription tokens default to the fixed xAI CLI proxy, not the developer API-key origin. Browser PKCE uses xAI's fixed loopback callback. The package exports device-flow constants only; a host that cannot listen on the callback must implement device-code initiation, polling, cancellation, and exchange itself. Validate token provider/freshness before construction, serialize refreshes, and atomically persist any replacement refresh token. Only configure a custom Grok response URL when it is a trusted credential-bearing proxy. The default CLI proxy is a private, unsupported surface that may change; use it only when permitted by xAI's terms.

Claude/Codex/Grok subscription-usage adapters accept the same OAuthAccessToken values but do not refresh or persist them. Go's fetchOpenCodeGoSubscriptionUsage accepts a redacted API key instead. Grok usage also requires the authenticated xAI user_id and a truthful host integration version as explicit options; it does not reinterpret generic token accountId or impersonate an official client version. Their private provider endpoints are best-effort. Hosts own polling, labels, stale-data rules, alerts, and UI; the adapters only fetch and normalize allowance windows with sanitized errors.

What the provider gives the loop

Provider layers implement LLMProvider. The loop calls that service with messages, tool definitions, system prompt, model id, and optional capabilities. The provider emits text deltas, tool calls, usage, and done/error events. Tool calls are decoded as protocol ToolCall; a malformed one (empty or padded id or name) fails the request with a typed LLMError, never a thrown defect.

A stream that completes without the usage report its request asked for still ends with LLMDone, marked usageUnavailable: true:

ProviderMarked when
Streamed chat (OpenAI-compatible, Vercel AI Gateway, OpenCode Go chat)the stream ends after the finish chunk, without the stream_options.include_usage usage chunk
Streamed Responses (OpenAI Codex, xAI Grok, OpenCode Go responses)response.completed carries no usage
OpenAI Codexthe stream ends without response.completed, or the response.completed output is missing or misses a required key and its usage is missing or does not decode
Anthropic Claude, native Messages (OpenCode Go messages)message_stop arrives without a message_delta carrying an output count (only message_start usage, if any)

Non-streamed (JSON) responses are never marked. Grok and OpenCode Go Responses fail without response.completed, and Messages streams fail without message_stop, so neither completes without its terminal event: such a stream emits no LLMDone and fails as non-retryable invalid_response with responseIssue: 'missing_done', the loop's incomplete stream. The loop forwards the mark on the protocol LLMStreamEnd (Protocol).

Codex's recovery of a final response with missing output (streamed or JSON) keeps its valid output items, so a function call the stream never emitted still runs, and reports its usage when that decodes (Done unmarked). A function call that does not decode must replay one the stream already emitted, and a message that does not decode and carries text must be one whose text already streamed; otherwise the response fails as invalid_response instead of ending the turn without it (OpenAI Codex).

OpenAI JSON admission

OpenAI Chat Completions and Responses lowering admits ToolDef.parameters and tool-call params as Schema.Json before transport. Non-JSON values fail as non-retryable LLMError provider_error. ToolDef.parameters now admits ToolJsonSchema at construction; call params/results remain opaque. Public Codex OpenAiCodexTool.parameters remains unknown. Inbound HTTP JSON and Responses SSE event JSON admit Schema.Json before helpers; non-object SSE JSON is ignored, malformed non-JSON event text fails invalid_response, and HTTP error bodies stay raw text for classification.

OpenAiProviderConfig.reasoningEffortFormat picks the request field for reasoningEffort: reasoning-object sends { reasoning: { effort } }, and reasoning-effort sends reasoning_effort. The native OpenAI endpoint (no chatCompletionsUrl) defaults to reasoning-effort; compatible endpoints have no default, and a request with an effort fails with a validation_error until one is set. omit never sends the effort and never fails. reasoningContent: true validates/emits reasoning_content (or the normalized reasoning thinking field, preferring reasoning_content when both are present) and preserves it in assistant replay; by default this vendor extension is ignored. OpenCode Go enables the latter two options.

Chat stays one JSON body by default; streaming: true requests SSE deltas (OpenCode Go chat always sets it). Only stream against endpoints that serve chat SSE. See the API reference and Go setup.

OpenAiProviderConfig.extraBody takes JSON-object input. Lowering discards canonical request fields without reading their values and snapshots surviving enumerable own data. Accessors are rejected unread, not evaluated; nonfinite values, cycles and exotic objects fail with a fixed Invalid … extraBody JSON: expected a JSON object and no HTTP request. Root symbols/hidden fields are omitted; nested hidden/symbol keys and extra array properties fail. DAG aliases are supported; mutating the input after lowering does not mutate the snapshot. Proxy traps are not guaranteed side-effect-free. Final composed-body Schema.Json admission after lone-surrogate rewriting remains. Gateway routing projects its declared JSON fields. See the migration guide.

Errors and retries

Provider adapters classify safe metadata into ProviderErrorInfo. Raw provider response bodies stay out of protocol/UI. The loop owns bounded retry behavior and usage aggregation.

Subscription-usage requests use separate ProviderSubscriptionUsageError variants because they run outside the LLM loop. They suppress credential-bearing HTTP traces and never preserve raw response bodies in typed failures.

On this page