AI chat
Streaming chat on the Vercel AI SDK, with saved threads and file attachments.
Requires:Works on its own
Built on
One library, no choice to makeVercel AI SDKPer tokenVercel AI SDK and the Vercel AI Gateway.ProsOne key, any modelSwitch models with one variableConsChat attachments need StorageReasoning models need a higher output limit
List prices at the time of writing. Verify before you rely on them.
Preview
What it adds
8 things, working end to end- Streaming chat: useChat in the browser, streamText in app/api/chat/route.ts
- Markdown replies, message editing and regenerate
- Models are Vercel AI Gateway strings in AI_MODEL, such as provider/model
- A guarded route: who may call it and a per-user or per-IP rate limit, plus limits on messages and output size
- With the database: threads are saved. With the database and auth: they belong to their owner, with a Recent list and delete
- With storage: attach images, PDFs and text files, kept in a private bucket and read on the server only
- Its own UI primitives (message, bubble, input group, attachment) without Radix
- Unit, integration and Playwright tests that run against a stub model
Set up Vercel AI SDK
Accounts and keys, in this order- 1Create a gateway keyCreate a key at vercel.com/ai-gateway. On Vercel an OIDC token is used when the key is empty.vercel.com/ai-gateway.envAI_GATEWAY_API_KEY=
- 2Pick a modelA gateway string
provider/model. No code change..envAI_MODEL=anthropic/claude-haiku-5.5 - 3Reasoning modelsRaise the output limit: with the default 1024 a reasoning model can spend everything thinking and send no text..envAI_MAX_OUTPUT_TOKENS=4096
- 4AttachmentsOn when Storage is installed. Tune with
AI_ATTACHMENTS,AI_ATTACHMENT_TYPES(png, jpeg, webp, gif, pdf, txt, md, csv, json by default) andAI_ATTACHMENT_MAX_FILES(1 to 10). If you add Storage after AI, runnpx tailar sync ai. - 5Check it worksSign in, open
/chatand send a message. The reply streams in.
Environment variables
For the selected provider.env
# Vercel AI Gateway key
AI_GATEWAY_API_KEY=
# Gateway model string, provider/model
AI_MODEL=
# Require a signed-in user; defaults to true with auth (optional)
AI_REQUIRE_AUTH=
# Requests per window, per user or per IP
AI_RATE_LIMIT_MAX=
# Length of that window
AI_RATE_LIMIT_WINDOW_SECONDS=
# Cap per reply (optional)
AI_MAX_OUTPUT_TOKENS=
# Cap on messages per request (optional)
AI_MAX_MESSAGES=
# Cap on input length (optional)
AI_MAX_INPUT_CHARS=
# System prompt (optional)
AI_SYSTEM_PROMPT=
# false hides the attach button (optional)
AI_ATTACHMENTS=
# Accepted media types, comma separated (optional)
AI_ATTACHMENT_TYPES=
# Most files in one message, 1 to 10 (optional)
AI_ATTACHMENT_MAX_FILES=
Works with
Other modules this one connects toAdd it to your repo
Pick the preset in the builder, check the providers, and download a repo that already has this module wired in.
