{"record":{"id":"d1597bd8ebddbe6a","repo":"vercel/ai","slug":"too-many-values-for-a-single-embedding-call-the-d1597b","errorCode":null,"errorMessage":"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.","messagePattern":"Too many values for a single embedding call\\. The (.+?) model \"(.+?)\" can only embed up to (.+?) values per call, but (.+?) values were provided\\.","errorType":"validation","errorClass":"TooManyEmbeddingValuesForCallError","httpStatus":null,"severity":"error","filePath":"packages/mistral/src/mistral-embedding-model.ts","lineNumber":72,"sourceCode":"\n  constructor(\n    modelId: MistralEmbeddingModelId,\n    config: MistralEmbeddingConfig,\n  ) {\n    this.modelId = modelId;\n    this.config = config;\n  }\n\n  async doEmbed({\n    values,\n    abortSignal,\n    headers,\n    providerOptions,\n  }: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<\n    Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>\n  > {\n    if (values.length > this.maxEmbeddingsPerCall) {\n      throw new TooManyEmbeddingValuesForCallError({\n        provider: this.provider,\n        modelId: this.modelId,\n        maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,\n        values,\n      });\n    }\n\n    const mistralOptions =\n      (await parseProviderOptions({\n        provider: 'mistral',\n        providerOptions,\n        schema: mistralEmbeddingModelOptions,\n      })) ?? {};\n\n    const {\n      responseHeaders,\n      value: response,\n      rawValue,","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/mistral/src/mistral-embedding-model.ts#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Chunk your values into batches no larger than maxEmbeddingsPerCall and call embedMany repeatedly.","Check model.maxEmbeddingsPerCall at runtime to size your batches.","Use embedMany's built-in support with a smaller input array.","Update @ai-sdk/mistral in case limits changed across versions."],"exampleFix":"// before\nawait embedMany({ model, values: all1000Docs });\n// after\nconst batches = chunk(all1000Docs, model.maxEmbeddingsPerCall);\nconst results = [];\nfor (const b of batches) {\n  results.push(await embedMany({ model, values: b }));\n}","handlingStrategy":"validation","validationCode":"if (values.length > model.maxEmbeddingsPerCall) {\n  throw new Error(`Chunk to <= ${model.maxEmbeddingsPerCall} values per call`);\n}\n// or chunk proactively:\nconst batchSize = model.maxEmbeddingsPerCall;\nconst batches = [];\nfor (let i = 0; i < values.length; i += batchSize) batches.push(values.slice(i, i + batchSize));","typeGuard":null,"tryCatchPattern":"try {\n  return await embedMany({ model, values });\n} catch (error) {\n  if (TooManyEmbeddingValuesForCallError.isInstance(error)) {\n    const { maxEmbeddingsPerCall, values } = error;\n    const batches = [];\n    for (let i = 0; i < values.length; i += maxEmbeddingsPerCall) {\n      batches.push(values.slice(i, i + maxEmbeddingsPerCall));\n    }\n    return (await Promise.all(batches.map(b => embedMany({ model, values: b })))).flat();\n  }\n  throw error;\n}","preventionTips":["Always chunk inputs to model.maxEmbeddingsPerCall before embedding.","Read maxEmbeddingsPerCall from the model object rather than hardcoding limits.","Add a batch-size unit test for every embedding model you use."],"tags":["mistral","embeddings","batch-limit","too-many-values"],"backgroundTag":"too-many-embedding-values","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}