# Error and limit states

> Calm, specific notices for failed answers, being offline, rate limits and chats that grow too long.

Every AI product hits these, and most show a red box with "Error". Each notice says what happened, what happens next and offers the one action that helps: Retry, which opens a spinner and morphs to "Retrying" while it runs; a countdown that rolls down to when the limit resets, then turns the hourglass into a check that draws itself as the words morph to "You can send messages again"; or starting fresh with a summary. Technical details fold away behind "Show details".

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/chat-notice.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `status-button`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/chat-notice
- Registry item (source): https://hairlineui.com/r/chat-notice.json

## Usage

```tsx
import { ChatNotice } from "@/components/chat-notice";

<ChatNotice kind="rate-limit" resetAt={resetAt} onUpgrade={openPricing} />
<ChatNotice kind="error" details="504 · req_8f2k1" onRetry={retry} />
```

## With the AI SDK

```tsx
import { useChat } from "@ai-sdk/react";
import { useSyncExternalStore } from "react";
import { ChatNotice } from "@/components/chat-notice";

const useOnline = () =>
  useSyncExternalStore(
    (cb) => (addEventListener("online", cb), addEventListener("offline", cb), () => (removeEventListener("online", cb), removeEventListener("offline", cb))),
    () => navigator.onLine,
    () => true
  );

function ChatErrors() {
  const { status, error, regenerate, clearError } = useChat();
  const online = useOnline();
  if (!online) return <ChatNotice kind="offline" />;
  if (status !== "error") return null;
  return (
    <ChatNotice
      kind={error?.message.includes("rate limit") ? "rate-limit" : "error"}
      details={error?.message}
      onRetry={() => {
        clearError();
        regenerate();
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `kind` | `"error" \| "offline" \| "rate-limit" \| "context"` | – | Picks the icon, wording and actions. |
| `title / description` | `string` | – | Override the default wording. |
| `resetAt / onReset` | `number / () => void` | – | Rate limit: when sending is allowed again, with a live countdown. |
| `onRetry / retrying` | `() => void / boolean` | – | Retry button, with a spinner (or "Reconnecting" when offline) while it runs. |
| `onUpgrade / upgradeLabel` | `() => void / string` | `"Upgrade"` | Rate limit: the way out. |
| `onSummarize / onNewChat` | `() => void` | – | Context: continue with a summary, or start over. |
| `details` | `string` | – | Technical details behind "Show details". |

## States

- **error**: "Something went wrong", reassurance that the message is safe, and Retry: a Status button whose spinner opens in as it morphs to "Retrying". Details fold open (420ms) as "Show details" morphs to "Hide details".
- **offline**: Explains it will pick up when the connection is back; "Reconnecting" opens in with a soft pulse while retrying, and "Try now" spins while it tries.
- **rate-limit**: The countdown rolls down a second at a time (00 rolls back to 59). At zero the hourglass blurs into a check that draws itself, the title and description morph to "You can send messages again" / "Your limit has reset." and Upgrade folds away.
- **context**: Offers a new chat, or continuing with a summary of this one.

## What it handles

Every AI product hits these four moments, and most show a red box that says “Error”. Each notice here says what happened, what happens next and offers the one action that helps.

- **Failed answers**: “Something went wrong”, a note that the message is safe, and Retry, which spins and reads “Retrying”. Technical details sit behind “Show details”.
- **Offline**: Explains that it will pick up when the connection is back, shows “Reconnecting”, and offers “Try now”.
- **Rate limits with a countdown**: The time left rolls down, then the notice becomes “You can send messages again” and Upgrade folds away.
- **Chats that grow too long**: Offers a new chat, or continuing with a summary of this one.
- **Calm for screen readers**: Errors use role alert and the rest use status. The ticking digits are hidden, so the countdown never chatters.
- **One component, four kinds**: The kind picks the icon, the words and the actions. Override the title and description when you need to.

## Replaces

an error banner, a retry button with state, a rate-limit countdown, offline messages, a context-limit prompt

## Where it fits

- **Failed answers**: Tell people the answer didn’t arrive, that their message is safe, and let them retry.
- **Free plan limits**: Show when sending is allowed again, with a way to upgrade.
- **Lost connections**: Say the chat will pick up when the connection is back.
- **Long conversations**: When the context is full, offer a new chat or a summary to continue with.

## Notes

- Errors use role="alert"; the other kinds use role="status", so screen readers hear them without interruption. The ticking digits are hidden from them (they hear the time it resets instead), so the countdown never chatters.
- The countdown starts once mounted, cleans up its timer and calls onReset once when the limit resets.
- Installs Number roll, Status button and Text morph. With reduced motion, states change in place.
- Actions wrap under the text on narrow screens.

License: MIT (https://hairlineui.com/license#components)
