#50

feat: add multi-provider support (OpenRouter, fal.ai, OpenAI direct)

Openprak-gupwants to merge intofrom

What this adds

A provider abstraction layer that lets ai-cli work without a Vercel AI Gateway key, by supporting OpenRouter, fal.ai, and direct OpenAI as backends.

Motivation

Getting a Vercel AI Gateway key requires a Vercel account. Many users already have OpenRouter or OpenAI API keys. This change lets them use ai-cli immediately with what they have.

How it works

Auto-detects the active backend from environment variables. Vercel AI Gateway remains the default — existing behaviour is unchanged.

Env vars setTextImageVideo
AI_GATEWAY_API_KEY✓ Vercel (100+ models)✓✓
OPENROUTER_API_KEY✓ OpenRouter (300+ models)——
OPENROUTER_API_KEY + FAL_KEY✓ OpenRouter✓ fal.ai (Flux, SDXL)✓ fal.ai (Kling, Wan, Runway)
FAL_KEY—✓ fal.ai✓ fal.ai
OPENAI_API_KEY✓ GPT models✓ DALL-E—
AI_PROVIDER=<backend>explicit override——

Changes

New file: src/lib/provider.ts

  • detectBackend() — reads env vars, returns active backend
  • createProvider() — returns { text(), image(), video() } factory functions pointing to the right AI SDK provider

src/lib/models.ts

  • fetchGatewayModels(backend) — fetches models from the right source
  • OpenRouter: live from openrouter.ai/api/v1/models
  • fal.ai: static catalogue (Flux, Kling, Wan, HunyuanVideo, Runway Gen3) — fal.ai has no public model list endpoint
  • OpenAI: static catalogue (GPT-4o, o3, o4-mini, DALL-E 2/3, GPT Image 1)
  • resolveModels(modality, model, known, backend) — selects correct defaults per backend

src/commands/text.ts, image.ts, video.ts, models.ts

  • All commands call createProvider() and use provider.text/image/video(modelId)
  • video.ts exits with a clear message if backend has no video support
  • image.ts language-image path (GPT-4o with image output) is guarded to Vercel gateway only

New dependencies

  • @openrouter/ai-sdk-provider v2.9.0
  • @ai-sdk/openai v3.0.58
  • @ai-sdk/fal v2.0.33

Testing status

  • TypeScript type-checks clean (tsc --noEmit)
  • CLI starts and all --help pages render correctly
  • Provider package APIs verified at runtime (fal.image, fal.video, openrouter() all confirmed callable with correct signatures)
  • End-to-end generation via OpenRouter (not tested with live key — wiring is correct based on package API verification)
  • End-to-end generation via fal.ai (not tested with live key — wiring is correct based on package API verification)
  • Vercel AI Gateway path: unchanged, all existing tests pass

Happy to add end-to-end tests or adjust the approach based on feedback. If the project prefers to keep the tool Vercel-specific, I understand — just thought this was worth proposing given how often it comes up for first-time users.

Activity

4
vercel[bot]6mo ago

@prak-gup is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

socket-security[bot]6mo ago

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

View full report

vercel[bot]reviewed6mo ago