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
- Log in to chat.qwen.ai in the automation browser profile, then retry the command.
- Run the library's qwen auth/login command (registerSiteAuthCommands) to perform the flow.
- Confirm via page.getCookies({url:'https://chat.qwen.ai'}) that a 'token' cookie exists before running commands.
- 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
- Use a persistent (non-incognito) browser profile with an active qwen.ai session
- Verify the token cookie exists before batch runs
- Re-login proactively when sessions age out
- Watch for site cookie-name changes after qwen.ai updates
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
- Chaoxing session cookies missing
- Claude sessionKey cookie missing
- Claude session incomplete — ajs_user_id cookie missing
- Google session cookies are missing
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3975435d6778254d.
Report an issue: GitHub.