@@ -9,6 +9,22 @@ import { safeParseToolCallArgs } from "../../tools/parseArgs.js";
99import { renderChatMessage , stripImages } from "../../util/messageContent.js" ;
1010import { BaseLLM } from "../index.js" ;
1111
12+ const errorMessages = {
13+ invalid_request_error :
14+ "There was an issue with the format or content of your request." ,
15+ authentication_error : "There's an issue with your API key." ,
16+ permission_error :
17+ "Your API key does not have permission to use the specified resource." ,
18+ not_found_error : "The requested resource was not found." ,
19+ request_too_large :
20+ "Request exceeds the maximum allowed number of bytes (32 MB limit)." ,
21+ rate_limit_error : "Your account has hit a rate limit." ,
22+ api_error :
23+ "An unexpected error has occurred internal to Anthropic's systems." ,
24+ overloaded_error :
25+ "Anthropic's API is temporarily overloaded. Please check their status page: https://status.anthropic.com/#past-incidents" ,
26+ } ;
27+
1228class Anthropic extends BaseLLM {
1329 static providerName = "anthropic" ;
1430 static defaultOptions : Partial < LLMOptions > = {
@@ -183,9 +199,9 @@ class Anthropic extends BaseLLM {
183199 if ( ! response . ok ) {
184200 const json = await response . json ( ) ;
185201 if ( json . type === "error" ) {
186- if ( json . error ?. type === "overloaded_error" ) {
202+ if ( json . error ?. type in errorMessages ) {
187203 throw new Error (
188- "The Anthropic API is currently overloaded. Please check their status page: https://status.anthropic.com/#past-incidents" ,
204+ errorMessages [ json . error . type as keyof typeof errorMessages ] ,
189205 ) ;
190206 }
191207 throw new Error ( json . message ) ;
0 commit comments