Skip to content

Commit 36bb44b

Browse files
committed
Handles out of funds error from Anthropic
1 parent b47dcd9 commit 36bb44b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/plus/ai/anthropicProvider.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,24 @@ export class AnthropicProvider extends OpenAICompatibleProviderBase<typeof provi
190190

191191
debugger;
192192

193-
if (json?.error?.type === 'invalid_request_error' && json?.error?.message?.includes('prompt is too long')) {
194-
if (retries < 2) {
195-
return { retry: true, maxInputTokens: maxInputTokens - 200 * (retries || 1) };
193+
if (json?.error?.type === 'invalid_request_error') {
194+
if (json?.error?.message?.includes('prompt is too long')) {
195+
if (retries < 2) {
196+
return { retry: true, maxInputTokens: maxInputTokens - 200 * (retries || 1) };
197+
}
198+
199+
throw new AIError(
200+
AIErrorReason.RequestTooLarge,
201+
new Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),
202+
);
196203
}
197204

198-
throw new AIError(
199-
AIErrorReason.RequestTooLarge,
200-
new Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),
201-
);
205+
if (json?.error?.message?.includes('balance is too low')) {
206+
throw new AIError(
207+
AIErrorReason.RateLimitOrFundsExceeded,
208+
new Error(`(${this.name}) ${rsp.status}: ${json?.error?.message || rsp.statusText}`),
209+
);
210+
}
202211
}
203212
}
204213

0 commit comments

Comments
 (0)