Skip to content

bug: Claude Sonnet 4.5 with thinking + ephemeral cache returns HTTP 400 #17883

Closed as not planned

Description

@cyberprophet

Description

When using claude-sonnet-4-5 via the Anthropic provider with extended thinking enabled, the API returns HTTP 400. The request includes thinking: { type: "enabled", budget_tokens: 31999 } and system messages with ephemeral cache_control type.

This was observed when using the model through a plugin (shop-plugin) that injects system prompts via experimental.chat.system.transform hook. The system array contains blocks with type: "ephemeral", which appears to conflict with the thinking configuration.

Error Details

service=llm providerID=anthropic modelID=claude-sonnet-4-5
error.name: AI_APICallError
error.url: https://api.anthropic.com/v1/messages
error.statusCode: 400

Request body:
  model: "claude-sonnet-4-5"
  max_tokens: 63999
  thinking: { type: "enabled", budget_tokens: 31999 }
  system: [{ type: "text", text: "..." }, { type: "ephemeral", ... }]

The same plugin works correctly with gpt-5-nano (no thinking enabled).

Steps to Reproduce

  1. Configure a plugin that uses experimental.chat.system.transform hook to inject system prompts
  2. Set model to anthropic/claude-sonnet-4-5
  3. Enable thinking (happens automatically via oh-my-opencode config or OpenCode defaults)
  4. Send any message

Expected Behavior

The API call should succeed, either by:

  • Stripping incompatible cache_control types when thinking is enabled
  • Or validating the combination before sending to the API

Environment

  • OpenCode version: 1.2.27
  • Plugin: shop-plugin (system prompt injection via hooks)
  • oh-my-opencode: 3.x
  • OS: macOS Darwin 25.3.0

Related Issues

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 17, 2026
  2. cyberprophet commented on Mar 17, 2026

    @cyberprophet
    ContributorAuthor

    Cross-reference from oh-my-openagent#2631

    After investigating the oh-my-openagent codebase, this issue is confirmed to be on the OpenCode / @ai-sdk/anthropic side, not oh-my-openagent.

    oh-my-openagent's role

    oh-my-openagent applies thinking: { type: "enabled", budgetTokens: 32000 } to all non-GPT models in its agent factories (e.g., Sisyphus, Oracle, Metis). This is a valid Anthropic API parameter for models that support extended thinking like claude-sonnet-4-5.

    The ephemeral cache_control in system messages comes from the plugin layer (experimental.chat.system.transform hook) — oh-my-openagent's own system-transform.ts is currently a no-op stub.

    Root cause

    OpenCode's provider layer should validate that the combination of thinking + system messages with cache_control: { type: "ephemeral" } is compatible before sending to the Anthropic API. The Anthropic Messages API rejects this combination with HTTP 400.

    Suggested fix

    Either:

    1. Strip cache_control from system message blocks when thinking is enabled (pre-flight sanitization)
    2. Or validate the combination and surface a clear error to the user before sending to the API

    Closing oh-my-openagent#2631 as this is an OpenCode-level concern.


    ref: code-yeongyu/oh-my-openagent#2631

  3. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  4. github-actions commented on Jul 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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