Skip to content

The Open Standard for Generative UI

Update messaging for 429s (#929)

ABae2f6e1d77ba
diff --git a/packages/devtools/package.json b/packages/devtools/package.json
index 7a478b70b..6c3763976 100644
--- a/packages/devtools/package.json
+++ b/packages/devtools/package.json
@@ -1,6 +1,6 @@
{
"name": "@openuidev/devtools",
- "version": "0.0.3",
+ "version": "0.0.4",
"description": "Development-only UI widget for OpenUI apps: surfaces errors captured by @openuidev/observability",
"license": "MIT",
"type": "module",
diff --git a/packages/devtools/src/OpenUIDevtools.tsx b/packages/devtools/src/OpenUIDevtools.tsx
index 83df5f0fb..8b3310061 100644
--- a/packages/devtools/src/OpenUIDevtools.tsx
+++ b/packages/devtools/src/OpenUIDevtools.tsx
@@ -5,8 +5,9 @@ import {
type ObservabilityErrorInfo,
type ObservabilityEvent,
} from "@openuidev/observability";
-import { ArrowLeft, Check, Copy, CreditCard, WrapText, X } from "lucide-react";
+import { ArrowLeft, Check, Copy, WrapText, X } from "lucide-react";
import { useEffect, useRef, useState, type CSSProperties } from "react";
+import { getQuotaError, QuotaErrorRow } from "./QuotaErrorRow";
import { getReactLangStreamDetail, ReactLangStreamEventRow } from "./ReactLangStreamEventRow";
import { ShiroLogo } from "./ShiroLogo";
import { addOrReplaceEvent } from "./eventBuffer";
@@ -218,7 +219,8 @@ export function OpenUIDevtools({
typeof event.detail["id"] === "string"
? event.detail["id"]
: `${event.timestamp}-${index}`;
- if (isCreditsExhausted(event)) return <CreditsEventRow key={key} />;
+ const quotaError = getQuotaError(event);
+ if (quotaError) return <QuotaErrorRow key={key} info={quotaError} />;
const stream = getReactLangStreamDetail(event);
if (stream) {
return <ReactLangStreamEventRow key={key} event={event} stream={stream} />;
@@ -279,36 +281,6 @@ function asRecord(detail: unknown): Record<string, unknown> {
return typeof detail === "object" && detail !== null ? (detail as Record<string, unknown>) : {};
}
-// A 429 from the LLM plane means the workspace is out of credits.
-function isCreditsExhausted(event: ObservabilityEvent): boolean {
- return event.level === "error" && asRecord(event.detail)["status"] === 429;
-}
-
-/** Out-of-credits list entry — the highlighted card a 429 event renders as. */
-function CreditsEventRow() {
- return (
- <div style={{ ...styles.row, ...styles.rowCredits }}>
- <div style={styles.creditsNote}>
- <div style={styles.creditsTitle}>Add credits to keep going</div>
- <p style={styles.creditsMessage}>
- Looks like this workspace is out of OpenUI Cloud credits. Purchase credits to keep
- testing, then try your request again. This notice is only shown in development.
- </p>
- <button
- type="button"
- style={styles.action}
- onClick={() =>
- window.open("https://console.thesys.dev/billing", "_blank", "noopener,noreferrer")
- }
- >
- <CreditCard size={13} />
- Purchase Credits
- </button>
- </div>
- </div>
- );
-}
-
function asString(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
@@ -548,47 +520,11 @@ const styles = {
background: "#ffffff",
boxShadow: "0 1px 2px rgba(24, 24, 27, 0.04)",
},
- rowCredits: {
- border: "1px solid #fde68a",
- background: "linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%)",
- },
badgeCredits: {
background: "#fef3c7",
color: "#92400e",
borderColor: "#fde68a",
},
- creditsNote: {
- display: "flex",
- flexDirection: "column",
- gap: 6,
- },
- creditsTitle: {
- fontSize: 13,
- fontWeight: 600,
- color: "#18181b",
- },
- creditsMessage: {
- margin: 0,
- fontSize: 12,
- lineHeight: 1.55,
- color: "#52525b",
- },
- action: {
- alignSelf: "flex-start",
- display: "inline-flex",
- alignItems: "center",
- gap: 6,
- border: "none",
- borderRadius: 8,
- background: "#18181b",
- color: "#ffffff",
- padding: "6px 12px",
- fontFamily: FONT,
- fontSize: 12,
- fontWeight: 500,
- cursor: "pointer",
- marginTop: 2,
- },
rowHeader: {
display: "flex",
justifyContent: "space-between",
diff --git a/packages/devtools/src/QuotaErrorRow.tsx b/packages/devtools/src/QuotaErrorRow.tsx
new file mode 100644
index 000000000..780f067b7
--- /dev/null
+++ b/packages/devtools/src/QuotaErrorRow.tsx
@@ -0,0 +1,114 @@
+import { type ObservabilityEvent } from "@openuidev/observability";
+import { CreditCard } from "lucide-react";
+import type { CSSProperties } from "react";
+
+export interface QuotaErrorInfo {
+ title: string;
+ message: string;
+ showPurchaseCta: boolean;
+}
+
+const QUOTA_ERROR_MESSAGES: Record<string, QuotaErrorInfo> = {
+ ERR_BILLING_THRESHOLD_EXCEEDED: {
+ title: "Add credits to keep going",
+ message:
+ "Looks like this workspace is out of OpenUI Cloud credits. Purchase credits to keep testing, then try your request again. This notice is only shown in development.",
+ showPurchaseCta: true,
+ },
+ ERR_QUOTA_EXCEEDED: {
+ title: "Rate limit reached",
+ message:
+ "This workspace has hit a rate limit, usually from sending requests too quickly, or exceeding the per-model token/request limit for the current plan. Wait a moment and try again. This notice is only shown in development.",
+ showPurchaseCta: false,
+ },
+};
+
+export function getQuotaError(event: ObservabilityEvent): QuotaErrorInfo | undefined {
+ if (event.level !== "error") return undefined;
+ const error = asRecord(event.detail)["error"];
+ const type = asString(asRecord(error)["type"]);
+ return type ? QUOTA_ERROR_MESSAGES[type] : undefined;
+}
+
+/** Billing/rate-limit list entry — the highlighted card a known 429 code renders as. */
+export function QuotaErrorRow({ info }: { info: QuotaErrorInfo }) {
+ return (
+ <div style={{ ...styles.row, ...styles.rowCredits }}>
+ <div style={styles.creditsNote}>
+ <div style={styles.creditsTitle}>{info.title}</div>
+ <p style={styles.creditsMessage}>{info.message}</p>
+ {info.showPurchaseCta ? (
+ <button
+ type="button"
+ style={styles.action}
+ onClick={() =>
+ window.open("https://console.thesys.dev/billing", "_blank", "noopener,noreferrer")
+ }
+ >
+ <CreditCard size={13} />
+ Purchase Credits
+ </button>
+ ) : null}
+ </div>
+ </div>
+ );
+}
+
+function asRecord(detail: unknown): Record<string, unknown> {
+ return typeof detail === "object" && detail !== null ? (detail as Record<string, unknown>) : {};
+}
+
+function asString(value: unknown): string | undefined {
+ return typeof value === "string" ? value : undefined;
+}
+
+const FONT = '"Inter", system-ui, sans-serif';
+
+const styles = {
+ row: {
+ border: "1px solid #e4e4e7",
+ borderRadius: 12,
+ padding: 12,
+ display: "flex",
+ flexDirection: "column",
+ gap: 6,
+ background: "#ffffff",
+ boxShadow: "0 1px 2px rgba(24, 24, 27, 0.04)",
+ },
+ rowCredits: {
+ border: "1px solid #fde68a",
+ background: "linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%)",
+ },
+ creditsNote: {
+ display: "flex",
+ flexDirection: "column",
+ gap: 6,
+ },
+ creditsTitle: {
+ fontSize: 13,
+ fontWeight: 600,
+ color: "#18181b",
+ },
+ creditsMessage: {
+ margin: 0,
+ fontSize: 12,
+ lineHeight: 1.55,
+ color: "#52525b",
+ },
+ action: {
+ alignSelf: "flex-start",
+ display: "inline-flex",
+ alignItems: "center",
+ gap: 6,
+ border: "none",
+ borderRadius: 8,
+ background: "#18181b",
+ color: "#ffffff",
+ padding: "6px 12px",
+ fontFamily: FONT,
+ fontSize: 12,
+ fontWeight: 500,
+ cursor: "pointer",
+ marginTop: 2,
+ },
+} satisfies Record<string, CSSProperties>;
diff --git a/packages/react-headless/package.json b/packages/react-headless/package.json
index 56e412829..221c39c3a 100644
--- a/packages/react-headless/package.json
+++ b/packages/react-headless/package.json
@@ -1,6 +1,6 @@
{
"name": "@openuidev/react-headless",
- "version": "0.9.5",
+ "version": "0.9.6",
"description": "Headless React primitives for AI chat — state management, streaming adapters for OpenAI and AG-UI, message format converters, and thread management for OpenUI generative UI apps",
"license": "MIT",
"type": "module",
diff --git a/packages/react-headless/src/adapters/fetchLLM.ts b/packages/react-headless/src/adapters/fetchLLM.ts
index c8b0d61df..a75d09c95 100644
--- a/packages/react-headless/src/adapters/fetchLLM.ts
+++ b/packages/react-headless/src/adapters/fetchLLM.ts
@@ -68,7 +68,7 @@ export function fetchLLM({
status: response.status,
ok: response.ok,
threadId,
- ...(response.ok ? null : { message: await getResponseErrorMessage(response) }),
+ ...(await buildObservabilityErrorDetail(response)),
});
return response;
},
@@ -87,3 +87,14 @@ export function fetchLLM({
streamProtocol: streamAdapter,
};
}
+
+async function buildObservabilityErrorDetail(response: Response) {
+ if (response.ok) return {};
+ const res = await response.clone().json();
+ return {
+ error: res?.error,
+ ...(!res.message
+ ? await getResponseErrorMessage(response).then((message) => ({ message }))
+ : { message: res.message }),
+ };
+}