Env Setup
The complete, updated cloudflare-env-import.env file — every variable, every key,
ready to import into Cloudflare Pages. Follow the steps below exactly; the whole site, the API,
the Telegram bot and the GET endpoints are configured from this single file.
This page ships with placeholders only — real API keys are never published here. An earlier version did embed live keys, and GitHub push protection blocked the push: anyone could read them in the page source. Use the generator below — the keys you type stay in your browser only, are sent nowhere, and produce the real import file. Never commit real keys to the repo.
1. Import into Cloudflare Pages (exact clicks)
- Open dash.cloudflare.com → Workers & Pages → aigateway.
- Go to Settings → Variables and Secrets.
- Click + Import .env → select the downloaded
cloudflare-env-import.envfile (or copy-paste the whole block below into the first variable's edit box using Import .env — it parses KEY=value lines). Confirm. - Switch to the Preview environment tab on the same page and repeat the import there too.
- Redeploy: Deployments → latest deployment → ⋯ → Retry deployment (or push any commit). Variables only take effect after a deploy.
2. The complete file (v1.4.0)
The template below lists every variable with safe placeholders. Use the generator right under it to stamp in your real keys and download the ready-to-import file.
…
Type your two provider keys and press the button: the page builds your complete real
cloudflare-env-import.env and downloads it — ready for the
Cloudflare import in step 1. The keys never leave this page: no server, no storage, no log receives them.
3. What each variable does (and where it's used)
| Variable | Example / value | Used by |
|---|---|---|
APP_NAME / APP_VERSION | AI Gateway API / 1.4.0 | Navbar chip, footer, /api/v1/config, health — one change rebrands everything. |
OPENROUTER_API_KEY | sk-or-v1-… | OpenRouter chat + model catalog (server-side only). |
POOLSIDE_API_KEY | sky_… | Poolside Laguna models chat + catalog. |
OPENCODEZEN_API_KEY | optional | Enables OpenCode Zen CHAT (its model list is public without a key). |
CUSTOM_BASE_URL/KEY/MODEL | optional | The zero-code custom provider (any OpenAI-compatible endpoint). |
DEFAULT_PROVIDER | openrouter | Which provider answers when the request doesn't name one; failover starts here. |
FAILOVER_* | true / 3 / 800 / 6 / 12 | Deep failover: switch, max chain rounds, round pause, max models tried per provider, hard cap on total attempts. Every model of a provider is tried before moving to the next provider. |
TELEGRAM_BOT_TOKEN | 7216…:AAH8… | The Telegram bot webhook (/telegram guide). Empty = bot disabled. |
TELEGRAM_WEBHOOK_SECRET | any random string | Secret path segment for /api/telegram/<secret> — other paths get 403. |
API_SECRET_KEY | optional | Protects POST /api/v1/chat with X-API-Key. GET chat & /ask stay open. |
ALLOWED_ORIGINS | * | CORS allow-list (who may call your API from browsers). |
RATE_LIMIT_* / CHAT_RATE_LIMIT_* | 100 / 30 | Per-IP request caps for the whole API and for chat specifically. |
MODELS_CACHE_TTL_MS | 21600000 | How long the auto-fetched model catalog is cached (6 h). |
APP_URL / API_BASE_URL | pages.dev URL / empty | Attribution header + optional base-URL override (leave empty = auto-detect). |
4. After importing — verify in 60 seconds
- Open
/api/v1/config→ should showversion: 1.4.0and your base URL. - Click /ask?prompt=Say GATEWAY-OK → JSON answer straight in the browser.
- Open /status/ → provider tiles should be live.
- If you set the Telegram vars, run the
setWebhookcommand from the Telegram page and message your bot.
- UPSTREAM_AUTH_ERROR → the provider key is wrong/expired: update it here and redeploy.
- Variables changed but nothing happened → you forgot the redeploy (step 1e).
- Import button missing → use the classic "Add variables" flow and paste each KEY=value, or update Cloudflare dashboard language/permissions — the Import .env button exists on all current Pages projects.
- "Variables are managed through wrangler.toml" → a
wrangler.tomlwas added back to the repo. Delete it, commit, redeploy — dashboard variables become editable again. This project ships WITHOUT that file on purpose.