[BUG] Claude Code changes model identifier mid-conversation on AWS Bedrock (eu to us region)

Status Closed — not planned
Maintainer reply None cached
Activity 13 comments · opened Aug 4, 2025 · closed Jan 7, 2026

Environment

  • Platform (select one):
  • [ ] Anthropic API
  • [x] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: LiteLLM
  • Claude CLI version: 1.0.67 (Claude Code)
  • Operating System: macOS 15.6
  • Terminal: Terminal / oh-my-zsh

Bug Description

I have a very odd bug where Claude Code switches the model used in a long conversation. I am using the eu sonnet model via Bedrock, proxied through a LiteLLM proxy. (Computer => LiteLLM => Bedrock)

The model used is eu.anthropic.claude-sonnet-4-20250514-v1:0

After conversing with the model for a while, suddenly this message appears:

  ⎿  API Error (500 {"error":{"message":"{\"message\":\"The provided model identifier is invalid.\"}. Received Model Group=us.anthropic.claude-sonnet-4-20250514-v1:0\nAvailable Model Group Fallbacks=None\nError doing the fallback: list index out of range","type":"None","param":"None","code":"500"}}) · Retrying in 1 seconds… (attempt 1/10)

Note the model identifier us.anthropic.claude-sonnet-4-20250514 with the us prefix, not eu. We can see from LiteLLM logs that the wrong model identifier is in fact being sent from Claude Code.

Closing CC and then using --resume allows the conversation to continue for a short while before the issue reappears.

Steps to Reproduce

  1. Run Claude Code with: AWS_REGION=eu-west-1 AWS_DEFAULT_REGION=eu-west-1 ANTHROPIC_MODEL=eu.anthropic.claude-sonnet-4-20250514-v1:0 ANTHROPIC_AUTH_TOKEN=REDACTED ANTHROPIC_BEDROCK_BASE_URL=https://litellm.REDACTED/bedrock CLAUDE_CODE_SKIP_BEDROCK_AUTH=1 CLAUDE_CODE_USE_BEDROCK=1 claude
  2. Ask CC to do something that requires a couple of minutes of agentic work
  3. The issue appears.

Expected Behavior

Always use the configured model from ANTHROPIC_MODEL.

Actual Behavior

Changes model randomly.

Additional Context

-

View original on GitHub ↗

13 Comments

dimohammed328 · 1 year ago

I think I am encountering a similar bug on Linux for bedrock as well. I think the issue specifically is that the model for the Task tool subagent doesn't respect the model set in the settings. Can you confirm if this is what you are seeing as well?

khromov · 1 year ago

@dimohammed328 it totally makes sense that this would be caused by a subagent as that would explain the ability to resume the conversation with --resume. How can I verify that the Task tool causes the issue?

dimohammed328 · 1 year ago

Unsure, if you're running into the issue, you can check if the last thing claude did was call a Task tool. I think you can also ask claude to do something as a subagent task so that would work as well.

khromov · 1 year ago

I can confirm the issue, when a new Task spins up it uses the wrong model name:

> create a new subagent to document this package

⏺ I'll create a specialized agent to document this package. Let me launch a general-purpose agent to analyze the codebase and create comprehensive documentation.
  ⎿  API Error (500 {"error":{"message":"{\"message\":\"The provided model identifier is invalid.\"}. Received Model Group=us.anthropic.claude-sonnet-4-20250514-v1:0\nAvailable Model Group Fallbacks=None\nError doing the fallback: list index out of range","type":"None","param":"None","code":"500"}}) · Retrying in 1 seconds… (attempt 1/10)
  ⎿  API Error (500 {"error":{"message":"{\"message\":\"The provided model identifier is invalid.\"}. Received Model Group=us.anthropic.claude-sonnet-4-20250514-v1:0\nAvailable Model Group Fallbacks=None\nError doing the fallback: list index out of range","type":"None","param":"None","code":"500"}}) · Retrying in 1 seconds… (attempt 2/10)
  ⎿  API Error (500 {"error":{"message":"{\"message\":\"The provided model identifier is invalid.\"}. Received Model Group=us.anthropic.claude-sonnet-4-20250514-v1:0\nAvailable Model Group Fallbacks=None\nError doing the fallback: list index out of range","type":"None","param":"None","code":"500"}}) · Retrying in 2 seconds… (attempt 3/10)

⏺ Task(Document DNA package)
  ⎿  Initializing…
github-actions[bot] · 1 year ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/4855
  2. https://github.com/anthropics/claude-code/issues/3903
  3. https://github.com/anthropics/claude-code/issues/4264

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

khromov · 1 year ago

Here's a simple Node.js script that works around the issue for now. Set TARGET_URL to your LiteLLM instance (or point directly to Bedrock) by automatically modifying the url to point to the EU model.

Invoke Claude Code by starting the script then setting ANTHROPIC_BEDROCK_BASE_URL=http://localhost:8888/bedrock

ANTHROPIC_SMALL_FAST_MODEL=eu.anthropic.claude-3-5-haiku-20241022-v1:0 ANTHROPIC_MODEL=eu.anthropic.claude-sonnet-4-20250514-v1:0 ANTHROPIC_AUTH_TOKEN=sk-LITELLM_TOKEN ANTHROPIC_BEDROCK_BASE_URL=http://localhost:8888/bedrock CLAUDE_CODE_SKIP_BEDROCK_AUTH=1 CLAUDE_CODE_USE_BEDROCK=1 CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 claude
import http from 'http';

const PORT = process.env.PORT || 8888;
const TARGET_URL = 'https://litellm.your-company.com';

const server = http.createServer(async (req, res) => {
  try {
    let targetPath = req.url;
    const usModelPattern = /us\.anthropic\.claude-[^\/]+/g;
    
    if (usModelPattern.test(targetPath)) {
      const originalPath = targetPath;
      targetPath = targetPath.replace(/us\.anthropic\./g, 'eu.anthropic.');
      console.log(`\n🔄 Model redirect: US -> EU`);
      console.log(`  Original: ${originalPath}`);
      console.log(`  Rewritten: ${targetPath}`);
    }
    
    const targetUrl = `${TARGET_URL}${targetPath}`;
    
    const chunks = [];
    for await (const chunk of req) {
      chunks.push(chunk);
    }
    const body = Buffer.concat(chunks);
    
    console.log(`\n--- ${new Date().toISOString()} ---`);
    console.log(`${req.method} ${targetPath}`);

    if (body.length > 0) {
      const bodyString = body.toString('utf-8');
      
      try {
        const jsonBody = JSON.parse(bodyString);
        // Check if model is also specified in the body and replace it
        if (jsonBody.model && jsonBody.model.includes('us.anthropic.')) {
          const originalModel = jsonBody.model;
          jsonBody.model = jsonBody.model.replace('us.anthropic.', 'eu.anthropic.');
          console.log(`  Body model redirect: ${originalModel} -> ${jsonBody.model}`);
          // Update the body with the modified JSON
          body.length = 0;
          const newBodyString = JSON.stringify(jsonBody);
          const newBody = Buffer.from(newBodyString, 'utf-8');
          Object.assign(body, newBody);
        }
      } catch (e) {
      }
    }
    
    const headers = { ...req.headers };
    delete headers['host'];
    delete headers['content-length']; // Let fetch calculate this
    
    // Make the proxied request
    const response = await fetch(targetUrl, {
      method: req.method,
      headers: headers,
      body: body.length > 0 ? body : undefined,
      redirect: 'manual'
    });
    
    // Log response status
    //console.log(`Response: ${response.status} ${response.statusText}`);
    
    res.statusCode = response.status;
    res.statusMessage = response.statusText;
    
    response.headers.forEach((value, key) => {
      if (!['content-encoding', 'transfer-encoding'].includes(key.toLowerCase())) {
        res.setHeader(key, value);
      }
    });
    
    const responseBody = await response.arrayBuffer();
    res.end(Buffer.from(responseBody));
    
  } catch (error) {
    console.error('Proxy error:', error);
    res.statusCode = 500;
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({ 
      error: 'Proxy error', 
      message: error.message 
    }));
  }
});

server.listen(PORT, () => {
  console.log(`Proxy server running on http://localhost:${PORT}`);
  console.log(`Forwarding requests to: ${TARGET_URL}`);
  console.log('Ready to accept requests...');
  console.log('\n✨ Auto-redirecting US models to EU models');
});

// Handle server errors
server.on('error', (error) => {
  console.error('Server error:', error);
});

// Graceful shutdown
process.on('SIGINT', () => {
  console.log('\nShutting down proxy server...');
  server.close(() => {
    console.log('Server closed');
    process.exit(0);
  });
});

process.on('SIGTERM', () => {
  console.log('\nShutting down proxy server...');
  server.close(() => {
    console.log('Server closed');
    process.exit(0);
  });
});
lacolaco · 1 year ago

Same issue here. Multiple tools affected by invalid model identifier error:

Tools failing:

  • Task tool (subagents): `API Error

(us.anthropic.claude-sonnet-4-20250514-v1:0): 400 The provided model identifier is invalid.`

Environment:

  • Claude Code 1.0.88
  • macOS
  • /model shows correct:

apac.anthropic.claude-sonnet-4-20250514-v1:0

Tools are using wrong us. prefix instead of apac.. Breaks entire subagent system.

lacolaco · 1 year ago

https://github.com/anthropics/claude-code/issues/4855#issuecomment-3220160458

Undocumented CLAUDE_CODE_SUBAGENT_MODEL env var works for me. (v1.0.92)

github-actions[bot] · 8 months ago

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

khromov · 8 months ago

Still occurring

FelipeNystrom · 8 months ago

This would be nice if it got fixed!

github-actions[bot] · 7 months ago

This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.

github-actions[bot] · 7 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.