Skip to content

Fix OpenRouter 401 'User not found' authentication error#3

Merged
leifiyoo merged 1 commit intomainfrom
fix/openrouter-auth-401
Feb 14, 2026
Merged

Fix OpenRouter 401 'User not found' authentication error#3
leifiyoo merged 1 commit intomainfrom
fix/openrouter-auth-401

Conversation

@kilo-code-bot
Copy link
Contributor

@kilo-code-bot kilo-code-bot bot commented Feb 14, 2026

Problem

The CLI app throws a 401 "User not found" error when trying to use the OpenRouter API, retrying 3 times before failing.

Root Cause

Two issues were identified:

  1. Placeholder API keys not rejected — The getApiKey() function in src/model/llm.ts did not validate whether the API key was a placeholder value (e.g., your-api-key from env.example). If a user copied env.example to .env without replacing the placeholder, the invalid key would be sent to OpenRouter, resulting in a 401 "User not found" error. Note: checkApiKeyExists() in src/utils/env.ts already had this validation, but getApiKey() did not.

  2. Missing required OpenRouter headers — OpenRouter's API requires HTTP-Referer and X-Title headers for proper request identification. Without these headers, authentication can fail or be unreliable.

Changes

  • src/model/llm.ts:
    • Added placeholder value detection in getApiKey() — rejects keys starting with your- with a clear error message
    • Improved error messages to guide users on proper .env setup
    • Added HTTP-Referer and X-Title default headers to the OpenRouter configuration

How to Set Up the API Key

  1. Copy the example environment file:

    cp env.example .env
  2. Edit .env and replace the placeholder with your actual OpenRouter API key:

    OPENROUTER_API_KEY=sk-or-v1-your-actual-key-here
    
  3. Get your API key from OpenRouter

Alternatively, you can set the key interactively in the CLI using the /model command and selecting OpenRouter as the provider.


Built for 87wf9xdgz8 by Kilo for Slack

…eaders

- Add placeholder value detection in getApiKey() to reject 'your-api-key' style values
  that would be sent to OpenRouter causing 401 'User not found' errors
- Add HTTP-Referer and X-Title headers required by OpenRouter API
- Improve error messages to guide users on proper .env setup
@leifiyoo leifiyoo merged commit 12cb337 into main Feb 14, 2026
1 of 2 checks passed
@leifiyoo leifiyoo deleted the fix/openrouter-auth-401 branch February 14, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant