Quickstart

Add a Model

Register a model with AIChannel and AIService.

Create an AIChannel, implement its standard V3 stream, then register an 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);

This single stream() implementation powers city.ai.text(), city.ai.stream(), CityModel, and /v1/ai/chat/completions.

See AIChannel and model registration for reasoning, fallback, billing, and providerOptions.