vercel/ai · error · TooManyEmbeddingValuesForCallError

Too many values for a single embedding call. The ${provider}

Error message

Too many values for a single embedding call. The ${provider} model "${modelId}" can only embed up to ${maxEmbeddingsPerCall} values per call, but ${values.length} values were provided.

What it means

The Mistral embedding model supports a fixed maximum number of values per doEmbed call (maxEmbeddingsPerCall). Passing more values than that throws TooManyEmbeddingValuesForCallError before any request is made, since the Mistral API cannot embed that many inputs in one call.

Source

Thrown at packages/mistral/src/mistral-embedding-model.ts:72

  constructor(
    modelId: MistralEmbeddingModelId,
    config: MistralEmbeddingConfig,
  ) {
    this.modelId = modelId;
    this.config = config;
  }

  async doEmbed({
    values,
    abortSignal,
    headers,
    providerOptions,
  }: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<
    Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>
  > {
    if (values.length > this.maxEmbeddingsPerCall) {
      throw new TooManyEmbeddingValuesForCallError({
        provider: this.provider,
        modelId: this.modelId,
        maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
        values,
      });
    }

    const mistralOptions =
      (await parseProviderOptions({
        provider: 'mistral',
        providerOptions,
        schema: mistralEmbeddingModelOptions,
      })) ?? {};

    const {
      responseHeaders,
      value: response,
      rawValue,

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Chunk your values into batches no larger than maxEmbeddingsPerCall and call embedMany repeatedly.
  2. Check model.maxEmbeddingsPerCall at runtime to size your batches.
  3. Use embedMany's built-in support with a smaller input array.
  4. Update @ai-sdk/mistral in case limits changed across versions.

Example fix

// before
await embedMany({ model, values: all1000Docs });
// after
const batches = chunk(all1000Docs, model.maxEmbeddingsPerCall);
const results = [];
for (const b of batches) {
  results.push(await embedMany({ model, values: b }));
}
Defensive patterns

Strategy: validation

Validate before calling

if (values.length > model.maxEmbeddingsPerCall) {
  throw new Error(`Chunk to <= ${model.maxEmbeddingsPerCall} values per call`);
}
// or chunk proactively:
const batchSize = model.maxEmbeddingsPerCall;
const batches = [];
for (let i = 0; i < values.length; i += batchSize) batches.push(values.slice(i, i + batchSize));

Try / catch

try {
  return await embedMany({ model, values });
} catch (error) {
  if (TooManyEmbeddingValuesForCallError.isInstance(error)) {
    const { maxEmbeddingsPerCall, values } = error;
    const batches = [];
    for (let i = 0; i < values.length; i += maxEmbeddingsPerCall) {
      batches.push(values.slice(i, i + maxEmbeddingsPerCall));
    }
    return (await Promise.all(batches.map(b => embedMany({ model, values: b })))).flat();
  }
  throw error;
}

Prevention

When it happens

Trigger: Calling embed/embedMany with more input values than the model's maxEmbeddingsPerCall in a single call, e.g. embedding hundreds of documents at once against mistral-embed.

Common situations: Bulk-embedding document collections or large batches in one call; assuming unlimited batch size like some other providers; batch pipelines not chunked for Mistral limits.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/d1597bd8ebddbe6a. Report an issue: GitHub.