Back to Promptfoo

OpenRouter

site/docs/providers/openrouter.md

0.121.94.7 KB
Original Source

OpenRouter

OpenRouter provides a unified interface for accessing various LLM APIs, including models from OpenAI, Meta, Perplexity, and others. It follows the OpenAI API format - see our OpenAI provider documentation for base API details.

Setup

  1. Get your API key from OpenRouter
  2. Set the OPENROUTER_API_KEY environment variable or specify apiKey in your config

OpenRouter's catalog changes quickly. These are current popular and recent model IDs that work well as starting points. Context lengths are from the OpenRouter catalog at time of writing — check OpenRouter Models (or GET /api/v1/models) for live values.

Model IDContext (tokens)Good for
openai/gpt-5.41,050,000Highest-quality general evaluation
anthropic/claude-opus-4.71,000,000Long-running agentic workflows
openai/gpt-5.4-mini400,000Fast, lower-cost GPT-5 workflows
anthropic/claude-haiku-4.5200,000Lower-latency Claude runs
google/gemini-2.5-pro1,048,576Reasoning-heavy tasks
google/gemini-2.5-flash1,048,576Fast multimodal and general chat
meta-llama/llama-4-maverick1,048,576Popular open-weight frontier model
deepseek/deepseek-v3.2163,840Cost-efficient reasoning and tools
mistralai/mistral-small-3.2-24b-instruct128,000Compact Mistral general use
qwen/qwen3-32b40,960Strong open multilingual model

For the full catalog of 300+ models and current pricing, visit OpenRouter Models.

Basic Configuration

yaml
# yaml-language-server: $schema=https://promptfoo.dev/config-schema.json
providers:
  - id: openrouter:openai/gpt-5.4
    config:
      temperature: 0.7
      max_tokens: 1000

  - id: openrouter:anthropic/claude-opus-4.7
    config:
      max_tokens: 2000

  - id: openrouter:google/gemini-2.5-flash
    config:
      temperature: 0.7
      max_tokens: 4000

If you route OpenRouter traffic through a proxy or OpenRouter-compatible gateway, set apiBaseUrl in the provider config. Precedence is config.apiBaseUrl → the hardcoded OpenRouter default (https://openrouter.ai/api/v1); the generic OpenAI OPENAI_API_BASE_URL / OPENAI_BASE_URL env fallbacks are not consulted for this provider.

The same pattern applies to apiKeyEnvar — set it to read your API key from a custom environment variable name (default OPENROUTER_API_KEY).

yaml
providers:
  - id: openrouter:openai/gpt-5.4
    config:
      apiBaseUrl: https://proxy.example.com/openrouter/api/v1
      apiKeyEnvar: MY_PROXY_KEY # optional: read the Bearer token from $MY_PROXY_KEY

Features

  • Access to 300+ models through a single API
  • Mix free and paid models in your evaluations
  • Support for text and multimodal (vision) models
  • Compatible with OpenAI API format
  • Pay-as-you-go pricing

Thinking/Reasoning Models

Some models like Gemini 2.5 Pro include thinking tokens in their responses. You can control whether these are shown using the showThinking parameter:

yaml
providers:
  - id: openrouter:google/gemini-2.5-pro
    config:
      showThinking: false # Hide thinking content from output (default: true)

When showThinking is true (default), the output includes thinking content:

Thinking: <reasoning process>

<actual response>