fix(ai-anthropic): drop sampling keys on models that reject them #1705
main fromrefs/pull/1705/headopened View on GitHub- packages/ai-anthropic/src/model-meta.ts lines 790 to 798Outdated@@ -759,3 +762,19 @@759762 CLAUDE_SONNET_5.id,760763 ] as const761764765+/**766+ * Models whose Messages API rejects non-default `temperature` / `top_p` /767+ * `top_k`. Keep in sync with `AnthropicChatModelProviderOptionsByName`768+ * entries that use `AnthropicMaxTokensOptions` instead of769+ * `AnthropicSamplingOptions`. Type tests in `model-meta.test.ts` enforce both770+ * directions so a new model id must pick one.771+ */772+export const ANTHROPIC_MODELS_WITHOUT_SAMPLING = [773+ CLAUDE_OPUS_4_7.id,774+ CLAUDE_OPUS_4_8.id,775+ CLAUDE_FABLE_5.id,776+ CLAUDE_FABLE_5_1.id,777+ CLAUDE_SONNET_5.id,778+ CLAUDE_SONNET_5_5.id,779+ CLAUDE_OPUS_5_5.id,780+ CLAUDE_HAIKU_5_5.id,
github-actions[bot](GitHub profile, opens in a new tab) assignedAlemTuzlak
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
AlemTuzlak added labelsai-ready
AlemTuzlak added labelssecure
github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
- packages/ai-anthropic/tests/anthropic-adapter.test.ts line 669Outdated@@ -623,0 +649,21 @@649+ max_tokens: 1024,650+ } as never,651+ debug: { logger, errors: true },652+ })) {653+ // consume stream654+ }655+656+ const [payload] = mocks.betaMessagesCreate.mock.calls[0]!657+ expect(payload.temperature).toBeUndefined()658+ expect(payload.top_p).toBeUndefined()659+ expect(payload.top_k).toBeUndefined()660+ expect(payload.max_tokens).toBe(1024)661+662+ const stripWarning = logger.warn.mock.calls.find((call) =>663+ String(call[0]).includes('omitted sampling key(s)'),664+ )665+ expect(stripWarning).toBeDefined()666+ })667+668+ it('keeps supportsSamplingTemperature true on sampling models', () => {669+ const adapter = createAdapter('claude-opus-4-1')
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelsmerge-conflicts
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
github-actions[bot](GitHub profile, opens in a new tab) removed labelswaiting-on: maintainer
tombeckenham assignedjherr
tombeckenham unassignedAlemTuzlak
harshlocham(GitHub profile, opens in a new tab) linked this to fix #1703
tanstack-source reviewed
packages/ai-anthropic/src/model-meta.ts line 790Outdated@@ -778,3 +781,10 @@778781 ] as const779782780783 /**784+ * Models whose Messages API rejects non-default `temperature` / `top_p` /785+ * `top_k`. Keep in sync with `AnthropicChatModelProviderOptionsByName`786+ * entries that use `AnthropicMaxTokensOptions` instead of787+ * `AnthropicSamplingOptions`. Type tests in `model-meta.test.ts` enforce both788+ * directions so a new model id must pick one.789+ */790+export const ANTHROPIC_MODELS_WITHOUT_SAMPLING = [packages/ai-anthropic/tests/chat-per-model-type-safety.test.ts line 281Outdated@@ -261,2 +261,21 @@261261 })262262263+ // Thinking and effort are `chat({ reasoning })`, not provider options.264+ describe('claude-opus-5-5 — max_tokens, no sampling', () => {265+ it('accepts max_tokens and the base options', () => {266+ chat({267+ adapter: anthropicText('claude-opus-5-5'),268+ threadId: 'thread-1',269+ messages: [{ role: 'user', content: 'hi' }],270+ modelOptions: {271+ service_tier: 'auto',272+ stop_sequences: ['STOP'],273+ tool_choice: { type: 'auto' },274+ max_tokens: 2048,275+ },276+ })277+ })278+279+ it('rejects sampling parameters', () => {280+ chat({281+ adapter: anthropicText('claude-opus-5-5'),- 2 bot comments
harshlocham(GitHub profile, opens in a new tab) changed the title
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 270500b03cab14949d36ea1b793a97cc0ff1ec41
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR