AIChannel 环境变量
在 Federation 环境中配置上游 API Key。
在 Channel 上声明密钥:
class DeepSeekChannel extends AIChannel {
constructor() {
super({
id: "deepseek",
env: { DEEPSEEK_API_KEY: "DeepSeek API Key" },
base_url: "https://api.deepseek.com/v1",
});
}
protected async stream(input: AIChannelStreamInput) {
const api_key = input.env("DEEPSEEK_API_KEY");
if (!api_key) throw new Error("DEEPSEEK_API_KEY is required");
return stream_openai_compatible_model(input, {
api_key,
base_url: this.base_url ?? "https://api.deepseek.com/v1",
});
}
}env 会为模型目录的管理端视图生成必填 env 声明。一个 Channel 需要多个环境变量时直接添加多个字段。
值存储在 Federation env 表中,执行时通过 input.env(key) 读取。它们不会进入 CityModelDescriptor 或客户端运行时。