SillyTavern/SillyTavern · error · Error

Workers AI API key or account ID is not set.

Error message

Workers AI API key or account ID is not set.

What it means

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.

Source

Thrown at public/scripts/extensions/shared.js:292

    if (multimodalApi === 'electronhub' && !secret_state[SECRET_KEYS.ELECTRONHUB]) {
        throw new Error('Electron Hub API key is not set.');
    }

    if (multimodalApi === 'chutes' && !secret_state[SECRET_KEYS.CHUTES]) {
        throw new Error('Chutes API key is not set.');
    }

    if (multimodalApi === 'zai' && !secret_state[SECRET_KEYS.ZAI]) {
        throw new Error('Z.AI API key is not set.');
    }

    if (multimodalApi === 'pollinations' && !secret_state[SECRET_KEYS.POLLINATIONS]) {
        throw new Error('Pollinations API key is not set.');
    }

    if (multimodalApi === 'workers_ai' && (!secret_state[SECRET_KEYS.WORKERS_AI] || !oai_settings.workers_ai_account_id)) {
        throw new Error('Workers AI API key or account ID is not set.');
    }
}

/**
 * Check if the WebLLM extension is installed and supported.
 * @returns {boolean} Whether the extension is installed and supported
 */
export function isWebLlmSupported() {
    if (!('gpu' in navigator)) {
        const warningKey = 'webllm_browser_warning_shown';
        if (!sessionStorage.getItem(warningKey)) {
            toastr.error('Your browser does not support the WebGPU API. Please use a different browser.', 'WebLLM', {
                preventDuplicates: true,
                timeOut: 0,
                extendedTimeOut: 0,
            });
            sessionStorage.setItem(warningKey, '1');
        }

View on GitHub (pinned to 8172dcd0ee)

Solutions

  1. Open the Secrets panel and save a valid Cloudflare Workers AI API token.
  2. In Chat Completion settings (Workers AI source), enter your Cloudflare Account ID into oai_settings.workers_ai_account_id.
  3. Both values are required — confirm both are set; get the Account ID from the Cloudflare dashboard sidebar.

Example fix

// before: secret_state[SECRET_KEYS.WORKERS_AI] = true; oai_settings.workers_ai_account_id = '';
// after:  oai_settings.workers_ai_account_id = 'a1b2c3d4...';
Defensive patterns

Strategy: validation

Validate before calling

import { SECRET_KEYS, secret_state } from '../secrets.js';
import { oai_settings } from '../openai.js';
import { extension_settings } from '../extensions.js';

function canCaptionWithWorkersAi() {
  const cap = extension_settings.caption;
  if (cap.multimodal_api !== 'workers_ai') return true;
  return Boolean(secret_state[SECRET_KEYS.WORKERS_AI]) && Boolean(oai_settings.workers_ai_account_id);
}
if (!canCaptionWithWorkersAi()) {
  toastr.warning('Workers AI needs both an API token and a Cloudflare Account ID.');
}

Type guard

function isWorkersAiConfigured(): boolean {
  const cap = extension_settings.caption;
  return cap.multimodal_api !== 'workers_ai'
    || (Boolean(secret_state[SECRET_KEYS.WORKERS_AI]) && Boolean(oai_settings.workers_ai_account_id));
}

Try / catch

try { return await getMultimodalCaption(img, prompt); }
catch (e) {
  if (e.message === 'Workers AI API key or account ID is not set.') {
    toastr.warning('Add the Workers AI token and Account ID.');
    return '';
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of SillyTavern/SillyTavern@8172dcd0ee (2026-08-13). Data as JSON: /api/errors/91979293a9de25dc. Report an issue: GitHub.