Files
promptfoo--promptfoo/site/docs/providers/openrouter.md
T
wehub-resource-sync 0d3cb498a3
CI / Shell Format Check (push) Has been cancelled
CI / Check Ruby (3.4) (push) Has been cancelled
CI / CI Config (push) Has been cancelled
CI / Test on Node ${{ matrix.node }} and ${{ matrix.os }}${{ matrix.shard && format(' (shard {0}/3)', matrix.shard) || '' }} (push) Has been cancelled
CI / Build on Node ${{ matrix.node }} (push) Has been cancelled
CI / Style Check (push) Has been cancelled
CI / Generate Assets (push) Has been cancelled
CI / Check Python (3.14) (push) Has been cancelled
CI / Check Python (3.9) (push) Has been cancelled
CI / Build Docs (push) Has been cancelled
CI / Code Scan Action (push) Has been cancelled
CI / Site tests (push) Has been cancelled
CI / webui tests (push) Has been cancelled
CI / Run Integration Tests (push) Has been cancelled
CI / Run Smoke Tests (push) Has been cancelled
CI / Go Tests (push) Has been cancelled
CI / Share Test (push) Has been cancelled
CI / Redteam (Production API) (push) Has been cancelled
CI / Redteam (Staging API) (push) Has been cancelled
CI / GitHub Actions Lint (push) Has been cancelled
CI / Check Ruby (3.0) (push) Has been cancelled
release-please / release-please (push) Has been cancelled
release-please / build (push) Has been cancelled
release-please / publish-npm (push) Has been cancelled
release-please / publish-npm-backfill (push) Has been cancelled
release-please / docker (push) Has been cancelled
release-please / publish-code-scan-action (push) Has been cancelled
release-please / attest-code-scan-action (push) Has been cancelled
Deploy local.promptfoo.app / Deploy to Cloudflare Pages (push) Has been cancelled
Test and Publish Multi-arch Docker Image / test (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-amd64 platform:linux/amd64 runner:ubuntu-latest]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / build-docker-and-push-digests (map[digest-suffix:linux-arm64 platform:linux/arm64 runner:ubuntu-24.04-arm]) (push) Has been cancelled
Test and Publish Multi-arch Docker Image / merge-docker-digests (push) Has been cancelled
Test and Publish Multi-arch Docker Image / Attest Multi-arch Image (push) Has been cancelled
Validate Renovate Config / Validate Renovate Configuration (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:24:08 +08:00

4.8 KiB

sidebar_label, description
sidebar_label description
OpenRouter Access 300+ models through OpenRouter's unified API gateway with configurable routing, proxy support, and OpenAI-compatible requests

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 ID Context (tokens) Good for
openai/gpt-5.4 1,050,000 Highest-quality general evaluation
anthropic/claude-opus-4.7 1,000,000 Long-running agentic workflows
openai/gpt-5.4-mini 400,000 Fast, lower-cost GPT-5 workflows
anthropic/claude-haiku-4.5 200,000 Lower-latency Claude runs
google/gemini-2.5-pro 1,048,576 Reasoning-heavy tasks
google/gemini-2.5-flash 1,048,576 Fast multimodal and general chat
meta-llama/llama-4-maverick 1,048,576 Popular open-weight frontier model
deepseek/deepseek-v3.2 163,840 Cost-efficient reasoning and tools
mistralai/mistral-small-3.2-24b-instruct 128,000 Compact Mistral general use
qwen/qwen3-32b 40,960 Strong open multilingual model

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

Basic Configuration

# 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).

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:

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>