SillyTavern/SillyTavern · error · Error

${apiName} did not return an array

Error message

${apiName} did not return an array

What it means

After a successful Google batch embedding response, the code asserts Array.isArray(data?.embeddings); if absent it throws `${apiName} did not return an array`. This guards the expected response shape where data.embeddings is an array of objects each with a `.values` field.

Source

Thrown at src/vectors/google-vectors.js:36

        })),
    };

    const response = await fetch(url, {
        body: JSON.stringify(body),
        method: 'POST',
        headers: headers,
    });

    if (!response.ok) {
        const text = await response.text();
        console.warn(`${apiName} batch request failed`, response.statusText, text);
        throw new Error(`${apiName} batch request failed`);
    }

    /** @type {any} */
    const data = await response.json();
    if (!Array.isArray(data?.embeddings)) {
        throw new Error(`${apiName} did not return an array`);
    }

    const embeddings = data.embeddings.map(embedding => embedding.values);
    return embeddings;
}

/**
 * Gets the vector for the given text from Google Vertex AI
 * @param {string[]} texts - The array of texts to get the vector for
 * @param {string} model - The model to use for embedding
 * @param {import('express').Request} request - The request object to get API key and URL
 * @returns {Promise<number[][]>} - The array of vectors for the texts
 */
export async function getVertexBatchVector(texts, model, request) {
    const { url, headers, apiName } = await getGoogleApiConfig(request, model, 'predict');

    const body = {
        instances: texts.map(text => ({ content: text })),

View on GitHub (pinned to 8172dcd0ee)

Solutions

  1. Inspect the actual response body to confirm the returned shape.
  2. Ensure the texts array passed in is non-empty and valid.
  3. Update the parser if Google changed the field name for this API version.
  4. Rule out an intermediary proxy returning a non-standard body.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the batch is non-empty and texts are strings
if (!Array.isArray(texts) || texts.length === 0 || texts.some(t => typeof t !== 'string')) {
    throw new Error('texts must be a non-empty array of strings');
}

Type guard

function isGoogleBatchResponse(data) {
    return !!data && Array.isArray(data?.embeddings);
}

Try / catch

try {
    return await getGoogleBatchVector(texts, model, request);
} catch (e) {
    if (e.message.endsWith('did not return an array')) {
        // log raw body; degrade gracefully
    } else throw e;
}

Prevention

When it happens

Trigger: Google returns 2xx but data.embeddings is missing or not an array: response schema changed, the request produced an empty result, or an error envelope was returned with 2xx by a proxy.

Common situations: Google API version change altering the response structure, empty input texts array producing an empty/absent embeddings field, or a gateway rewriting the body.

Related errors


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