openclaw - 💡(How to fix) Fix OpenRouter provider fails with "401 Missing Authentication header" despite valid API key [14 comments, 10 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#51056Fetched 2026-04-08 01:04:52
View on GitHub
Comments
14
Participants
10
Timeline
26
Reactions
0
Timeline (top)
commented ×13subscribed ×5mentioned ×4cross-referenced ×2

OpenClaw's OpenRouter provider is not sending the Authorization: Bearer <token> header, causing all requests to fail with 401 authentication errors.

Environment

• OpenClaw version: 2026.3.13 (61d171a) • OS: Linux (Debian-based) • Node version: v22.22.1

Configuration

// ~/.openclaw/openclaw.json "models": { "providers": { "openrouter": { "baseUrl": "https://openrouter.ai/api/v1", "api": "openai-completions", "models": [...] } } }, "auth": { "profiles": { "openrouter:default": { "provider": "openrouter", "mode": "api_key" } } }

Root Cause

OpenClaw's OpenRouter provider is not sending the Authorization: Bearer <token> header, causing all requests to fail with 401 authentication errors.

Environment

• OpenClaw version: 2026.3.13 (61d171a) • OS: Linux (Debian-based) • Node version: v22.22.1

Configuration

// ~/.openclaw/openclaw.json "models": { "providers": { "openrouter": { "baseUrl": "https://openrouter.ai/api/v1", "api": "openai-completions", "models": [...] } } }, "auth": { "profiles": { "openrouter:default": { "provider": "openrouter", "mode": "api_key" } } }

RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Summary

OpenClaw's OpenRouter provider is not sending the Authorization: Bearer <token> header, causing all requests to fail with 401 authentication errors.

Environment

• OpenClaw version: 2026.3.13 (61d171a) • OS: Linux (Debian-based) • Node version: v22.22.1

Configuration

// ~/.openclaw/openclaw.json "models": { "providers": { "openrouter": { "baseUrl": "https://openrouter.ai/api/v1", "api": "openai-completions", "models": [...] } } }, "auth": { "profiles": { "openrouter:default": { "provider": "openrouter", "mode": "api_key" } } }

Steps to reproduce

  1. Configure OpenRouter as a provider with api_key auth mode
  2. Store API key in ~/.openclaw/agents/main/agent/auth-profiles.json
  3. Run openclaw models status --probe
  4. Observe OpenRouter probe fails with 401

Expected behavior

OpenClaw should send Authorization: Bearer <api_key> header to OpenRouter API.

Actual behavior

│ openrouter/openrouter/auto │ openrouter:default (api_key) │ auth · 694ms │ │ │ ↳ 401 Missing Authentication header

OpenClaw version

2026.3.13 (61d171a)

Operating system

Linux (Debian-based)

Install method

No response

Model

any openrouter model

Provider / routing chain

openclaw -> openrouter

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

Unable to use OpenRouter.

Additional information

Verification

• ✅ API key is valid (tested with direct curl to /models endpoint) • ✅ Environment variable OPENROUTER_API_KEY recognized by OpenClaw • ✅ Moonshot provider with same auth mode works correctly • ✅ Auth profile shows source=env: OPENROUTER_API_KEY in probe output

Suspected Cause

OpenClaw's OpenRouter provider isn't properly sending the Authorization header despite detecting the API key from auth profiles or environment variables.

extent analysis

Fix Plan

To fix the issue, we need to modify the OpenClaw's OpenRouter provider to send the Authorization: Bearer <token> header.

Here are the steps:

  • Update the openclaw.json configuration file to include the authToken property in the openrouter provider.
  • Modify the OpenClaw code to use the authToken property to send the Authorization header.

Example code snippet:

// In openclaw.json
"models": {
  "providers": {
    "openrouter": {
      "baseUrl": "https://openrouter.ai/api/v1",
      "api": "openai-completions",
      "models": [...],
      "authToken": "${OPENROUTER_API_KEY}" // Add this line
    }
  }
}

// In OpenClaw code (e.g., openrouter-provider.js)
const axios = require('axios');

// ...

const authToken = this.config.authToken;
const headers = {
  'Authorization': `Bearer ${authToken}`,
};

axios.get(this.config.baseUrl, { headers })
  .then(response => {
    // Handle response
  })
  .catch(error => {
    // Handle error
  });

Verification

To verify that the fix worked, run the following command:

openclaw models status --probe

Check the output to see if the OpenRouter probe is successful and the Authorization header is sent correctly.

Extra Tips

Make sure to update the OpenClaw code to handle cases where the authToken property is not set or is empty. Additionally, consider adding logging to verify that the Authorization header is being sent correctly.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

OpenClaw should send Authorization: Bearer <api_key> header to OpenRouter API.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix OpenRouter provider fails with "401 Missing Authentication header" despite valid API key [14 comments, 10 participants]