[BUG] Integration issue with OpenRouter API (Base URL override):API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"Invalid Anthropic Messages API request"}

Resolved 💬 7 comments Opened Mar 6, 2026 by flied Closed Apr 14, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

I encountered a persistent session-breaking bug when using Claude Code with OpenRouter as the backend. After a fresh installation (no extra MCP or skills installed), the CLI works fine for general chat but crashes immediately when a "Tool Use" action is triggered.

Once this error occurs, the entire session becomes unresponsive and requires a clear command to recover.

Environment
Claude Code Version: Latest (Fresh install)

Backend Provider: OpenRouter

API Configuration: Standard OpenRouter API Key

OS: macOS / Linux (Specify your OS here)

What Should Happen?

it should work well.

Error Messages/Logs

{
  "API_Error_Code": 400,
  "type": "error",
  "error": {
    "type": "invalid_request_error",
    "message": "Invalid Anthropic Messages API request"
  },
  "request_id": null,
  "metadata": {
    "raw": [
      {
        "code": "invalid_union",
        "errors": [
          [
            {
              "expected": "string",
              "code": "invalid_type",
              "path": [],
              "message": "Invalid input: expected string, received array"
            }
          ],
          [
            {
              "code": "invalid_union",
              "errors": [
                [
                  {
                    "expected": "string",
                    "code": "invalid_type",
                    "path": [],
                    "message": "Invalid input: expected string, received array"
                  }
                ],
                [
                  {
                    "code": "invalid_union",
                    "errors": [
                      [
                        {
                          "code": "invalid_value",
                          "values": ["text"],
                          "path": ["type"],
                          "message": "Invalid input: expected \"text\""
                        },
                        {
                          "expected": "string",
                          "code": "invalid_type",
                          "path": ["text"],
                          "message": "Invalid input: expected string, received undefined"
                        }
                      ],
                      [
                        {
                          "code": "invalid_value",
                          "values": ["image"],
                          "path": ["type"],
                          "message": "Invalid input: expected \"image\""
                        },
                        {
                          "code": "invalid_type",
                          "expected": "object",
                          "path": ["source"],
                          "message": "Invalid input: expected object, received undefined"
                        }
                      ]
                    ],
                    "path": [0],
                    "message": "Invalid input"
                  }
                ]
              ],
              "path": [0, "content"],
              "message": "Invalid input"
            }
          ]
        ],
        "path": ["messages", 3, "content"],
        "message": "Invalid input"
      }
    ]
  }
}

Steps to Reproduce

  1. Perform a clean installation of Claude Code.
  1. Initialize a project using an OpenRouter API key.
  1. Trigger a tool-related request, such as:

"Search the web for [topic]"

"List files in the current directory"

"Read the content of [filename]"

  1. Observe the console error.

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.69

Platform

Other

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗