Skip to content

Normalized Anthropic model IDs fall back to the wrong default max_tokens #432

Description

@fallintoplace

Summary

The AI SDK provider normalizes Anthropic model IDs to dot-form names like anthropic/claude-3.7-sonnet, but the default max_tokens logic still only checks dash-form names like claude-3-7-sonnet.

That means common Anthropic inputs can silently fall back to 4096 instead of the intended model-specific defaults.

Affected code paths

This looks to affect both V2 and V3:

  • llm/ai-sdk/provider/stripe-provider.ts
  • llm/ai-sdk/provider/utils.ts
  • llm/ai-sdk/provider/stripe-language-model.ts
  • llm/ai-sdk/provider/stripe-language-model-v3.ts

Repro

The provider factory normalizes Anthropic model IDs:

  • anthropic/claude-3-7-sonnet-20250115 -> anthropic/claude-3.7-sonnet
  • anthropic/claude-3-5-haiku-20241022 -> anthropic/claude-3.5-haiku

But getDefaultMaxTokens() still checks only dash-form strings such as:

  • claude-3-7-sonnet
  • claude-3-5-haiku
  • haiku-4-5

So after normalization, these models miss their intended branches.

Actual behavior

Examples that appear to fall through to the fallback:

  • anthropic/claude-3-7-sonnet-20250115 -> normalized to anthropic/claude-3.7-sonnet -> falls back to 4096 instead of 64000
  • anthropic/claude-3-5-haiku-20241022 -> normalized to anthropic/claude-3.5-haiku -> falls back to 4096 instead of 8192
  • anthropic/claude-haiku-4-5-* -> normalized to anthropic/claude-haiku-4.5 -> falls back to 4096 instead of 64000

Expected behavior

Normalized Anthropic model IDs should still receive the intended default max_tokens values.

Suggested fix

Either:

  1. Normalize again inside getDefaultMaxTokens(), or
  2. Check both dash-form and dot-form model IDs there

It would also help to add tests that cover the full provider path via createStripe() / createStripeV3(), since the current tests already cover normalization and default token behavior separately but not together.

History

From local history, this appears to have been introduced when the provider was added in #167 and then mirrored into the V3 implementation in #303.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions