jackwener/OpenCLI · error · AuthRequiredError

qwen.ai

Error message

qwen.ai

What it means

AuthRequiredError with site 'qwen.ai' thrown by verifyQwenIdentity when no cookie named 'token' is found among cookies for https://chat.qwen.ai (read via CDP getCookies so httpOnly cookies are visible). The library requires this token to probe the whoami API.

Source

Thrown at clis/qwen/auth.js:15

import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { registerSiteAuthCommands } from '../_shared/site-auth.js';

async function hasQwenSessionCookie(page) {
  const cookies = await page.getCookies({ url: 'https://chat.qwen.ai' });
  return cookies.some(c => c.name === 'token' && c.value);
}

async function verifyQwenIdentity(page) {
  // Source the token via CDP getCookies (works even if `token` is httpOnly,
  // which document.cookie cannot read).
  const cookies = await page.getCookies({ url: 'https://chat.qwen.ai' });
  const token = cookies.find(c => c.name === 'token')?.value || '';
  if (!token) {
    throw new AuthRequiredError('qwen.ai', 'Qwen token cookie missing');
  }
  await page.goto('https://chat.qwen.ai/');
  await page.wait(2);
  const result = await page.evaluate(`(async () => {
    try {
      const token = ${JSON.stringify(token)};
      const res = await fetch('/api/v1/auths/', { credentials: 'include', headers: { 'Authorization': 'Bearer ' + token, 'Accept': 'application/json' } });
      if (res.status === 401 || res.status === 403) {
        return { kind: 'auth', detail: 'Qwen /api/v1/auths/ HTTP ' + res.status };
      }
      if (!res.ok) return { kind: 'http', httpStatus: res.status };
      const d = await res.json();
      if (!d || !d.id) {
        return { kind: 'auth', detail: 'Qwen /api/v1/auths/ returned no user id' };
      }
      return { ok: true, user_id: String(d.id), name: String(d.name || '') };
    } catch (e) {
      return { kind: 'exception', detail: String(e && e.message || e) };

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log in to chat.qwen.ai in the automation browser profile, then retry the command.
  2. Run the library's qwen auth/login command (registerSiteAuthCommands) to perform the flow.
  3. Confirm via page.getCookies({url:'https://chat.qwen.ai'}) that a 'token' cookie exists before running commands.
  4. If you did log in but the cookie is absent, check for a cookie-name change in the site and update the library.

Example fix

// before
await askQwen(page, 'hello'); // fails: token cookie missing
// after
await qwenLogin(page);        // establish session first
await askQwen(page, 'hello');
Defensive patterns

Strategy: validation

Validate before calling

const cookies = await page.getCookies({ url: 'https://chat.qwen.ai' });
if (!cookies.some(c => c.name === 'token' && c.value)) {
  console.error('qwen.ai token cookie missing - login required');
  process.exit(2);
}

Type guard

function hasQwenToken(cookies) {
  return Array.isArray(cookies) && cookies.some(c => c.name === 'token' && !!c.value);
}

Try / catch

try {
  await verifyQwenIdentity(page);
} catch (e) {
  if (e instanceof AuthRequiredError) {
    await qwenLogin(page);
    await verifyQwenIdentity(page);
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling any qwen command that verifies identity while the browser profile has no qwen.ai session: never logged in, cookies cleared, or an expired session where the server dropped the token cookie.

Common situations: Fresh automation profile without login; cookie jar wiped by profile reset or incognito run; qwen.ai rotating/renaming the auth cookie after a site update.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/3975435d6778254d. Report an issue: GitHub.