vercel/ai · error · TooManyEmbeddingValuesForCallError

AI_TooManyEmbeddingValuesForCallError

AI_TooManyEmbeddingValuesForCallError

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

Bedrock embedding models accept only maxEmbeddingsPerCall values per doEmbed request. When you pass more values than the model's per-call limit, the SDK throws AI_TooManyEmbeddingValuesForCallError instead of silently truncating. The `embedMany` helper normally batches automatically; this error surfaces when calling the model's doEmbed directly or when batch size is forced.

Solutions

  1. Split your inputs into chunks no larger than the model's maxEmbeddingsPerCall (embedMany does this automatically — pass the full array to embedMany rather than calling doEmbed directly)
  2. Check model.maxEmbeddingsPerCall before calling doEmbed and slice your values array accordingly
  3. Use the top-level embed()/embedMany() API instead of the low-level doEmbed method
  4. If you need larger batches, pick a Bedrock embedding model with a higher per-call limit

Example fix

// before
await model.doEmbed({ values: docs }); // 500 docs, limit 32
// after
const BATCH = model.maxEmbeddingsPerCall;
for (let i = 0; i < docs.length; i += BATCH) {
  await model.doEmbed({ values: docs.slice(i, i + BATCH) });
}
Defensive patterns

Strategy: validation

Validate before calling

const max = model.maxEmbeddingsPerCall;
if (values.length > max) throw new Error(`Chunk inputs to <= ${max} values per call`);
// or: chunk and call per chunk

Try / catch

try {
  await embedMany({ model, values });
} catch (e) {
  if (TooManyEmbeddingValuesForCallError.isInstance(e)) {
    // chunk values by e.maxEmbeddingsPerCall and retry
  }
}

Prevention

When it happens

Trigger: Calling embedMany/embed with more input values than the model's maxEmbeddingsPerCall (Bedrock Titan models commonly cap at 1–32), or calling model.doEmbed directly with an oversized array.

Common situations: Batching thousands of documents into a single embed call; copying code from another provider whose models allow 2048 inputs per call; overriding maxEmbeddingsPerCall or using maxCallsPerRound/maxEntriesPerCall options incorrectly.

Related errors


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

Appendix: source

Thrown at packages/amazon-bedrock/src/amazon-bedrock-embedding-model.ts:79

  constructor(
    readonly modelId: AmazonBedrockEmbeddingModelId,
    private readonly config: AmazonBedrockEmbeddingConfig,
  ) {}

  private getUrl(modelId: string): string {
    const encodedModelId = encodeURIComponent(modelId);
    return `${this.config.baseUrl()}/model/${encodedModelId}/invoke`;
  }

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

    // Parse provider options. Prefer `amazonBedrock`; fall back to legacy
    // `bedrock` key for backward compatibility.
    const amazonBedrockOptions =
      (await parseProviderOptions({
        provider: 'amazonBedrock',
        providerOptions,
        schema: amazonBedrockEmbeddingModelOptionsSchema,
      })) ??
      (await parseProviderOptions({
        provider: 'bedrock',
        providerOptions,

View on GitHub (pinned to 69428b1f8b)