Skip to content

OpenRouter

FlowKit supports 100+ models via OpenRouter with the OpenRouterAdapter.

Setup

bash
export OPENROUTER_API_KEY=sk-or-...

Get your API key from OpenRouter.

Usage

typescript
import { OpenRouterAdapter } from "@andresaya/flowkit";

const adapter = new OpenRouterAdapter({
  apiKey: process.env.OPENROUTER_API_KEY!,
  model: "anthropic/claude-3-haiku",
});

const engine = new FlowEngine(flow, { llm: adapter, storage });

Configuration

typescript
interface OpenRouterConfig {
  /** OpenRouter API key (required) */
  apiKey: string;
  /** Model ID (default: openai/gpt-4o-mini) */
  model?: string;
  /** Your app name for rankings (optional) */
  appName?: string;
  /** Your site URL for rankings (optional) */
  siteUrl?: string;
  /** Temperature (default: 0) */
  temperature?: number;
  /** Timeout in ms (default: 60000) */
  timeout?: number;
  /** Enable streaming (default: false) */
  streaming?: boolean;
}
Model IDProviderCost
openai/gpt-4o-miniOpenAI$
openai/gpt-4oOpenAI$$$
anthropic/claude-3-haikuAnthropic$
anthropic/claude-3-5-sonnetAnthropic$$
anthropic/claude-3-opusAnthropic$$$
google/gemini-proGoogle$
meta-llama/llama-3.1-70b-instructMeta$$
mistralai/mistral-largeMistral$$
qwen/qwen-2.5-72b-instructAlibaba$

See OpenRouter Models for complete list.

Example

typescript
import { 
  agent, flow, FlowEngine, MemoryStorage, OpenRouterAdapter, 
  name, yesNo 
} from "@andresaya/flowkit";

const bot = agent("Alex")
  .personality("friendly")
  .build();

const myFlow = flow("greeting", bot)
  .ask("name", "What's your name?", name(), "user_name")
  .then("confirm")
  .ask("confirm", "Nice to meet you {{user_name}}! Need help?", yesNo(), "needs_help")
  .when({ yes: "help", no: "bye" })
  .say("help", "How can I help?")
  .done()
  .say("bye", "Goodbye!")
  .done()
  .build();

const engine = new FlowEngine(myFlow, {
  llm: new OpenRouterAdapter({
    apiKey: process.env.OPENROUTER_API_KEY!,
    model: "anthropic/claude-3-haiku",
    appName: "MyApp",  // Shows in OpenRouter dashboard
  }),
  storage: new MemoryStorage(),
});

const result = await engine.start("session-1");
console.log(result.message);

Features

FeatureSupported
StreamingYes
Tool CallingYes
JSON ModeYes
100+ ModelsYes
Free ModelsYes

Free Models: OpenRouter offers many free models including DeepSeek R1, Gemma, some Llama variants, and more. Free tier has rate limits (20 RPM, 50-1000 requests/day).

Why OpenRouter?

  • One API, many models - Access OpenAI, Anthropic, Google, Meta, etc.
  • Easy model switching - Just change the model ID
  • Transparent pricing - See token costs per request
  • Fallback support - Automatic failover between models

Tips

  1. Great for experimentation - Try different models easily
  2. Use for production diversity - Failover between providers
  3. Set appName - Track usage in OpenRouter dashboard
  4. Compare models - Test same flow with different models

Released under the MIT License.