{"record":{"id":"e1b4601d7d533438","repo":"vercel/ai","slug":"anthropic-message-batches-do-not-support-per-reque","errorCode":null,"errorMessage":"Anthropic Message Batches do not support per-request betas (request \"${request.id}\"). Set providerOptions.anthropic.anthropicBeta on startTextBatch instead.","messagePattern":"Anthropic Message Batches do not support per-request betas \\(request \"(.+?)\"\\)\\. Set providerOptions\\.anthropic\\.anthropicBeta on startTextBatch instead\\.","errorType":"exception","errorClass":"UnsupportedFunctionalityError","httpStatus":null,"severity":"error","filePath":"packages/anthropic/src/anthropic-messages-batch.ts","lineNumber":215,"sourceCode":"        ? []\n        : [\n            {\n              warning: {\n                type: 'unsupported',\n                feature: 'webhookUrl',\n                details:\n                  'The Anthropic Message Batches API does not support completion webhooks.',\n              },\n            },\n          ];\n\n    for (const request of requests) {\n      const requestBetas = await getAnthropicBatchProviderBetas({\n        provider: this.config.provider,\n        providerOptions: request.options.providerOptions,\n      });\n      if (requestBetas.length > 0) {\n        throw new UnsupportedFunctionalityError({\n          functionality: 'per-request providerOptions.anthropic.anthropicBeta',\n          message:\n            `Anthropic Message Batches do not support per-request betas ` +\n            `(request \"${request.id}\"). Set providerOptions.anthropic.anthropicBeta ` +\n            `on startTextBatch instead.`,\n        });\n      }\n\n      const prepared = await this.getArgs({\n        ...request.options,\n        stream: false,\n        userSuppliedBetas: new Set(explicitBatchBetas),\n      });\n      if (prepared.usesJsonResponseTool) {\n        throw new UnsupportedFunctionalityError({\n          functionality: 'batch responseFormat JSON-tool fallback',\n          message:\n            `Anthropic Message Batches cannot decode the JSON-tool structured-output fallback ` +","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/anthropic/src/anthropic-messages-batch.ts#L197-L233","documentation":"Anthropic Message Batches apply beta headers at the batch level, so per-request `providerOptions.anthropic.anthropicBeta` values are unsupported. experimental_doStartBatch checks each request's betas and throws an UnsupportedFunctionalityError naming the request and directing you to set the beta on startTextBatch instead.","triggerScenarios":"Calling `experimental_doStartBatch` (via batch start) with requests that carry `providerOptions: { anthropic: { anthropicBeta: ... } }` — any non-empty per-request betas list triggers the error.","commonSituations":"Reusing a standard streaming requestOptions object for batch requests; copying code that sets anthropicBeta per request for prompt caching or context management into batch workflows.","solutions":["Remove anthropicBeta from individual request providerOptions.","Pass `providerOptions.anthropic.anthropicBeta` at the startTextBatch level instead.","Verify after refactor that the batch call no longer includes per-request betas."],"exampleFix":"// before\nawait model.experimental_doStartBatch({\n  requests: [{ id: '1', options: { providerOptions: { anthropic: { anthropicBeta: ['context-1h'] } } } }],\n});\n// after\nawait model.experimental_doStartBatch({\n  providerOptions: { anthropic: { anthropicBeta: ['context-1h'] } },\n  requests: [{ id: '1', options: {} }],\n});","handlingStrategy":"validation","validationCode":"const perRequestBetas = request.options?.providerOptions?.anthropic?.anthropicBeta;\nif (perRequestBetas) throw new Error('Move anthropicBeta to startTextBatch-level providerOptions');","typeGuard":"function hasPerRequestBetas(req: { options?: { providerOptions?: { anthropic?: { anthropicBeta?: unknown } } } }): boolean {\n  const b = req.options?.providerOptions?.anthropic?.anthropicBeta;\n  return Array.isArray(b) ? b.length > 0 : b != null;\n}","tryCatchPattern":"try {\n  await model.experimental_doStartBatch(args);\n} catch (e) {\n  if (e instanceof Error && e.message.includes('do not support per-request betas')) {\n    // hoist anthropicBeta to startTextBatch-level providerOptions\n  }\n  throw e;\n}","preventionTips":["Never attach anthropicBeta to per-request providerOptions in batch workflows.","Set betas once at the batch level.","Strip request-level providerOptions when converting streaming code to batch code."],"tags":["batches","unsupported-feature","anthropic","provider-options"],"backgroundTag":"unsupported-feature","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}