Repository navigation
Description
Feature hasn't been suggested before.
- I searched for an existing request covering this complete interface. [FEATURE]: Allow provider-native options in stateless generate.text #47366 concerns per-request options on stateless text generation; [FEATURE]: Allow LLM execution to be provided by an external runtime #50185 concerns supplying an external executor to OpenCode, which is the opposite direction.
Describe the enhancement you want to request
Expose a public, authenticated single-step streaming inference API for applications that own their own conversation history, agent loop, tool execution, and approvals, while OpenCode continues to own provider connections, credential refresh, configuration, and model resolution.
Current gap
Source inspected: OpenCode 2.2.5, commit ff90ed9.
@opencode/aialready supports single-callgenerate/streamwith full messages and tool declarations; its separateloopAPI executes tools.GenerateusesModelResolverand the existing authenticated provider runtime, but publicexperimental.generate.textaccepts only prompt/model and returns text.session.generateuses OpenCode-owned session context and returns text.session.prompt, CLI run, and ACP operate on OpenCode agent sessions.- Using
@opencode/aidirectly does not by itself reuse an installed OpenCode instance's connected accounts, configuration, and model resolution.
An external orchestrator therefore cannot currently use the complete existing provider/account machinery through the public API while retaining ownership of history and tool execution.
Requested contract
Extend the existing Generate owner and expose it through the official Server/client and embedded SDK surfaces; exact method naming is open for discussion.
Input:
- Explicit model reference (
providerID, model ID, optional variant). - System instructions and complete messages, including assistant tool calls and externally produced tool results.
- Tool declarations/JSON schemas, tool choice, and supported generation options.
- Request identity and cancellation through the existing request/stream lifecycle.
Output:
- Typed text/reasoning and tool-call stream events.
- Finish reason and usage, including cache fields when supplied by the provider.
- Existing typed authentication/model/provider errors; no silent model, account, or billing fallback.
Semantics:
- Perform one model step, without executing client tools or starting an OpenCode agent loop.
- Do not create a business Session or append to a user's session history.
- Reuse Provider/Integration/ModelResolver, supported provider hooks, credential refresh, and the existing request executor.
- Define the configuration/location and account scope explicitly. Do not export provider credentials in model/readiness responses or diagnostics (related exposure concern: api: /api/model, /api/config and /api/provider/{id} return resolved provider credentials #53465).
- Require only bounded request-scoped state, with cancellation and resource cleanup owned by the existing lifecycle.
Acceptance evidence
- Use a connected test provider through the normal OpenCode resolver; credentials remain server-side.
- Submit full history plus a test tool schema, receive a tool call without executing it in OpenCode, then submit an independently generated external tool result in a second request.
- Stream normalized output and usage; cancellation terminates the request and releases resources.
- Missing account, unavailable model/variant, and unsupported capabilities produce explicit failures.
- No business Session/history rows are created by these calls, and unrelated sessions/configuration remain unchanged.
- Cover the contract through the official generated client and embedded SDK using an isolated test account/environment.
Related: #39243, #47366, #50185. This requests the external-history/tool streaming contract in addition to existing text-only generation; it does not request a second agent runtime or a new credential store.
Activity
opencodejr commentedon Nov 3, 2026
Thanks for the detailed request! In short, you're asking for a public, authenticated single-step streaming inference API. The caller would send the full history (including assistant tool calls and tool results it produced itself), tool schemas and generation options, and get back streamed text, reasoning and tool-call events with finish reason and usage. OpenCode would keep handling provider connections, credentials and model resolution, but wouldn't run tools, start an agent loop or create a session.
I checked the code and it matches your description.
experimental.generate.text(packages/protocol/src/groups/generate.ts) accepts onlypromptandmodeland returns text. The lower-levelLLM.requestin@opencode/aialready accepts system, messages, tools, tool choice and generation options, but the public endpoint doesn't pass them through.Maintainers will consider this. Related issues:
/api/experimental/generateaccepts only{prompt, model}whileLLM.requestalready acceptssystem,messagesandgeneration#49549: asks to widengenerate.textwithmessagesandgeneration, a subset of this requestgenerate.text