AI Providers

AI Providers

Try-on generation is abstracted behind a provider interface so KIE.AI and fal.ai are interchangeable.

Interface

lib/server/try-on-provider.ts defines TryOnProviderClient:

type TryOnProviderClient = {
  generateTryOn(input): Promise<TryOnResult>;            // synchronous (polls)
  createTryOnTask(input & { callBackUrl? }): Promise<TryOnTaskCreation>;  // async
  getTaskSnapshot(taskId): Promise<TryOnTaskSnapshot>;   // poll provider directly
};

createTryOnProviderClient({ provider, modelOverride }) returns the KIE or fal client (lib/server/try-on-provider-client.ts). Default provider is kie.ai.

KIE.AI (lib/server/kie-ai-client.ts)

  • Uses KIE_API_KEY, KIE_API_BASE_URL, KIE_UPLOAD_BASE_URL, KIE_MODEL.
  • createTryOnTask resolves both images via resolveInputImagedata URLs are uploaded to the provider, http URLs are passed through. So the person image can be a data URL and the garment a public URL.
  • getTaskSnapshot polls the KIE task; generateTryOn wraps create+poll with retries.
  • KIE_ALLOW_MOCK_FALLBACK returns a mock result when the key is missing or on provider error (useful for local/dev).

fal.ai (lib/server/fal-ai-client.ts)

  • Alternative provider; selected per store via stores.generation_provider = 'fal.ai' with model nano-banana-2.

Per-store model selection

store.generation_provider + store.generation_model choose the client/model. Operators can change a store’s model from the admin dashboard.

Prompts

The garment/person inputs plus product metadata feed buildTryOnPrompt (category, product name/type) to steer the generation.