OpenCode Chat Model
AI-generatedSummary
Chats with OpenCode using a selected model and session mode, returning AI-generated text with token usage and optional tool call support.
Inputs
- sessionMode — Choose how to handle sessions: use an existing session or create a temporary one per request. Default: existing.
- sessionId (required) — Select an OpenCode session to use for the chat model. Required when sessionMode is 'existing'. Loads available sessions via getSessions method.
- tempSessionTitle — Title for temporary sessions (for debugging purposes). Default: 'Temporary Chat Session'. Shown when sessionMode is 'temporary'.
- model — Select a model (optional, uses default if not specified). Format: 'providerID::modelID' if provider-specific model is needed. Loads available models via getModels method.
- options — Additional request options. Default: {}. Contains 'timeout' property in milliseconds.
Output shape
Returns an object with 'generations' (array of {text, message, generationInfo}) and 'llmOutput' (tokenUsage, modelId, providerId). When tools are configured, tool calls are parsed and included in the message.
Generates a ChatOpenCode instance configured with the specified session, model, and timeout. Execution contacts the OpenCode API at /session/{sessionId}/message. Temporary sessions are automatically created at request start and deleted after response via a finally block. Existing sessions are reused without automatic deletion. Timeout defaults to 300000ms (5 minutes); exceeded requests throw 'OpenCode API request timeout after 300000ms'.