SillyTavern/SillyTavern · error

Internal error

Error message

Internal error

What it means

Catch-all for the AIMLAPI generate flow. It catches the explicit throws ('Failed to fetch image URL' when blobRes is not ok, 'Unsupported image format' when imgObj has no usable field), plus network errors and .json() parse failures, and returns a generic 'Internal error' string that discards the actual error detail.

Source

Thrown at src/endpoints/stable-diffusion.js:1867

        const imgObj = Array.isArray(data.images) ? data.images[0] : data.data?.[0];
        if (!imgObj) return res.status(500).send('No image returned');

        let base64;
        if (imgObj.b64_json || imgObj.base64) {
            base64 = imgObj.b64_json || imgObj.base64;
        } else if (imgObj.url) {
            const blobRes = await fetch(imgObj.url);
            if (!blobRes.ok) throw new Error('Failed to fetch image URL');
            const buffer = await blobRes.arrayBuffer();
            base64 = Buffer.from(buffer).toString('base64');
        } else {
            throw new Error('Unsupported image format');
        }

        return res.json({ format: 'png', data: base64 });
    } catch (e) {
        console.error(e);
        res.status(500).send('Internal error');
    }
});

const zai = express.Router();

zai.post('/generate', async (request, response) => {
    try {
        const key = readSecret(request.user.directories, SECRET_KEYS.ZAI);

        if (!key) {
            console.warn('Z.AI key not found.');
            return response.sendStatus(400);
        }

        console.debug('Z.AI image request:', request.body);

        // Always use Common API for image generation (Coding API has stricter rate limits)
        const generateResponse = await fetch('https://api.z.ai/api/paas/v4/images/generations', {

View on GitHub (pinned to 8172dcd0ee)

Solutions

  1. Send e.message (and log e) instead of the static 'Internal error' so the real cause is visible.
  2. Handle the url-fetch failure with a retry and log the failing URL/status.
  3. Support additional image fields before throwing 'Unsupported image format'.

Example fix

// before
    } catch (e) {
        console.error(e);
        res.status(500).send('Internal error');
    }
// after
    } catch (e) {
        console.error('AIMLAPI generate failed:', e);
        res.status(500).send(e?.message || 'Internal error');
    }
Defensive patterns

Strategy: try-catch

Type guard

/** @param {any} o */
function hasUsableImage(o) {
  return Boolean(o) && (Boolean(o.b64_json) || Boolean(o.base64) || typeof o.url === 'string');
}

Try / catch

} catch (e) {
  console.error('AIMLAPI generate failed:', e);
  res.status(500).send(e?.message || 'Internal error');
}

Prevention

When it happens

Trigger: imgObj has neither b64_json/base64 nor url (throws 'Unsupported image format'); imgObj.url returns non-2xx on fetch (throws 'Failed to fetch image URL'); network drop; apiRes.json() parse failure.

Common situations: Model returns a URL that 403s without auth; model returns a format the handler does not recognise; schema change; transient network error.

Related errors


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