Skip to content

[FEATURE]: Stateless streaming inference with external history and tool declarations #61321

Closed as not planned

Description

@chenhuayi83

Feature hasn't been suggested before.

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/ai already supports single-call generate/stream with full messages and tool declarations; its separate loop API executes tools.
  • Generate uses ModelResolver and the existing authenticated provider runtime, but public experimental.generate.text accepts only prompt/model and returns text.
  • session.generate uses OpenCode-owned session context and returns text. session.prompt, CLI run, and ACP operate on OpenCode agent sessions.
  • Using @opencode/ai directly 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

  1. Use a connected test provider through the normal OpenCode resolver; credentials remain server-side.
  2. 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.
  3. Stream normalized output and usage; cancellation terminates the request and releases resources.
  4. Missing account, unavailable model/variant, and unsupported capabilities produce explicit failures.
  5. No business Session/history rows are created by these calls, and unrelated sessions/configuration remain unchanged.
  6. 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

  1. opencodejr commented on Nov 3, 2026

    @opencodejr
    Contributor

    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 only prompt and model and returns text. The lower-level LLM.request in @opencode/ai already accepts system, messages, tools, tool choice and generation options, but the public endpoint doesn't pass them through.

    Maintainers will consider this. Related issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions