Chat Flow
Flow Builder
Blocks
Integrations
OpenRouter

OpenRouter Integration

What it does: Access multiple AI models through a single unified API using OpenRouter. Route requests to various providers like OpenAI, Anthropic, Google, Meta, and more.

🔄

In simple terms: OpenRouter is like a universal adapter for AI models. Instead of connecting to each AI provider separately, use OpenRouter to access hundreds of models through one simple integration.

When to Use This

Use OpenRouter when you need:

  • ✅ Access to multiple AI models without managing separate API keys
  • ✅ Cost optimization by choosing the best price/performance ratio
  • ✅ Fallback options if one model is unavailable
  • ✅ Easy model switching without code changes
  • ✅ Access to latest models immediately when released

Example: Build a chatbot that can switch between GPT-4, Claude, Llama, or any other model based on user preference or cost considerations.

Key Features

  • Multi-Provider Access: 100+ models from OpenAI, Anthropic, Google, Meta, and more
  • Unified API: OpenAI-compatible API format
  • Cost Tracking: Built-in usage tracking and billing
  • Rate Limiting: Automatic rate limit management
  • Model Fallbacks: Switch models if one fails
  • Real-Time Updates: Access to newest models as they're released

Setup Guide

Step 1: Get OpenRouter API Key

  1. Go to openrouter.ai (opens in a new tab) and sign up
  2. Navigate to the API Keys section in your dashboard
  3. Click "Create API Key"
  4. Give it a descriptive name
  5. Copy and save your API key securely

Step 2: Configure the Block

Connection Settings:

  1. Credentials: Select your OpenRouter credentials from the dropdown or create new ones

    • API Key: Your OpenRouter API key
    • The system will automatically fetch available models
  2. Model: Select the AI model you want to use

    • Dozens of models available (GPT-4, Claude, Llama, etc.)
    • Models are fetched from OpenRouter API
    • Each model has different capabilities and pricing
  3. Messages: Configure the conversation

    • System Message: Instructions that guide the AI's behavior
    • User Messages: Add user queries and context
    • Dialogue: Use conversation history from variables
  4. Temperature: Control response randomness (0-2)

    • 0: Deterministic, focused responses
    • 1: Balanced creativity (default)
    • 2: Maximum creativity and randomness
  5. Response Mapping: Save AI responses to variables

    • Map "Message content" to workflow variables
    • Access total tokens used
    • Store response for later use

Message Configuration

System Message

Define how the AI should behave:

You are a helpful customer support assistant. Be friendly, professional, and concise.
Always ask clarifying questions if the user's request is unclear.

User Messages

Add the user's query:

  • Use workflow variables: {{user_question}}
  • Combine multiple inputs: User asking about {{topic}}: {{message}}
  • Add context: Based on {{previous_answer}}, please explain {{new_topic}}

Dialogue History

Reference conversation history:

  • Select a dialogue variable that stores past messages
  • Maintains context across multiple exchanges
  • Enables natural, coherent conversations

Model Selection

Popular Models Available

OpenAI Models:

  • GPT-4 Turbo: Latest OpenAI model
  • GPT-4: High capability, reasoning
  • GPT-3.5 Turbo: Fast and cost-effective

Anthropic Models:

  • Claude 3 Opus: Highest capability
  • Claude 3 Sonnet: Balanced performance
  • Claude 3 Haiku: Fast and efficient

Open Source Models:

  • Llama 3: Meta's latest model
  • Mixtral: Mistral AI's mixture of experts
  • Command R+: Cohere's command model

Specialized Models:

  • Image generation models
  • Code-specific models
  • Translation models

Common Use Cases

Intelligent Chatbot

Create a responsive assistant that understands context:

  • Model: claude-3-sonnet-20240229
  • System Message:
    You are a knowledgeable AI assistant. Provide accurate, helpful answers.
    If you don't know something, say so honestly.
  • User Message: {{user_question}}
  • Temperature: 0.7
  • Response Mapping: Save "Message content" to {{ai_response}}

Content Generation

Generate blog posts, product descriptions, or marketing copy:

  • Model: gpt-4-turbo
  • System Message:
    You are a professional content writer. Create engaging, SEO-friendly content
    that captures the brand voice and appeals to the target audience.
  • User Message: Write a blog post about {{topic}}
  • Temperature: 1.2 (higher for creativity)

Code Assistant

Help users with programming questions:

  • Model: gpt-4-code or claude-3-opus
  • System Message:
    You are an expert programmer. Provide clear code examples with explanations.
    Follow best practices and consider security implications.
  • User Message: {{code_question}}
  • Temperature: 0.3 (lower for accuracy)

Customer Support

Answer customer queries using your knowledge base:

  • Model: gpt-3.5-turbo (cost-effective)
  • System Message:
    You are a customer support agent. Use the provided context to answer questions.
    Be empathetic, professional, and solution-oriented.
    
    Context: {{knowledge_base_results}}
  • User Message: {{customer_question}}
  • Temperature: 0.5

Translation Service

Translate content between languages:

  • Model: gpt-4 or claude-3-sonnet
  • System Message:
    You are a professional translator. Provide accurate translations that preserve
    the meaning, tone, and cultural context of the original text.
  • User Message: Translate this from {{source_lang}} to {{target_lang}}: {{text}}
  • Temperature: 0.2 (precision matters)

Advanced Configuration

Using Dialogue History

Setup:

  1. Create a dialogue variable (e.g., conversation_history)
  2. Add messages to it using Set Variable blocks
  3. Reference it in OpenRouter block's message section

Example Flow:

1. User sends message → Store in {{user_message}}
2. Append user message to {{conversation_history}}
3. OpenRouter block:
   - Messages: Use dialogue variable {{conversation_history}}
   - Get response
4. Append AI response to {{conversation_history}}
5. Continue conversation with full context

Response Mapping

Extract specific data from AI responses:

FieldWhat It Contains
Message contentThe actual AI response text
Total tokensNumber of tokens used (for cost tracking)

Example Mapping:

  • Map "Message content" to {{ai_answer}}
  • Map "Total tokens" to {{tokens_used}}
  • Use {{ai_answer}} in subsequent steps
  • Track costs with {{tokens_used}}

What You Get Back

After running an OpenRouter completion:

  • Message Content: The AI-generated response
  • Total Tokens: Token count for billing/tracking
  • Model Used: Confirmation of which model processed the request

Tips for Success

  1. Choose the right model - Balance cost, speed, and capability

    • GPT-3.5 Turbo: Fast and cheap for simple tasks
    • GPT-4/Claude 3: Complex reasoning and analysis
    • Llama 3: Open source, good for basic tasks
  2. Optimize system messages - Clear instructions improve results

    • Be specific about desired output format
    • Include examples if possible
    • Define tone and style
  3. Manage temperature - Adjust based on task

    • Low (0-0.3): Facts, code, structured data
    • Medium (0.5-0.8): Conversations, explanations
    • High (1.0-2.0): Creative writing, brainstorming
  4. Use dialogue history - Maintain conversation context

    • Store messages in dialogue variables
    • Include relevant history, not everything
    • Clear context when starting new topics
  5. Monitor token usage - Track costs effectively

    • Store token counts in variables
    • Set up alerts for high usage
    • Use cheaper models when possible

Troubleshooting

ProblemLikely CauseSolution
No models shownInvalid API keyVerify API key in OpenRouter dashboard
Rate limit errorsToo many requestsAdd delays between requests or upgrade plan
Inconsistent responsesTemperature too highLower temperature for more consistent results
Context lostNot using dialogue historyImplement dialogue variables to maintain context
High costsUsing expensive models unnecessarilySwitch to GPT-3.5 or Llama for simpler tasks

Best Practices

  • Test multiple models - Find the best fit for your use case and budget
  • Start with low temperature - Increase only if you need more creativity
  • Use system messages effectively - Spend time crafting good instructions
  • Implement error handling - Have fallback options if a model fails
  • Monitor costs - Track token usage to avoid surprises
  • Keep messages concise - Reduce token usage by being clear and brief
  • Use streaming - For better user experience in real-time conversations

Pricing

OpenRouter charges based on model used:

  • Pay only for what you use
  • No subscription fees
  • Transparent per-token pricing
  • Volume discounts available

Check openrouter.ai/pricing (opens in a new tab) for current rates.

Indite Documentation v1.4.0
PrivacyTermsSupport