Guides
Provider Environment Variables
How to configure provider API keys in the Federation environment.
All provider API keys are managed through Federation's own env table.
Declare environment variables
Declare them in the Provider constructor:
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { Provider, type OpenAICompatibleClientConfig } from "@downcity/city";
class DeepSeekProvider extends Provider {
constructor() {
super({
id: "deepseek",
env: { DEEPSEEK_API_KEY: "DeepSeek API Key" },
baseURL: "https://api.deepseek.com",
envKey: "DEEPSEEK_API_KEY",
});
}
protected createClient({ apiKey, baseURL }: OpenAICompatibleClientConfig) {
return createOpenAICompatible({ apiKey, baseURL, name: "deepseek" });
}
}
const deepseek = new DeepSeekProvider();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\nOPENAI_API_KEY=sk-yyy"}'Read them inside a handler
import { readRequiredEnv, type Context } from "@downcity/city";
async text(ctx: Context) {
const apiKey = ctx.env("DEEPSEEK_API_KEY");
// Or use the helper that throws when missing
const apiKey2 = readRequiredEnv(ctx, "DEEPSEEK_API_KEY");
}ctx.env(key) reads from Federation's active env table. AIService automatic passthrough also reads the API key through ctx.env(envKey).
See also HTTP API - admin env management.