jackwener/OpenCLI · error · AuthRequiredError
Bilibili ${label} API requires login or permission: ${messag
Error message
Bilibili ${label} API requires login or permission: ${message} (${payload.code}) What it means
When the Bilibili API returns a non-zero code of -101 or -403, or the message text matches login/permission keywords (登录/权限/forbidden/permission/login), requireOkPayload() throws AuthRequiredError for the bilibili.com realm. These codes mean the endpoint requires an authenticated session (cookies such as SESSDATA) or the account lacks permission for the content.
Source
Thrown at clis/bilibili/summary.js:65
if (!B23_HOST_RE.test(parsed.hostname)) {
throw new ArgumentError('Bilibili summary URL must be a bilibili.com or b23.tv URL');
}
}
try {
return await resolveBvid(input);
} catch (error) {
throw new ArgumentError(`Cannot resolve Bilibili BV ID from input: ${input}`, error instanceof Error ? error.message : String(error));
}
}
function requireOkPayload(payload, label) {
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
throw new CommandExecutionError(`Bilibili ${label} API returned a malformed payload`);
}
if (payload.code !== 0) {
const message = payload.message ?? 'unknown error';
if (payload.code === -101 || payload.code === -403 || /登录|权限|forbidden|permission|login/i.test(String(message))) {
throw new AuthRequiredError('bilibili.com', `Bilibili ${label} API requires login or permission: ${message} (${payload.code})`);
}
throw new CommandExecutionError(`Bilibili ${label} API failed: ${message} (${payload.code})`);
}
return payload.data;
}
function readModelResult(data, bvid) {
if (!data || typeof data !== 'object' || Array.isArray(data)) {
throw new CommandExecutionError('Bilibili conclusion API returned malformed data');
}
if (data.code !== 0) {
throw new EmptyResultError('bilibili summary', `Bilibili has not generated an AI summary for ${bvid}.`);
}
let modelResult = data.model_result;
if (typeof modelResult === 'string') {
try {
modelResult = JSON.parse(modelResult);
} catch {View on GitHub (pinned to 49907e53dc)
Solutions
- Log in to bilibili.com in a browser and export fresh cookies (SESSDATA) into the CLI's credential/config store.
- Re-export cookies if they were rotated/expired (code -101).
- For -403, verify the account can view the video in a browser (charged/members-only/region-locked content cannot be summarized).
- Retry the command after refreshing credentials.
Example fix
// before OPENCLI_BILIBILI_COOKIE= cli summary BV1xx411c7mD // no cookies -> -101 // after OPENCLI_BILIBILI_COOKIE="SESSDATA=...; buvid3=..." cli summary BV1xx411c7mD
Defensive patterns
Strategy: try-catch
Validate before calling
if (!cookies || !/SESSDATA=/.test(cookies)) {
console.warn('No SESSDATA cookie configured; restricted videos will fail with auth errors');
} Type guard
function hasBilibiliCredentials(config) {
return typeof config?.cookie === 'string' && config.cookie.includes('SESSDATA=');
} Try / catch
try {
const summary = await summaryCommand(bvid);
} catch (e) {
if (e.name === 'AuthRequiredError' || /requires login or permission/.test(e.message)) {
await refreshBilibiliCookies(); // re-export SESSDATA from browser
return summaryCommand(bvid);
}
throw e;
} Prevention
- Keep fresh SESSDATA cookies in the CLI config; re-export after re-login or cookie rotation.
- Test whether the video is viewable while logged in before summarizing restricted content.
- In CI, inject cookies via secrets rather than relying on anonymous access.
- Expect -101/-403 for members-only, charged, or region-locked videos — filter them out beforehand.
When it happens
Trigger: Calling view/conclusion endpoints without a logged-in cookie jar; SESSDATA cookie expired; the video is region-locked or restricted (charged/members-only content) returning code -403; API message containing 登录/权限 keywords.
Common situations: Cookie expired after Bilibili invalidated sessions; running headless/CI without exporting browser cookies; accessing premium or region-locked videos; Bilibili tightening anonymous access to web-interface endpoints.
Related errors
- Bilibili ${label} API requires login or permission: ${messag
- 12306 tk auth cookie missing
- amazon.com
- Bilibili creator-center login is required: ${message}
- Bilibili creator-center login is required: ${detail}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/1d930d0f04caed01.
Report an issue: GitHub.