You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my application, I allow users to pass in their own Anthropic API key. When a request is made using streamText and toDataStreamResponse with an Anthropic API key that has no credit balance, the following error occurs:
I'd like to catch this error to show a useful error message to the user, but the error occurs without being caught in a try/catch or showing up in onFinish in streamText or getErrorMessage in toDataStreamResponse (in other words, the error does not show up anywhere it can be handled programmatically):
I'd like to be able to handle this error on the server, or alternatively, have this error streamed back to the client so that it can be handled in onError in useChat.
If there is a way to handle this error, I'd appreciate pointers. Thanks!
Code example
No response
AI provider
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
After removal of await from streamText in AI sdk v4, we've started facing this issue. If any AI provider returns an error (e.g. Invalid API key), we're now unable to catch it on the server side and handle it (e.g. retry with alternative provider).
Description
In my application, I allow users to pass in their own Anthropic API key. When a request is made using
streamText
andtoDataStreamResponse
with an Anthropic API key that has no credit balance, the following error occurs:I'd like to catch this error to show a useful error message to the user, but the error occurs without being caught in a try/catch or showing up in
onFinish
instreamText
orgetErrorMessage
intoDataStreamResponse
(in other words, the error does not show up anywhere it can be handled programmatically):The server fails with a 500 error message due to the uncaught exception.
Related issue due to the same cause: #3655
I'd like to be able to handle this error on the server, or alternatively, have this error streamed back to the client so that it can be handled in
onError
inuseChat
.If there is a way to handle this error, I'd appreciate pointers. Thanks!
Code example
No response
AI provider
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: