{"record":{"id":"91979293a9de25dc","repo":"SillyTavern/SillyTavern","slug":"workers-ai-api-key-or-account-id-is-not-set","errorCode":null,"errorMessage":"Workers AI API key or account ID is not set.","messagePattern":"Workers AI API key or account ID is not set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"public/scripts/extensions/shared.js","lineNumber":292,"sourceCode":"\n    if (multimodalApi === 'electronhub' && !secret_state[SECRET_KEYS.ELECTRONHUB]) {\n        throw new Error('Electron Hub API key is not set.');\n    }\n\n    if (multimodalApi === 'chutes' && !secret_state[SECRET_KEYS.CHUTES]) {\n        throw new Error('Chutes API key is not set.');\n    }\n\n    if (multimodalApi === 'zai' && !secret_state[SECRET_KEYS.ZAI]) {\n        throw new Error('Z.AI API key is not set.');\n    }\n\n    if (multimodalApi === 'pollinations' && !secret_state[SECRET_KEYS.POLLINATIONS]) {\n        throw new Error('Pollinations API key is not set.');\n    }\n\n    if (multimodalApi === 'workers_ai' && (!secret_state[SECRET_KEYS.WORKERS_AI] || !oai_settings.workers_ai_account_id)) {\n        throw new Error('Workers AI API key or account ID is not set.');\n    }\n}\n\n/**\n * Check if the WebLLM extension is installed and supported.\n * @returns {boolean} Whether the extension is installed and supported\n */\nexport function isWebLlmSupported() {\n    if (!('gpu' in navigator)) {\n        const warningKey = 'webllm_browser_warning_shown';\n        if (!sessionStorage.getItem(warningKey)) {\n            toastr.error('Your browser does not support the WebGPU API. Please use a different browser.', 'WebLLM', {\n                preventDuplicates: true,\n                timeOut: 0,\n                extendedTimeOut: 0,\n            });\n            sessionStorage.setItem(warningKey, '1');\n        }","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/SillyTavern/SillyTavern/blob/8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8/public/scripts/extensions/shared.js#L274-L310","documentation":"Thrown by throwIfInvalidModel() when the caption backend is 'workers_ai' AND either secret_state[SECRET_KEYS.WORKERS_AI] is unset OR oai_settings.workers_ai_account_id is empty. Cloudflare Workers AI requires both an API token and the target account ID to build the route URL (https://api.cloudflare.com/client/v4/accounts/{id}/ai/...), so the guard fails on either missing piece. This is a two-part precondition specific to Workers AI.","triggerScenarios":"Caption provider set to 'Workers AI' and captioning triggered when either the Workers AI API token was never stored, or the Cloudflare Account ID field under Chat Completion > Workers AI was left blank.","commonSituations":"Token entered but account ID forgotten; account ID entered but token missing; both missing on fresh setup; user copied the account ID with whitespace or a wrong field.","solutions":["Open the Secrets panel and save a valid Cloudflare Workers AI API token.","In Chat Completion settings (Workers AI source), enter your Cloudflare Account ID into oai_settings.workers_ai_account_id.","Both values are required — confirm both are set; get the Account ID from the Cloudflare dashboard sidebar."],"exampleFix":"// before: secret_state[SECRET_KEYS.WORKERS_AI] = true; oai_settings.workers_ai_account_id = '';\n// after:  oai_settings.workers_ai_account_id = 'a1b2c3d4...';","handlingStrategy":"validation","validationCode":"import { SECRET_KEYS, secret_state } from '../secrets.js';\nimport { oai_settings } from '../openai.js';\nimport { extension_settings } from '../extensions.js';\n\nfunction canCaptionWithWorkersAi() {\n  const cap = extension_settings.caption;\n  if (cap.multimodal_api !== 'workers_ai') return true;\n  return Boolean(secret_state[SECRET_KEYS.WORKERS_AI]) && Boolean(oai_settings.workers_ai_account_id);\n}\nif (!canCaptionWithWorkersAi()) {\n  toastr.warning('Workers AI needs both an API token and a Cloudflare Account ID.');\n}","typeGuard":"function isWorkersAiConfigured(): boolean {\n  const cap = extension_settings.caption;\n  return cap.multimodal_api !== 'workers_ai'\n    || (Boolean(secret_state[SECRET_KEYS.WORKERS_AI]) && Boolean(oai_settings.workers_ai_account_id));\n}","tryCatchPattern":"try { return await getMultimodalCaption(img, prompt); }\ncatch (e) {\n  if (e.message === 'Workers AI API key or account ID is not set.') {\n    toastr.warning('Add the Workers AI token and Account ID.');\n    return '';\n  }\n  throw e;\n}","preventionTips":["Show two required fields (token + account ID) together in the Workers AI settings with both marked mandatory.","Trim whitespace from the account ID on save — a common copy-paste failure."],"tags":["multimodal","workers-ai","cloudflare","api-key","account-id","caption","validation"],"backgroundTag":null,"analyzedSha":"8172dcd0ee672d3cd9a5e5f7af134f91a45cd2b8","analyzedAt":"2026-08-13T07:48:40.832Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}