Skip to content

@ai-sdk/anthropic does not add advanced-tool-use beta for tool search / deferLoading #16245

Description

@DaisukeYoda

Description

When using the Anthropic provider with toolSearchRegex_20251119() and tools marked with providerOptions: { anthropic: { deferLoading: true } }, the SDK serializes Anthropic advanced tool-use fields into the request body but does not include the required advanced-tool-use-2025-11-20 beta header.

Anthropic rejects these requests unless users manually add the beta via providerOptions.anthropic.anthropicBeta.

Reproduction

import { createAnthropic } from "@ai-sdk/anthropic";
import { generateText, tool } from "ai";
import { z } from "zod";

const anthropic = createAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

await generateText({
  model: anthropic("claude-sonnet-4-6"),
  prompt: "hello",
  tools: {
    tool_search_tool_regex: anthropic.tools.toolSearchRegex_20251119(),
    sample: tool({
      description: "sample tool",
      inputSchema: z.object({}),
      providerOptions: {
        anthropic: { deferLoading: true },
      },
      execute: async () => ({ ok: true }),
    }),
  },
});

Expected behavior

The Anthropic provider should automatically include:

anthropic-beta: advanced-tool-use-2025-11-20

when using toolSearchRegex_20251119(), toolSearchBm25_20251119(), or deferLoading, similar to how other Anthropic beta-gated tools/options add their required beta headers automatically.

Actual behavior

The provider sends tool_search_tool_regex_20251119 and defer_loading in the request body, but does not add advanced-tool-use-2025-11-20 to anthropic-beta.

With @ai-sdk/anthropic@3.0.85 and ai@6.0.207, intercepting the request with a fake fetch produced this header:

{
  "anthropic-beta": "structured-outputs-2025-11-13",
  "anthropic-version": "2023-06-01",
  "content-type": "application/json"
}

A manual workaround is required:

providerOptions: {
  anthropic: {
    anthropicBeta: ["advanced-tool-use-2025-11-20"],
  },
}

Versions

  • @ai-sdk/anthropic: 3.0.85
  • ai: 6.0.207
  • Runtime used for verification: bun@1.3.13

Notes

This looks like a provider implementation bug rather than a feature request because the SDK exposes the beta-gated API surface and serializes the corresponding request body fields, but omits the required beta header.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions