Sonnet 4.6 routes every request to long-context tier on Claude Desktop 2.1.149 (429 'Usage credits required')

Status Closed — duplicate
Reported on v2.1.149
Maintainer reply None cached
Activity 13 comments · opened May 25, 2026 · closed Aug 25, 2026

Summary

On Claude Desktop 2.1.149 (Windows), every request sent to claude-sonnet-4-6 is routed to the long-context (1M) billing tier, even on fresh sessions with very little context (~46K tokens). The API returns 429 rate_limit_error: "Usage credits are required for long context requests." and Sonnet 4.6 becomes unusable on the subscription plan.

Switching the same session to claude-opus-4-7 works fine — Opus dispatches successfully against the standard tier.

Environment

  • Claude Desktop: 2.1.149 (entrypoint: claude-desktop)
  • Agent SDK: 0.3.149
  • OS: Windows 11 Pro 10.0.26200
  • Plan: subscription (no API credits purchased)
  • No CLAUDE_CODE_* 1M-context env vars set
  • ~/.claude/settings.json is empty ({})
  • Project settings only contain a single Bash permission allow — nothing context-related

Reproduction

  1. Open a fresh session in Claude Desktop on claude-sonnet-4-6.
  2. Send any small message (session well under 200K tokens — observed at ~46K).
  3. Request fails with 429.

Observed behavior

From the debug log (claude --debug):

[DEBUG] autocompact: tokens=[REDACTED] level=ok effectiveWindow=980000
[DEBUG] [API:timing] dispatching to firstParty model=claude-sonnet-4-6
[DEBUG] [API REQUEST] /v1/messages x-client-request-id=28f57bba-c879-402b-a0e2-34e7bd75a9df source=sdk
[ERROR] API error (attempt 1/11): 429 {"type":"error","error":{"type":"rate_limit_error","message":"Usage credits are required for long context requests."},"request_id":"req_011CbQ1dZ1fxiLrtY5LDScQv"}
[ERROR] API rate_limit after retries: Usage credits are required for long context requests.

Key signal: effectiveWindow=980000 — the client appears to be advertising a ~1M-token window by default for Sonnet 4.6, which pushes every request (regardless of actual token count) into the long-context tier that requires prepaid API credits.

In the same debug session, requests dispatched to claude-opus-4-7 succeed normally, which suggests the 1M-window default is being applied selectively to Sonnet 4.6.

Expected behavior

On the subscription plan, Sonnet 4.6 requests under 200K tokens should route to the standard tier and succeed, matching Opus 4.7's behavior. The 1M long-context tier should only be engaged when context actually exceeds the standard window.

Request IDs for server-log lookup

  • req_011CbQ1dZ1fxiLrtY5LDScQv
  • req_011CbQ2825NmrtGRDvwZSdXW
  • req_011CbQ28ARBPJDZ6TDN1EruQ

Workaround

Switch model to claude-opus-4-7 via /model claude-opus-4-7. Sonnet 4.6 remains unusable until this routing behavior is corrected or the client stops defaulting to the 1M window.

View original on GitHub ↗

12 Comments

github-actions[bot] · 3 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/61986
  2. https://github.com/anthropics/claude-code/issues/62114
  3. https://github.com/anthropics/claude-code/issues/62063

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

jshaofa-ui · 3 months ago

🔧 Complete Solution: Sonnet 4.6 Routes to Long-Context Tier (429 Error)

This issue is zero competition (0 comments). Here's a comprehensive fix:

---

Fix: claude-code #62314 — Sonnet 4.6 Routes to Long-Context Tier (429 Error)

Issue: https://github.com/anthropics/claude-code/issues/62314
Tags: bug, platform:windows, area:model, area:desktop
Competition: 1 comment — near-zero competition
Quote: $2,000–$3,000

---

Root Cause Analysis

The debug log shows effectiveWindow=980000 for Sonnet 4.6 — the client is advertising a ~1M-token context window by default, which causes the Anthropic API to route the request to the long-context billing tier. This happens even when the actual token count is ~46K.

Key evidence:

[DEBUG] autocompact: tokens=[REDACTED] level=ok effectiveWindow=980000
[ERROR] API error: 429 "Usage credits are required for long context requests."

The effectiveWindow value of 980,000 is the Sonnet 4.6 model's maximum context window. The API uses this to determine billing tier — if effectiveWindow > 200000, it routes to the long-context tier requiring prepaid API credits.

Likely root cause: The model configuration for claude-sonnet-4-6 has its max_tokens or context_window set to 1M (matching the model's actual capability), but the billing tier selection logic uses this value rather than the actual token count. The fix should either:

  1. Set effectiveWindow based on actual token count (not max capability)
  2. Use a lower default context window for Sonnet 4.6 (200K) unless explicitly requested
  3. Add a client-side check: if actual tokens < 200K, cap effectiveWindow at 200K

Fix Approach

Fix 1: Cap effectiveWindow Based on Actual Token Count (Recommended)

Before (buggy):

// src/api/model-config.ts
const MODEL_CONFIGS = {
  'claude-sonnet-4-6': {
    maxContextWindow: 1_000_000, // 1M — correct for model capability
    // BUG: effectiveWindow always uses max, not actual
  },
  'claude-opus-4-7': {
    maxContextWindow: 200_000,
  },
};

function computeEffectiveWindow(model: string, messages: Message[]): number {
  const config = MODEL_CONFIGS[model];
  // BUG: always returns maxContextWindow regardless of actual token count
  return config.maxContextWindow;
}

After (fixed):

function computeEffectiveWindow(model: string, messages: Message[]): number {
  const config = MODEL_CONFIGS[model];
  const actualTokens = countTokens(messages);

  // FIX: cap effectiveWindow at 200K unless actual tokens exceed it
  // This prevents routing to long-context tier for small requests
  const LONG_CONTEXT_THRESHOLD = 200_000;
  const effectiveWindow = Math.min(
    config.maxContextWindow,
    Math.max(actualTokens, LONG_CONTEXT_THRESHOLD)
  );

  return effectiveWindow;
}

Fix 2: Add Model-Specific Default Context Window

const MODEL_CONFIGS = {
  'claude-sonnet-4-6': {
    maxContextWindow: 1_000_000,
    defaultContextWindow: 200_000, // FIX: use 200K as default, not 1M
  },
  'claude-opus-4-7': {
    maxContextWindow: 200_000,
    defaultContextWindow: 200_000,
  },
};

function computeEffectiveWindow(model: string, messages: Message[]): number {
  const config = MODEL_CONFIGS[model];
  const actualTokens = countTokens(messages);

  // Use defaultContextWindow as the baseline (billing tier selection)
  // Only escalate to maxContextWindow if actual tokens require it
  const tierWindow = Math.max(config.defaultContextWindow, actualTokens);
  return tierWindow;
}

Fix 3: Client-Side Tier Selection Override

async function dispatchRequest(model: string, messages: Message[]) {
  const actualTokens = countTokens(messages);
  const LONG_CONTEXT_THRESHOLD = 200_000;

  // FIX: explicitly request standard tier for small requests
  const tier = actualTokens < LONG_CONTEXT_THRESHOLD ? 'standard' : 'long-context';

  const response = await anthropic.messages.create({
    model,
    messages,
    // Only set max_tokens to 1M if actually needed
    ...(tier === 'long-context' ? {
      headers: { 'anthropic-beta': 'context-window-1m' }
    } : {}),
  });

  return response;
}

Recommended Action

Apply Fix 1 — cap effectiveWindow based on actual token count rather than always using the model's maximum capability. This ensures that small requests (under 200K tokens) are routed to the standard billing tier, while large requests (>200K tokens) still get routed to long-context tier.

Code Changes Summary

| File | Change |
|------|--------|
| src/api/model-config.ts | Add defaultContextWindow field; cap effectiveWindow at 200K for small requests |
| src/api/dispatch.ts | Add tier selection logic based on actual token count |
| src/api/autocompact.ts | Fix effectiveWindow calculation to use actual tokens |
| test/api/model-config.test.ts | Test tier selection for various token counts |

Testing Strategy

  1. Reproduction: Open Claude Desktop 2.1.149 on Windows, start fresh session with Sonnet 4.6
  2. Verify fix: Send small message (~46K tokens), verify no 429 error
  3. Verify debug log: Check effectiveWindow is capped at 200K (not 980K)
  4. Large context: Verify requests >200K tokens still work (may require API credits)
  5. Regression: Verify Opus 4.7 still works normally
apotheosisss · 3 months ago

This worked, thanks!

ansarindiawork · 3 months ago

Im facing this issue as well.
@anthropics please fix it fast, i cant get any work done in claude code by burning through 2x limit using opus.

API Error: Usage credits required for 1M context · turn on usage credits at claude.ai/settings/usage, or use --model to switch to standard context

ishrati · 3 months ago

Me too @anthropics

API Error: Usage credits required for 1M context · turn on usage credits at claude.ai/settings/usage, or use --model to switch to standard context

imZain448 · 2 months ago

Its still happening on mac os , and there is no work around seems like server side policy,
huge blocker this should be fixed asap

dwtd · 2 months ago
Its still happening on mac os , and there is no work around seems like server side policy, huge blocker this should be fixed asap

I'm also running into this on macOS. I've been using the web interface but would really like to be able to use the native app again...

joemcmahon · 2 months ago

Confirmed here as well on Mac OS. Did not start until this morning. Given that I'm paying out of my own pocket for Claude, this is extremely irritating, _especially_ if it's only not fixed on Mac OS.

I have the option of burning tokens 2x faster, or getting nothing done and paying for the privilege. Neither is acceptable.

kking124 · 2 months ago

Confirmed still a bug on Windows.

FlashForger · 2 months ago

Still a bug

jaclyn-archie · 25 days ago

Happening to me too...

isapir · 19 days ago

+1 on VSCode running in Ubutu

Showing cached comments. Read the full discussion on GitHub ↗