Skip to content

OpenRouter Provider Initialization Error (400 Bad Request) #863

Closed

Description

@sivaxreddy

I'm encountering an issue when trying to use the OpenRouter provider with opencode. I'm consistently receiving a 400 Bad Request error during message sending, indicating a ProviderInitError specifically for the openrouter provider. This happens even after ensuring my apiKey is correctly placed in the config.json.


failed to send message: POST
"[http://127.0.0.1:45365/session/ses\_808f933dfffe1R6hPvcSMMWQuX/message](http://127.0.0.1:45365/session/ses_808f933dfffe1R6hPvcSMMWQuX/message)": 400 Bad Request
{"name":"ProviderInitError","data":{"providerID":"openrouter"}}


Configuration (config.json):

{
  "$schema": "[https://opencode.ai/config.json](https://opencode.ai/config.json)",
  "provider": {
    "openrouter": {
      "npm": "@openrouter/ai-sdk-provider",
      "name": "OpenRouter",
      "options": {
        "apiKey": "YOUR-API-KEY" 
      },
      "models": {
        "deepseek/deepseek-r1-0528:free": {
          "name": "Deepseek R1 0528 (free)"
        },
        "deepseek/deepseek-chat-v3-0324:free": {
          "name": "Deepseek Chat V3 0324 (free)"
        },
        "meta-llama/llama-4-maverick:free": {
          "name": "meta-llama/llama-4-maverick:free"
        }
      }
    }
  }
}

Activity

  1. DenzelVH commented on Jul 11, 2025

    @DenzelVH
  2. facelezzzz commented on Jul 11, 2025

    @facelezzzz

    This is a bug because NPM package is not installed.

    You can try
    cd ~/.cache/opencode
    pnpm install

  3. sivaxreddy commented on Jul 11, 2025

    @sivaxreddy
    Author

    can u link me to any other config which uses deepseek or qwen models from openrouter, i am unable to other models (apart from gemini, claude,gpts)

  4. thdxr commented on Jul 12, 2025

    @thdxr
    Member

    get rid of the npm field you don't need it - and update to latest

    realized our docs were saying the wrong thing - fixed

  5. self-assigned this
    on Jul 12, 2025
  6. iwinux commented on Jul 12, 2025

    @iwinux

    I see a subprocess of opencode add @ai-sdk/openai-compatible every time I restart the CLI. What is happening!?

  7. sivaxreddy commented on Jul 13, 2025

    @sivaxreddy
    Author

    no idea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions