Storage is where your app keeps uploaded files and generated media. If you skip this, the basic app still runs, but upload-heavy features like document chat, image generation, and audio won’t work properly.
What Uses Storage
Your app needs storage for:- Chat document uploads (PDFs)
- Generated images
- Generated videos
- Generated audio
- User-uploaded files for vision and other tools
Get It Running
Create a bucket
We recommend Cloudflare R2 because it’s S3-compatible and simple to set up. Create a bucket in the R2 dashboard.
Generate API credentials
Create an API token with read/write access to your bucket. Copy the S3 endpoint from your R2 dashboard.
Configure a public URL
Set up a custom domain or use the default
r2.dev URL so your users can access stored files in the browser.What Each Env Var Does
| Variable | Purpose |
|---|---|
STORAGE_REGION | Region value expected by your provider (auto for R2) |
STORAGE_ACCESS_KEY | Access key for your bucket |
STORAGE_SECRET_KEY | Secret key for your bucket |
STORAGE_ENDPOINT | S3-compatible API endpoint |
STORAGE_BUCKET | Bucket name |
STORAGE_PUBLIC_URL | The public URL users will open in the browser |
Key Files
The main storage logic lives in:lib/storage/object-storage.ts— uploads, deletes, and public URLslib/integrations/cloudflare.ts— Cloudflare-specific integration
Verify It Works
Your storage setup is working if you can:
- Upload a file through the app
- See generated media save successfully
- Open the stored file URL in your browser
Wrong bucket name or endpoint
Wrong bucket name or endpoint
Double-check that
STORAGE_BUCKET matches the exact name in your provider dashboard, and that STORAGE_ENDPOINT uses the correct account ID.Public URL pointing to the wrong place
Public URL pointing to the wrong place
Your
STORAGE_PUBLIC_URL must resolve to the same bucket you’re uploading to. If you’re using a CDN, make sure it’s configured to serve from the right origin.Env vars set but nothing works
Env vars set but nothing works
Did you restart the app? Next.js doesn’t pick up new env vars until you restart the dev server.

