opencode-qwencode-auth icon indicating copy to clipboard operation
opencode-qwencode-auth copied to clipboard

invalid access token or token expired

Open mohamedbilal7 opened this issue 8 months ago • 6 comments

@luanweslley77 I installed the tool using the following command:

bun add git+https://github.com/luanweslley77/opencode-qwencode-auth.git#feat/v1.5.0-rate-limit-fix

However, I am getting the error message "invalid access token or token expired", even though I tried to re-authenticate by running the following commands:

rm ~/.qwen/oauth_creds.json opencode auth login

The error message still appears. Please suggest a solution to this problem.

Thank you.

mohamedbilal7 avatar Mar 16 '26 18:03 mohamedbilal7

could you try cd ~/.config/opencode && rm -f bun.lock and edit ~/.config/opencode/package.json to something like that

{
  "dependencies": {
    "@opencode-ai/plugin": "1.2.27",
    "opencode-qwencode-auth": "git+https://github.com/luanweslley77/opencode-qwencode-auth.git#feat/v1.5.0-rate-limit-fix"
  }
}

so run cd ~/.config/opencode && bun install

Please let me know if it worked or not.

luanweslley77 avatar Mar 16 '26 20:03 luanweslley77

@luanweslley77 I have already followed the following commands before seeing your last reply: bun remove opencode-qwencode-auth bun add github:luanweslley77/opencode-qwencode-auth#dev rm ~/.qwen/oauth_creds.json opencode auth login

This installed the latest commit from the development branch from your Fork, but the problem still persists.

Should I follow the commands you mentioned in your previous message? Please specify which branch I should update to, since there are three branches in your fork on GitHub.

mohamedbilal7 avatar Mar 16 '26 21:03 mohamedbilal7

@mohamedbilal7 Yes, follow my instructions on the feat/v1.5.0-rate-limit-fix branch. The commit I mentioned here was breaking the code. So i have force pushed to the dev branch to b730b1f5847084a846dfb4064f8c18c6d2ccad22, I tested both with the commit 76737caafdc616e87d38b3b926bc698d4e95deb3 including bun add and with the edited package.json + bun install, and also without the commit 76737caafdc616e87d38b3b926bc698d4e95deb3 including bun add and with the edited package.json + bun install. The bun add isn't working. so follow the steps i have replied

luanweslley77 avatar Mar 16 '26 21:03 luanweslley77

@luanweslley77 I followed the solution you suggested on the feat/v1.5.0-rate-limit-fix branch, but the same problem still persists.

I’ve also attached the opencode.json configuration file in case it helps identify the issue:

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "oh-my-opencode",
    "opencode-qwencode-auth"
  ],
  "enabled_providers": ["qwen", "openrouter"],
  "model": "qwen/qwen3-coder-plus",
  "small_model": "z-ai/glm-4.5-air:free",
  "provider": {
    "qwen": {
      "name": "Qwen",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://portal.qwen.ai/v1"
      },
      "models": {
        "qwen3-coder-plus": {
          "name": "Qwen3 Coder Plus",
          "limit": {
            "context": 1048576,
            "output": 65536
          }
        }
      }
    }  
  }
}

mohamedbilal7 avatar Mar 16 '26 21:03 mohamedbilal7

@mohamedbilal7

✅ Corrected Configuration (EQUIVALENT)

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "oh-my-opencode",
    "opencode-qwencode-auth"
  ],
  "enabled_providers": ["qwen-code", "openrouter"],
  "provider": {
    "qwen-code": {
      "name": "Qwen Code (OAuth)",
      "models": {
        "coder-model": {
          "name": "Qwen Coder (auto)",
          "limit": {
            "context": 1048576,
            "output": 65536
          }
        }
      }
    }
  }
}

🔄 Changes Made

Field Original (❌) Corrected (✅) Reason
enabled_providers ["qwen", ...] ["qwen-code", ...] Correct provider name in the system.
model qwen/qwen3-coder-plus (removed) Plugin already defines default model.
small_model z-ai/glm-4.5-air:free (removed) Not required in the minimal version.
provider.qwen {...} provider.qwen-code Correct key for OAuth mapping.
provider.*.name "Qwen" "Qwen Code (OAuth)" More descriptive display name.
provider.*.npm "@ai-sdk/..." (removed) Plugin manages it internally.
provider.*.options baseURL: "..." (removed) OAuth handles the URL automatically.

🎯 Minimal Version (Recommended)

{
  "$schema": "https://opencode.ai/config.json",
  "plugin": [
    "oh-my-opencode",
    "opencode-qwencode-auth"
  ]
}

Note: The plugin already registers qwen-code automatically, so provider, enabled_providers, model, and small_model are not required.


📝 Instructions for the User

# 1. Backup the old config
cp ~/.config/opencode/opencode.json ~/.config/opencode/opencode.json.backup

# 2. Update with the new configuration
# (copy and paste the corrected JSON above)

# 3. Clear old credentials
rm ~/.qwen/oauth_creds.json

# 4. Re-authenticate
opencode auth login
# Select "qwen-code" from the list

# 5. Test
opencode "Hello, Qwen!"

This corrected configuration keeps the same structure the user already had, only adjusting the names to match what the plugin actually exposes.

luanweslley77 avatar Mar 16 '26 22:03 luanweslley77

@luanweslley77 I sincerely thank you for your help, as the problem was solved after following the configurations you suggested for the opencode.json file. However, I would like you to confirm whether the plugin works with Qwen3 Coder Plus. To be honest with you, those configurations work on your fork because they are programmed specifically for it. Although my previous configurations used to work with a similar tool to a large extent, that tool has a feature to link multiple accounts and switch between them to get a higher limit.

I would appreciate it if you could take a look at it and give your opinion on it, and let me know if there’s any problem. I have used it before, You can try it via: https://github.com/foxswat/opencode-qwen-auth

mohamedbilal7 avatar Mar 16 '26 23:03 mohamedbilal7