From 2fc6eddd035517b4208b6c5755af9cad5d78b26c Mon Sep 17 00:00:00 2001 From: Ryan Pate Date: Mon, 21 Apr 2025 10:25:33 -0700 Subject: [PATCH] fix: resolve 160 Anthropic throws unknown model for some models due to missing max tokens clause --- .changeset/old-tomatoes-pump.md | 5 +++++ src/handlers/anthropic.ts | 11 ++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changeset/old-tomatoes-pump.md diff --git a/.changeset/old-tomatoes-pump.md b/.changeset/old-tomatoes-pump.md new file mode 100644 index 0000000..5677506 --- /dev/null +++ b/.changeset/old-tomatoes-pump.md @@ -0,0 +1,5 @@ +--- +'token.js': patch +--- + +Fix: resolve error where new anthropic models do not work due to hardcoded max token limit diff --git a/src/handlers/anthropic.ts b/src/handlers/anthropic.ts index f7a9455..9e88e74 100644 --- a/src/handlers/anthropic.ts +++ b/src/handlers/anthropic.ts @@ -344,8 +344,17 @@ export const getDefaultMaxTokens = (model: string): number => { model === 'claude-instant-1.2' ) { return 4096 + } else if ( + model === 'claude-3-5-sonnet-latest' || + model === 'claude-3-5-sonnet-20241022' || + model === 'claude-3-7-sonnet-latest' || + model === 'claude-3-7-sonnet-20250219' || + model === 'claude-3-5-haiku-20241022' + ) { + return 8192 } else { - throw new InputError(`Unknown model: ${model}`) + // We default to 8192 when the model is not specifically handled here to avoid throwing errors + return 8192 } }