SIGN IN SIGN UP

feat(anthropic): preserve message batch metadata (#19643)

## context

AI SDK already supports creating, polling, and reading Anthropic Message
Batches. This PR is a follow-up to make that provider implementation
complete enough for downstream integrations that need to preserve
Anthropic's response semantics across the asynchronous lifecycle.

Before this change, the generic batch result kept the normalized status
and text but discarded provider-specific lifecycle fields, native
request counts, and some valid non-text result content. Once polling has
completed, a downstream consumer cannot reconstruct those fields from
the normalized result alone.

This is not a second batch API or a new orchestration layer. The generic
AI SDK batch contract stays provider-neutral, while Anthropic-specific
details are retained through `providerMetadata`. A downstream Gateway
integration is the immediate consumer and will need a released version
of these package changes before it can adopt them.

## summary

- preserve Anthropic Message Batch lifecycle metadata and native request
counts in provider metadata
- preserve normalized content and usage for successful results,
including citations, reasoning, client tool calls, and provider-executed
tool results
- decode Anthropic tool calls and tool results from the batch results
stream
- carry the supported language-model option surface into batch requests,
with explicit validation for options that depend on request context that
is unavailable during later polling
- keep MCP tool-result citation payloads permissive because they are
opaque third-party data

The provider adapter remains responsible only for Anthropic request and
response translation. Durable job storage, routing, billing, and
compatibility endpoints remain outside this PR.

## testing

- `pnpm --filter @ai-sdk/anthropic test`
- `pnpm --filter @ai-sdk/anthropic type-check`
- `pnpm --filter @ai-sdk/provider type-check`
- `pnpm --filter @ai-sdk/anthropic build`
- `pnpm check`
- full GitHub CI
B
Brian Zhang committed
aa457413c5973746d6e2b281ef0d83f6a7e112a6
Parent: 1d9b13b
Committed by GitHub <noreply@github.com> on 8/28/2026, 10:02:30 PM