Session LLM Runtime Boundaries
../llm.ts is the opencode session LLM service. It owns opencode concerns: auth, config, model/provider resolution, plugins, permissions, telemetry headers, and runtime selection.
This folder contains adapters behind that service boundary:
ai-sdk.tsconverts AI SDKfullStreamparts into@opencode-ai/llmLLMEvents. This is the default runtime path.native-request.tsconverts opencode's normalized session input into a native@opencode-ai/llmLLMRequest. It does not execute requests.native-runtime.tsis the opt-in native runtime adapter. It decides whether a selected model is supported, builds the native request, bridges opencode tools into native executable tools, and delegates transport toLLMClient/RequestExecutor.
Runtime selection
Both runtimes converge on the same LLMEvent stream consumed by the session processor. The gate is per-request: a single session can route some calls through native and fall back for others.
╭───────────────────╮
╭───────────────────────────▶│ session processor │
│ ╰─────────┬─────────╯
│ │
│ │
│ │
│ ▼
│ ╭─────────────────────────╮
│ │ LLM.Service (../llm.ts) │
│ ╰────────────┬────────────╯
│ │
│ │
│ │
│ ▼
│ ╭───────────╮
│ ╭─╯ ╰─╮
│ │ native gate │
│ ╰─╮ ╭─╯
│ ╰─────┬─────╯
│ │
│ ╭────── no ──────┴─────── yes ────────╮
│ │ │
│ ▼ ▼
│ ╭───────────────────────────╮ ╭───────────────────╮
│ │ AI SDK │ │ native-runtime.ts │
│ │ streamText / generateText │ ╰────────┬──────────╯
│ ╰─────────────┬─────────────╯ │
│ │ │
│ ╭───╯ │
│ │ │
│ ▼ ▼
│ ╭───────────────────────╮ ╭────────────────────────────╮
│ │ ai-sdk.ts │ │ native-request.ts │
│ │ fullStream → LLMEvent │ │ session input → LLMRequest │
│ ╰──────────┬────────────╯ ╰──────────────┬─────────────╯
│ │ │
│ │ ╭───╯
│ │ │
│ ▼ ▼
│ ╭─────────────────╮ ╭─────────────────────────────╮
╰───────┤ LLMEvent stream │◀────────────┤ LLMClient · RequestExecutor │
╰─────────────────╯ ╰─────────────────────────────╯
native-runtime.ts evaluates the gate and either bridges into @opencode-ai/llm or returns control so llm.ts can take the AI SDK path. Tool execution stays opencode-owned in both branches; only request lowering and transport differ.
Safety boundary:
- AI SDK remains the default.
OPENCODE_EXPERIMENTAL_NATIVE_LLM=trueor the umbrellaOPENCODE_EXPERIMENTAL=trueopts in. Native is not a global replacement.- Native execution currently runs only for OpenAI-compatible Responses models exposed through
@ai-sdk/openai: directopenaiAPI-key auth and console-managedopencode/Zen API-key config. - Unsupported providers, OpenAI OAuth, and missing API-key cases fall back to AI SDK.