Skip to content

Commit 8c074d3

Browse files
tombeckenhamclaude
andcommitted
fix(anthropic): align #849 max_tokens map and tests with synced model metadata
Main's OpenRouter metadata sync (e14586b) retired claude-3.x / claude-4 / -fast model ids and added Fable 5 / Sonnet 5, so after rebasing: - ANTHROPIC_MODEL_MAX_OUTPUT_TOKENS again mirrors ANTHROPIC_MODELS exactly (removed retired entries, added claude-fable-5 / claude-sonnet-5). - Tests use current ids (claude-opus-4-8, claude-opus-4-1, claude-sonnet-4-5, claude-opus-4-5 for the 32K ceiling case). - The 'ceiling below the non-streaming limit' test relied on claude-3-haiku's 4K ceiling; no current model sits under 21K, so it now asserts every model in the lineup clamps on the non-streaming path instead. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 9872d34 commit 8c074d3

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

packages/ai-anthropic/src/model-meta.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,10 @@ const ANTHROPIC_MODEL_MAX_OUTPUT_TOKENS: Record<string, number> = {
537537
[CLAUDE_SONNET_4_5.id]: CLAUDE_SONNET_4_5.max_output_tokens,
538538
[CLAUDE_HAIKU_4_5.id]: CLAUDE_HAIKU_4_5.max_output_tokens,
539539
[CLAUDE_OPUS_4_1.id]: CLAUDE_OPUS_4_1.max_output_tokens,
540-
[CLAUDE_SONNET_4.id]: CLAUDE_SONNET_4.max_output_tokens,
541-
[CLAUDE_SONNET_3_7.id]: CLAUDE_SONNET_3_7.max_output_tokens,
542-
[CLAUDE_OPUS_4.id]: CLAUDE_OPUS_4.max_output_tokens,
543-
[CLAUDE_HAIKU_3_5.id]: CLAUDE_HAIKU_3_5.max_output_tokens,
544-
[CLAUDE_HAIKU_3.id]: CLAUDE_HAIKU_3.max_output_tokens,
545-
[CLAUDE_OPUS_4_6_FAST.id]: CLAUDE_OPUS_4_6_FAST.max_output_tokens,
546540
[CLAUDE_OPUS_4_7.id]: CLAUDE_OPUS_4_7.max_output_tokens,
547-
[CLAUDE_OPUS_4_7_FAST.id]: CLAUDE_OPUS_4_7_FAST.max_output_tokens,
548541
[CLAUDE_OPUS_4_8.id]: CLAUDE_OPUS_4_8.max_output_tokens,
549-
[CLAUDE_OPUS_4_8_FAST.id]: CLAUDE_OPUS_4_8_FAST.max_output_tokens,
542+
[CLAUDE_FABLE_5.id]: CLAUDE_FABLE_5.max_output_tokens,
543+
[CLAUDE_SONNET_5.id]: CLAUDE_SONNET_5.max_output_tokens,
550544
}
551545

552546
/**

packages/ai-anthropic/tests/anthropic-adapter.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe('Anthropic adapter option mapping', () => {
464464
}
465465

466466
const [payload] = mocks.betaMessagesCreate.mock.calls[0]!
467-
// claude-3-7-sonnet's model-meta max_output_tokens is 64_000 — not the old
467+
// claude-opus-4-1's model-meta max_output_tokens is 64_000 — not the old
468468
// hard-coded 1024 floor that silently truncated long responses.
469469
expect(payload.max_tokens).toBe(64_000)
470470
})
@@ -492,7 +492,7 @@ describe('Anthropic adapter option mapping', () => {
492492
})()
493493
mocks.betaMessagesCreate.mockResolvedValueOnce(truncatedStream)
494494

495-
const adapter = createAdapter('claude-3-7-sonnet')
495+
const adapter = createAdapter('claude-opus-4-1')
496496

497497
const logger = {
498498
debug: vi.fn(),
@@ -526,7 +526,7 @@ describe('Anthropic adapter option mapping', () => {
526526
})()
527527
mocks.betaMessagesCreate.mockResolvedValueOnce(truncatedStream)
528528

529-
const adapter = createAdapter('claude-3-7-sonnet')
529+
const adapter = createAdapter('claude-opus-4-1')
530530

531531
const logger = {
532532
debug: vi.fn(),
@@ -560,7 +560,7 @@ describe('Anthropic adapter option mapping', () => {
560560
id: 'msg_structured',
561561
type: 'message',
562562
role: 'assistant',
563-
model: 'claude-3-7-sonnet',
563+
model: 'claude-opus-4-1',
564564
content: [
565565
{
566566
type: 'tool_use',
@@ -573,7 +573,7 @@ describe('Anthropic adapter option mapping', () => {
573573
usage: { input_tokens: 10, output_tokens: 20 },
574574
})
575575

576-
const adapter = createAdapter('claude-3-7-sonnet')
576+
const adapter = createAdapter('claude-opus-4-1')
577577

578578
for await (const _ of chat({
579579
adapter,
@@ -589,7 +589,7 @@ describe('Anthropic adapter option mapping', () => {
589589

590590
const [payload] = mocks.betaMessagesCreate.mock.calls[0]!
591591
expect(payload.stream).toBe(false)
592-
// Clamped to the non-streaming limit — NOT claude-3-7-sonnet's full 64K
592+
// Clamped to the non-streaming limit — NOT claude-opus-4-1's full 64K
593593
// streaming ceiling, which would make the SDK throw before the request.
594594
expect(payload.max_tokens).toBe(ANTHROPIC_MAX_NONSTREAMING_TOKENS)
595595
expect(payload.max_tokens).toBeLessThanOrEqual(21_333)

packages/ai-anthropic/tests/model-meta.test.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, expectTypeOf, it } from 'vitest'
22
import {
33
ANTHROPIC_DEFAULT_MAX_OUTPUT_TOKENS,
44
ANTHROPIC_MAX_NONSTREAMING_TOKENS,
5+
ANTHROPIC_MODELS,
56
getAnthropicDefaultMaxTokens,
67
} from '../src/model-meta'
78
import type {
@@ -333,11 +334,11 @@ describe('Anthropic Model Input Modality Type Assertions', () => {
333334

334335
describe('getAnthropicDefaultMaxTokens (#849)', () => {
335336
it("returns the model's max_output_tokens for known models", () => {
336-
expect(getAnthropicDefaultMaxTokens('claude-opus-4.8')).toBe(128_000)
337+
expect(getAnthropicDefaultMaxTokens('claude-opus-4-8')).toBe(128_000)
337338
expect(getAnthropicDefaultMaxTokens('claude-opus-4-6')).toBe(128_000)
338339
expect(getAnthropicDefaultMaxTokens('claude-sonnet-4-6')).toBe(64_000)
339-
expect(getAnthropicDefaultMaxTokens('claude-3-7-sonnet')).toBe(64_000)
340-
expect(getAnthropicDefaultMaxTokens('claude-3-haiku')).toBe(4_000)
340+
expect(getAnthropicDefaultMaxTokens('claude-sonnet-4-5')).toBe(64_000)
341+
expect(getAnthropicDefaultMaxTokens('claude-opus-4-5')).toBe(32_000)
341342
})
342343

343344
it('falls back to the safe constant for unknown models', () => {
@@ -348,7 +349,7 @@ describe('getAnthropicDefaultMaxTokens (#849)', () => {
348349
})
349350

350351
it('never returns the old hard-coded 1024 floor for a known model', () => {
351-
expect(getAnthropicDefaultMaxTokens('claude-opus-4.8')).toBeGreaterThan(
352+
expect(getAnthropicDefaultMaxTokens('claude-opus-4-8')).toBeGreaterThan(
352353
1024,
353354
)
354355
})
@@ -361,7 +362,7 @@ describe('getAnthropicDefaultMaxTokens (#849)', () => {
361362

362363
// Opus 128K and Sonnet 64K both exceed the non-streaming limit → clamped.
363364
expect(
364-
getAnthropicDefaultMaxTokens('claude-opus-4.8', { stream: false }),
365+
getAnthropicDefaultMaxTokens('claude-opus-4-8', { stream: false }),
365366
).toBe(ANTHROPIC_MAX_NONSTREAMING_TOKENS)
366367
expect(
367368
getAnthropicDefaultMaxTokens('claude-sonnet-4-6', { stream: false }),
@@ -374,19 +375,22 @@ describe('getAnthropicDefaultMaxTokens (#849)', () => {
374375
).toBe(ANTHROPIC_MAX_NONSTREAMING_TOKENS)
375376
})
376377

377-
it('does not clamp a model whose ceiling is already below the non-streaming limit (#849)', () => {
378-
// claude-3-haiku's 4K ceiling is under the non-streaming limit, so the
379-
// non-streaming path returns the real ceiling, not the (larger) cap.
380-
expect(
381-
getAnthropicDefaultMaxTokens('claude-3-haiku', { stream: false }),
382-
).toBe(4_000)
378+
it('clamps every current model on the non-streaming path (#849)', () => {
379+
// Every model in today's lineup has a ceiling (32K–128K) above the
380+
// non-streaming limit, so all of them clamp. (The clamp is a Math.min, so
381+
// a future sub-21K model would keep its real ceiling instead.)
382+
for (const model of ANTHROPIC_MODELS) {
383+
expect(getAnthropicDefaultMaxTokens(model, { stream: false })).toBe(
384+
ANTHROPIC_MAX_NONSTREAMING_TOKENS,
385+
)
386+
}
383387
})
384388

385389
it('keeps the full ceiling for streaming requests (default) (#849)', () => {
386390
expect(
387-
getAnthropicDefaultMaxTokens('claude-opus-4.8', { stream: true }),
391+
getAnthropicDefaultMaxTokens('claude-opus-4-8', { stream: true }),
388392
).toBe(128_000)
389393
// Omitting the option defaults to streaming.
390-
expect(getAnthropicDefaultMaxTokens('claude-opus-4.8')).toBe(128_000)
394+
expect(getAnthropicDefaultMaxTokens('claude-opus-4-8')).toBe(128_000)
391395
})
392396
})

0 commit comments

Comments
 (0)