Skip to content

fix: skip Anthropic cache control for OAuth#18311

Open
jorgitin02 wants to merge 2 commits intoanomalyco:devfrom
jorgitin02:fix/17910-anthropic-oauth-cache
Open

fix: skip Anthropic cache control for OAuth#18311
jorgitin02 wants to merge 2 commits intoanomalyco:devfrom
jorgitin02:fix/17910-anthropic-oauth-cache

Conversation

@jorgitin02
Copy link
Contributor

@jorgitin02 jorgitin02 commented Mar 20, 2026

Issue for this PR

Closes #17910

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Anthropic OAuth requests were still going through the normal Anthropic cache-control path, which adds cache_control: { type: "ephemeral" } to recent prompt messages. That metadata is rejected on the OAuth path and causes the request to fail.

This changes ProviderTransform.message() to skip Anthropic cache-control injection when the resolved auth type is oauth, and updates LLM.stream() to pass the resolved auth type into that transform. I also added regression coverage at two levels: one focused transform test for the cache-control behavior, and one LLM.stream() test that exercises the Anthropic messages request path with OAuth auth present.

The fix is narrow on purpose: it only changes Anthropic when auth is OAuth, and leaves the existing non-OAuth Anthropic caching behavior in place.

How did you verify your code works?

  • bun test test/session/llm.test.ts
  • bun test test/provider/transform.test.ts
  • bun typecheck
  • bun test

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added contributor needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Mar 20, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@jwcrystal
Copy link

⚠️ Update: The cache_control hypothesis has been disproven. See issue comment for details.

The actual root cause is missing x-anthropic-billing-header that Anthropic now requires for OAuth requests. This PR's approach may not fully resolve the issue.

A reference implementation is available at clewdr@a4e5df3.

@jorgitin02
Copy link
Contributor Author

Updated this PR.

It now does three things for Anthropic OAuth:

  • skips injected cache_control
  • prepends the Claude Code-style billing header system text
  • sends the Claude Code user-agent on OAuth requests

Local verification:

  • bun test ./test/provider/transform.test.ts
  • bun test ./test/session/llm.test.ts
  • bun typecheck

The earlier failing e2e checks were in the app workspace-routing suite, not this provider/session codepath, so those need to be re-evaluated on the refreshed branch checks.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: OAuth auth + cache_control ephemeral causes HTTP 400 on all Claude models since 2026-03-17

2 participants