Skip to content

[FEATURE]: Log LLM API request/response body at DEBUG log level #29186

Closed as not planned

Description

@u2x1

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

Currently --log-level DEBUG produces no useful output for debugging LLM API calls. Across the entire codebase there are only 21 log.debug() calls (mostly config loading and TUI audio), and none of them cover the LLM request body sent to providers.

When troubleshooting issues like provider errors, malformed requests, or unexpected model behavior, there's no way to inspect what opencode actually sends to the API.

Comparison

Claude Code has --debug "api" which logs API-level request/response details. This is essential for debugging custom providers and understanding model failures.

Proposed Solution

Add log.debug() calls at the session/llm.ts level, after LLMRequestPrep.prepare() returns the prepared request. At minimum, log:

  • messages array (system prompt + conversation history)
  • tools being sent
  • temperature / maxOutputTokens / other params
  • response headers/status on error
    Ideally also log at the HTTP layer (e.g. via a custom fetch wrapper in provider.ts) to capture the raw JSON body sent to the provider endpoint.

Affected Files

  • packages/opencode/src/session/llm.ts — where streamText() is called
  • packages/opencode/src/session/llm/request.ts — where request is assembled
  • packages/opencode/src/provider/provider.ts — where provider SDKs are created

Activity

  1. webgoto commented on Jun 14, 2026

    @webgoto

    I really want this feature too!

  2. bornmw commented on Jun 15, 2026

    @bornmw

    I really want this feature too!

    this works for me #32381
    have to add "experimental": { "log_messages": "trace" } to ~/.opencode/opencode.json and add env variable OPENCODE_LOG_LEVEL=DEBUG, or start opencode with OPENCODE_LOG_LEVEL=DEBUG opencode

  3. lakechain commented on Jul 17, 2026

    @lakechain

    I really want this feature too!

  4. neriousy commented on Oct 22, 2026

    @neriousy
    Member

    Closing as stale

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

Metadata

Metadata

Assignees

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