Skip to main content
Enabled when OPENROUTER_API_KEY is set in your environment.

Overview

The @standardagents/openrouter package provides the OpenRouter provider factory for Standard Agents. OpenRouter is a multi-provider gateway that routes requests to various LLM providers (OpenAI, Anthropic, Google, Meta, and more) through a single API.

Key Features

  • Access to 200+ models from multiple providers
  • Automatic pricing data fetched from OpenRouter API
  • Typed providerOptions for routing configuration
  • Provider selection, fallbacks, and price limits
  • Zero Data Retention (ZDR) endpoints
  • Provider-executed OpenRouter server tools

Installation

npm
pnpm
yarn

Quick Start

agents/models/claude_sonnet.ts
OpenRouter models automatically fetch pricing from the OpenRouter API. You do not need to specify inputPrice or outputPrice.

Provider Factory

The openrouter export is a provider factory function:

Model ID Format

OpenRouter uses a provider/model-name format for model IDs: Browse all available models at openrouter.ai/models.

Provider Options

The openrouter factory includes a typed schema for routing configuration:

Routing Options

All routing options are nested under the provider key:

Server Tool Options

OpenRouter server tools are provider-executed tools. Enable the tool names with providerTools, select them from prompts like normal tools, and pass optional OpenRouter parameters through providerOptions.serverTools:
serverTools configures native OpenRouter tool parameters only. It is stripped from the request body after the provider converts selected tools into openrouter:* tool definitions.

Price Limits

Set hard limits on pricing (request fails if no provider meets threshold):

Provider Selection

Control which providers handle your requests:

Sorting

Sort available providers by different criteria:

Zero Data Retention (ZDR)

For sensitive data, restrict to ZDR endpoints:

Performance Preferences

Set soft preferences for throughput and latency:

Type Safety

The providerOptions type is automatically inferred:

Model Capabilities

Set capabilities for proper framework behavior:

Environment Setup

Set your OpenRouter API key:
.dev.vars
For Cloudflare Workers:

Example Configurations

Budget-Conscious Model

High-Security Configuration

Multi-Provider Fallback

Performance-Optimized

Tool Calling

OpenRouter tool calls are sent with strict function schemas. The provider normalizes object schemas for OpenAI-backed endpoints by listing every object property in required, while AgentBuilder still validates the returned tool arguments against the original tool Zod schema before execution. When tools are present, tool_choice: "auto" is omitted because OpenRouter treats that as the default. This keeps endpoints that support tools but do not advertise the separate tool_choice parameter eligible for routing.

Provider-Executed Server Tools

The OpenRouter provider exposes these built-in server tools through getTools(): AgentBuilder marks these tools as provider-executed. The OpenRouter provider translates them to native openrouter:* tools for both Chat Completions and Responses requests, and records completed server tool usage through the generic provider-tool log path.

Generation Metadata

OpenRouter provides additional metadata about request routing that can be fetched after completion:

Exports

Next Steps

Models

Learn about model configuration

OpenAI Provider

Direct OpenAI API access

Prompts

Configure prompts with models

defineModel API

Complete API reference