Downcity
Downcity City DocsGuides

Provider Environment Variables

How to configure provider API keys in the City environment.

All provider API keys are managed through City's own env table.

Declare environment variables

Declare them in the Provider constructor:

const deepseek = new Provider("deepseek", {
  env: { DEEPSEEK_API_KEY: "DeepSeek API Key" },
  baseURL: "https://api.deepseek.com",
  envKey: "DEEPSEEK_API_KEY",
  text: deepseekTextHandler,
  stream: deepseekStreamHandler,
});

The env field declares required environment variables (key -> description), and envKey tells automatic passthrough which key to read.

Set environment variables

Write them through the Admin API:

curl -X POST http://127.0.0.1:43127/v1/env/upsert \
  -H "Authorization: Bearer <admin_secret_key>" \
  -H "Content-Type: application/json" \
  -d '{"key": "DEEPSEEK_API_KEY", "value": "sk-xxx"}'

Or import a .env file in bulk:

curl -X POST http://127.0.0.1:43127/v1/env/import \
  -H "Authorization: Bearer <admin_secret_key>" \
  -H "Content-Type: application/json" \
  -d '{"raw": "DEEPSEEK_API_KEY=sk-xxx\nMOONSHOT_API_KEY=sk-yyy"}'

Read them inside a handler

text: async (ctx) => {
  const apiKey = ctx.env("DEEPSEEK_API_KEY");
  // Or use the helper that throws when missing
  const apiKey2 = readApiKey(ctx, "DEEPSEEK_API_KEY");
}

ctx.env(key) reads from City's active env table. AIService automatic passthrough also reads the API key through ctx.env(envKey).

See also HTTP API - admin env management.