快速开始

添加模型

使用 AIChannel 和 AIService 注册模型。

创建 AIChannel,实现标准 V3 stream,再注册 AIModelSpec

class DeepSeekChannel extends AIChannel {
  constructor() {
    super({
      id: "deepseek",
      env_key: "DEEPSEEK_API_KEY",
      base_url: "https://api.deepseek.com/v1",
      ai_sdk_provider_id: "deepseek",
    });
  }

  protected async stream(input: AIChannelStreamInput) {
    const deepseek = createDeepSeek({
      apiKey: read_required_env(input, this.env_key ?? ""),
      baseURL: this.base_url,
    });
    return deepseek(input.model.upstream_model).doStream(input.call);
  }
}

const channel = new DeepSeekChannel();
const ai = new AIService();

ai.use(channel.model({
  id: "deepseek-v4-flash",
  upstream_model: "deepseek-chat",
  name: "DeepSeek V4 Flash",
  context_window: 128_000,
}));

federation.use(ai);

这一个 stream() 同时支持 city.ai.text()city.ai.stream()CityModel/v1/ai/chat/completions

reasoning、fallback、计费和 providerOptions 详见 AIChannel 与模型注册