Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai): keep retryAfterMs and HTTP status on a rejected chat() #2301

Openpcbeingused33(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2301/headopened View on GitHub

Showing 8 changed files with 96 additions and 63 deletions (loading 5).

x
0 of 8 viewed, 8 left
5 additions and 0 deletions.changeset/chat-reject-keeps-retry-after.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/ai": patch
+---
+​
+`chat({ stream: false })` and `chat({ outputSchema })` keep `retryAfterMs`, `errorType`, `requestId`, `rawEvent`, and the HTTP `status` on the error they throw.
21 additions and 0 deletionsdocs/chat/stream-events.mdModified
View file
@@ -312,6 +312,27 @@
​
If there is no `retryAfterMs`, the provider sent no wait header. Pick your own backoff.
​
+`await chat({ stream: false })` and `await chat({ outputSchema })` reject with the same details. The `Error` has `retryAfterMs`, `errorType`, `requestId`, and `rawEvent`. `status` is the HTTP status, for example `429`, when the provider SDK set a numeric status. `code` can still be the provider code, such as `rate_limit_exceeded`.
+​
+```typescript
+import { chat } from "@tanstack/ai";
+import { anthropicText } from "@tanstack/ai-anthropic";
+​
+try {
+ await chat({
+ adapter: anthropicText("claude-sonnet-5-5"),
+ messages: [{ role: "user", content: "Hello!" }],
+ threadId: "thread-1",
+ stream: false,
+ });
+} catch (error) {
+ const failed = error as Error & { status?: number; retryAfterMs?: number };
+ if (failed.status === 429) {
+ console.log(failed.retryAfterMs);
+ }