How to integrate Openrouter MCP with Claude Code

Connect Claude Code to Openrouter MCP. Generate python code from this prompt, summarize this article using claude-3, and more using natural language, with authentication handled for you.

Openrouter logoOpenrouter
Api Key

OpenRouter is a unified API platform for accessing language models from various providers. It lets you easily integrate and switch between multiple LLMs with a single API.

122 Tools

Introduction

Manage your Openrouter directly from Claude Code with zero worries about OAuth hassles, API-breaking issues, or reliability and security concerns.

You can do this in two different ways:

  1. Via Composio Connect - Direct and easiest approach
  2. Via Composio SDK - Programmatic approach with more control

Also integrate Openrouter with

Why use Composio?

  • Only one MCP URL to connect multiple apps with Claude Code with zero auth hassles.
  • Programmatic tool calling allows LLMs to write its code in a remote workbench to handle complex tool chaining. Reduces to-and-fro with LLMs for frequent tool calling.
  • Handling Large tool responses out of LLM context to minimize context rot.
  • Dynamic just-in-time access to 20,000 tools across 1700+ other Apps for cross-app workflows. It loads the tools you need, so LLMs aren't overwhelmed by tools you don't need.

Connecting Openrouter to Claude Code using Composio

1. Add the Composio MCP to Claude

Terminal

2. Start Claude Code

bash
claude

3. Open your MCP list

bash
/mcp

4. Select Composio and click on Authenticate

Select Composio and click Authenticate

5. This will redirect you to the Composio OAuth page. Complete the flow by authorizing Composio and you're all set.

Composio OAuth authorization page
Composio authorization complete
Ask Claude to connect to your account and authenticate via the link

What is the Openrouter MCP server, and what's possible with it?

The Openrouter MCP server is an implementation of the Model Context Protocol that connects your AI agent and assistants like Claude, Cursor, etc directly to your Openrouter account. It provides structured and secure access to a wide range of large language models, so your agent can generate completions, manage model access, check credits, and retrieve generation details seamlessly on your behalf.

  • Unified model completions: Let your agent generate chat-based or text completions using any model available through Openrouter, perfect for conversation or content creation tasks.
  • Model catalog and provider discovery: Ask your agent to list all available AI models and providers, helping you compare capabilities, endpoints, and pricing in real time.
  • Credit monitoring and usage tracking: Have your agent fetch your current API credit balance, so you always know your usage limits before starting new tasks.
  • Generation result retrieval: Direct your agent to pull detailed metadata for any previous generation, including token counts, costs, and latency for analysis or auditing.
  • Endpoint and configuration info: Empower your agent to fetch the latest model endpoints and supported parameters, making it easy to fine-tune routing and optimize performance.

Connecting Openrouter via Composio SDK

Composio SDK is the underlying technology that powers these integrations. It provides a universal gateway with full programmatic control. You can programmatically generate an MCP URL with the app you need (here Openrouter) for even more tool search precision. It's secure and reliable.

How the Composio SDK works

The Composio SDK follows a three-phase workflow:

  1. Discovery: Searches for tools matching your task and returns relevant toolkits with their details.
  2. Authentication: Checks for active connections. If missing, creates an auth config and returns a connection URL via Auth Link.
  3. Execution: Executes the action using the authenticated connection.

Step-by-step Guide

Step by step10 STEPS
1

Prerequisites

Before starting, make sure you have:
  • Claude Pro, Max, or API billing enabled Anthropic account
  • Composio API Key
  • A Openrouter account
  • Basic knowledge of Python or TypeScript
2

Install Claude Code

bash
# macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bash

# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

# Windows CMD
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

To install Claude Code, use one of the following methods based on your operating system:

3

Set up Claude Code

bash
cd your-project-folder
claude

Open a terminal, go to your project folder, and start Claude Code:

  • Claude Code will open in your terminal
  • Follow the prompts to sign in with your Anthropic account
  • Complete the authentication flow
  • Once authenticated, you can start using Claude Code
Claude Code initial setup showing sign-in prompt
Claude Code terminal after successful login
4

Set up environment variables

bash
COMPOSIO_API_KEY=your_composio_api_key_here
USER_ID=your_user_id_here

Create a .env file in your project root with the following variables:

  • COMPOSIO_API_KEY authenticates with Composio (get it from Composio dashboard)
  • USER_ID identifies the user for session management (use any unique identifier)
5

Install Composio library

npm install @composio/core dotenv

Install the Composio TypeScript library to create MCP sessions.

  • @composio/core provides the core Composio functionality
  • dotenv loads environment variables from your .env file
6

Generate Composio MCP URL

import 'dotenv/config';
import { Composio } from '@composio/core';

const { COMPOSIO_API_KEY, USER_ID } = process.env;

if (!COMPOSIO_API_KEY || !USER_ID) {
  throw new Error('COMPOSIO_API_KEY and USER_ID required in .env');
}

const composioClient = new Composio({ apiKey: COMPOSIO_API_KEY });

const composioSession = await composioClient.create(USER_ID, {
  toolkits: ['openrouter'],
});

const composioMcpUrl = composioSession?.mcp.url;

console.log(`MCP URL: ${composioMcpUrl}`);
console.log(`\nUse this command to add to Claude Code:`);
console.log(`claude mcp add --transport http openrouter-composio "${composioMcpUrl}" --headers "X-API-Key:${COMPOSIO_API_KEY}"`);

Create a script to generate a Composio MCP URL for Openrouter. This URL will be used to connect Claude Code to Openrouter.

What's happening

  • We import the Composio client and load environment variables
  • Create a Composio instance with your API key
  • Call create() to create a Tool Router session for Openrouter
  • The returned mcp.url is the MCP server URL that Claude Code will use
  • The script prints this URL so you can copy it
7

Run the script and copy the MCP URL

node --loader ts-node/esm generate_mcp_url.ts
# or if using tsx
tsx generate_mcp_url.ts

Run your TypeScript script to generate the MCP URL.

  • The script connects to Composio and creates a Tool Router session
  • It prints the MCP URL and the exact command you need to run
  • Copy the entire claude mcp add command from the output
8

Add Openrouter MCP to Claude Code

bash
claude mcp add --transport http openrouter-composio "YOUR_MCP_URL_HERE" --headers "X-API-Key:YOUR_COMPOSIO_API_KEY"

# Then restart Claude Code
exit
claude

In your terminal, add the MCP server using the command from the previous step. The command format is:

  • claude mcp add registers a new MCP server with Claude Code
  • --transport http specifies that this is an HTTP-based MCP server
  • The server name (openrouter-composio) is how you'll reference it
  • The URL points to your Composio Tool Router session
  • --headers includes your Composio API key for authentication

After running the command, close the current Claude Code session and start a new one for the changes to take effect.

9

Verify the installation

bash
claude mcp list

Check that your Openrouter MCP server is properly configured.

  • This command lists all MCP servers registered with Claude Code
  • You should see your openrouter-composio entry in the list
  • This confirms that Claude Code can now access Openrouter tools

If everything is wired up, you should see your openrouter-composio entry listed:

Claude Code MCP list showing the toolkit MCP server
10

Authenticate Openrouter

The first time you try to use Openrouter tools, you'll be prompted to authenticate.

  • Claude Code will detect that you need to authenticate with Openrouter
  • It will show you an authentication link
  • Open the link in your browser (or copy/paste it)
  • Complete the Openrouter authorization flow
  • Return to the terminal and start using Openrouter through Claude Code

Once authenticated, you can ask Claude Code to perform Openrouter operations in natural language. For example:

  • "Generate Python code from this prompt"
  • "Summarize this article using Claude-3"
  • "List all available Llama-3 model endpoints"

Complete Code

Here's the complete code to get you started with Openrouter and Claude Code:

import 'dotenv/config';
import { Composio } from '@composio/core';

const { COMPOSIO_API_KEY, USER_ID } = process.env;

if (!COMPOSIO_API_KEY || !USER_ID) {
  throw new Error('COMPOSIO_API_KEY and USER_ID required in .env');
}

const composioClient = new Composio({ apiKey: COMPOSIO_API_KEY });

const composioSession = await composioClient.create(USER_ID, {
  toolkits: ['openrouter'],
});

const composioMcpUrl = composioSession?.mcp.url;

console.log(`MCP URL: ${composioMcpUrl}`);
console.log(`\nUse this command to add to Claude Code:`);
console.log(`claude mcp add --transport http openrouter-composio "${composioMcpUrl}" --headers "X-API-Key:${COMPOSIO_API_KEY}"`);

Conclusion

You've successfully integrated Openrouter with Claude Code using Composio's MCP server. Now you can interact with Openrouter directly from your terminal using natural language commands.

Key features of this setup:

  • Terminal-native experience without switching contexts
  • Natural language commands for Openrouter operations
  • Secure authentication through Composio's managed MCP
  • Tool Router for dynamic tool discovery and execution

Next steps:

  • Try asking Claude Code to perform various Openrouter operations
  • Add more toolkits to your Tool Router session for multi-app workflows
  • Integrate this setup into your development workflow for increased productivity

You can extend this by adding more toolkits, implementing custom workflows, or building automation scripts that leverage Claude Code's capabilities.

TOOLS

Supported Tools

Every Openrouter action and event your agent gets out of the box.

Activate a validated private endpoint

Make a validated draft routable.

Bulk add members to a workspace

Add multiple organization members to a workspace.

Bulk assign keys to a guardrail

Assign multiple API keys to a specific guardrail.

Bulk assign members to a guardrail

Assign multiple organization members to a specific guardrail.

Bulk remove members from a workspace

Remove multiple members from a workspace.

Bulk unassign keys from a guardrail

Unassign multiple API keys from a specific guardrail.

Bulk unassign members from a guardrail

Unassign multiple organization members from a specific guardrail.

Create a new API key

Create a new API key for the authenticated user.

Create authorization code

Create an authorization code for the PKCE flow to generate a user-controlled API key

Create a batch

Creates a batch of requests that run asynchronously against a single endpoint (`/v1/chat/completions`, `/v1/responses`, `/v1/messages`, `/v1/embeddings`).

Create a BYOK provider credential

Create a new bring-your-own-key (BYOK) provider credential.

Create Chat Completion

Generate a chat-style completion from messages and a selected model, with function-call request options.

Create Coinbase Charge

Tool to create a Coinbase charge for crypto payment to add credits to your OpenRouter account.

Create Embeddings

Create vector embeddings for text, token, or multimodal inputs.

Create a guardrail

Create a new guardrail for the authenticated user.

Create Message (Anthropic Format)

Create a message using Anthropic Messages API format via OpenRouter, with text, image, PDF, tool, and extended-thinking request options.

Create an observability destination

Create a new observability destination.

Create a preset from a chat-completions request body

Creates a preset (or a new version of an existing one) from an inference request body.

Create a preset from a messages request body

Creates a preset (or a new version of an existing one) from an inference request body.

Create a preset from a responses request body

Creates a preset (or a new version of an existing one) from an inference request body.

Create a private endpoint

Create a private endpoint as a draft.

Create a SCIM group mapping

Create a SCIM group-to-workspace role mapping.

Start a SCIM directory sync

Start a SCIM directory sync.

Create Speech

Synthesize speech from text or multi-speaker turns.

Create Transcription

Transcribe audio into text using an OpenRouter speech-to-text model.

Create Video Generation

Submit an asynchronous video generation job to OpenRouter.

Create a workspace

Create a new workspace for the authenticated user.

Delete an API key

Delete one of the authenticated account's own API keys, revoking the selected key's access.

Delete a batch

Deletes a batch in a terminal status (`completed`, `failed`, `expired`, or `cancelled`) and its stored requests and results.

Delete a BYOK provider credential

Delete (soft-delete) a bring-your-own-key (BYOK) provider credential by its `id`.

Delete a file

Deletes a file owned by the requesting workspace.

Delete a guardrail

Delete an existing guardrail.

Delete an observability destination

Delete an existing observability destination.

Delete a private endpoint

Delete a private endpoint and stop routing to it.

Delete a SCIM group mapping

Delete a SCIM group-to-workspace mapping.

Delete a workspace

Delete an existing workspace.

Delete a workspace budget

Remove the budget for a given interval.

Disable a private endpoint

Stop routing to an active endpoint without deleting it.

Download Container File Content

Download raw file content from an OpenRouter container using its canonical container and file IDs.

Download File Content

Download raw content of a server-created file.

Enable a private endpoint

Resume routing to a disabled endpoint.

Exchange authorization code for API key

Exchange an authorization code from the PKCE flow for a user-controlled API key

Exchange a workload identity token

RFC 8693 token exchange.

Generate an image

Generates an image from a text prompt via the image generation router

Get available analytics metrics and dimensions

Returns the available metrics, dimensions, filter operators, and granularities for the analytics query endpoint.

Get a single API key

Get a single API key by hash.

Top apps by token usage

Returns the top public apps on OpenRouter ranked by token usage inside the requested date window, matching the public apps marketplace on openrouter.

Get a batch

Returns a batch with its status and request counts.

List Benchmarks

Unified benchmark endpoint that aggregates scores from multiple benchmark sources (Artificial Analysis, Design Arena, and OpenRouter's own tau-bench, GPQA, and web-search evals).

Get a BYOK provider credential

Get a single bring-your-own-key (BYOK) provider credential by its `id`.

Retrieve a container file

Returns the metadata of a single file in a container.

Get Credits

Tool to get the current API credit balance for the authenticated user.

Get Current Key

Tool to get information about the currently authenticated API key.

Get file metadata

Retrieves metadata for a single file owned by the requesting workspace.

Get Generation

Tool to retrieve a generation result by its unique ID.

Get a guardrail

Get a single guardrail by ID.

Get a model by its slug

Returns full details for a single model identified by its author and slug (e.

Get Models Count

Tool to get the total count of available models on OpenRouter.

OpenRouter access token signing keys

RFC 7517 JWK Set containing the public keys OpenRouter signs access tokens with.

Get an observability destination

Fetch a single observability destination by its UUID.

Get organization settings

Get the settings of the organization associated with the authenticated management key.

Get a preset

Retrieves a preset by its slug with its currently designated version inline.

Get a specific version of a preset

Retrieves a specific version of a preset by its slug and version number.

Get a private endpoint

Get one private endpoint with its upstream configuration and current pricing.

Daily token totals for top 50 models

Returns the top 50 public models per day by total token usage on OpenRouter, plus a single aggregated `other` row per day that sums every model outside that top 50.

Get a SCIM group mapping

Get a SCIM group-to-workspace mapping.

Get SCIM directory sync status

Get SCIM directory sync status.

Cost per session by harness and model

Returns weekly refreshed, aggregated cost-per-session cells for the published harnesses.

Task classification market share

Returns the market-share breakdown of OpenRouter traffic by task classification (e.

Get a server tool

One server tool by canonical name or any accepted alias, with the models that run it natively.

Get user activity grouped by endpoint

Returns user activity data grouped by endpoint for the last 30 (completed) UTC days.

Get Video Content

Download one output from a completed OpenRouter video generation job.

Get Video Generation

Poll a video generation job for its status, outputs, and usage.

Get a workspace

Get a single workspace by ID or slug.

Get a workspace budget

Retrieve the budget for a given interval.

List API keys

List all API keys for the authenticated user.

List Available Models

List available OpenRouter models, optionally filtered by category.

List batches

Lists batches in the workspace of the authenticating API key, newest first.

List BYOK provider credentials

List the bring-your-own-key (BYOK) provider credentials for the authenticated entity's default workspace.

List container files

Lists the files in a container, in lexicographic path order.

List Embedding Models

List available OpenRouter embedding models with properties including architecture, pricing, and capabilities.

List files

Lists files belonging to the workspace of the authenticating API key.

Get stored prompt, completion, and error content for a generation

Get stored prompt, completion, and error content for a generation

List key assignments for a guardrail

List all API key assignments for a specific guardrail.

List member assignments for a guardrail

List all organization member assignments for a specific guardrail.

List guardrails

List all guardrails for the authenticated user.

List endpoints for an image model

Returns the full per-endpoint records for an image model: each endpoint's definitive supported parameters, pricing, and passthrough allowlist.

List image generation models

Lists every image generation model with its top-level supported-parameter superset and a URL to its full per-endpoint records.

List all key assignments

List all API key guardrail assignments for the authenticated user.

List all member assignments

List all organization member guardrail assignments for the authenticated user.

OpenRouter List Model Endpoints

Tool to list endpoints for a specific model.

List observability destinations

List the observability destinations configured for the authenticated entity's default workspace.

List organization members

List all members of the organization associated with the authenticated management key.

List presets

Lists all presets for the authenticated user, ordered by most recently updated first.

List versions of a preset

Lists all versions of a preset, ordered by version number ascending (oldest first).

List private endpoints

List the organization's private endpoints, including drafts.

OpenRouter List Providers

Tool to list all AI model providers available through the OpenRouter API.

List SCIM group mappings

List SCIM group-to-workspace mappings for the organization.

List SCIM groups

List SCIM groups for the organization.

List server tools

Lists every server tool OpenRouter can run on behalf of a model: accepted `tools[].

List User Models

List models filtered by user provider preferences, privacy settings, and guardrails.

List Video Models

List video generation models and their supported capabilities.

List workspace budgets

List all budgets configured for a workspace.

List workspace members

List all members of a workspace.

List workspaces

List all workspaces for the authenticated user.

OpenRouter List ZDR Endpoints

Tool to preview the impact of Zero Data Retention (ZDR) on the available endpoints.

Promote a container file into workspace documents

Copies a file from the container's sandbox prefix into the workspace's durable document storage, so it outlives the container.

Query analytics data

Execute an analytics query with specified metrics, dimensions, filters, and time range.

Rerank Content

Rank text or multimodal documents by relevance to a query.

Submit feedback for a generation

Submit structured feedback on a generation the authenticated user made.

Submit a System One request

Sends state and typed questions to a System One model such as Jev and returns its answers.

Update an API key

Update one of the authenticated account's own API keys.

Update a BYOK provider credential

Update an existing bring-your-own-key (BYOK) provider credential by its `id`.

Update a guardrail

Update an existing guardrail, or materialize an unconfigured workspace default guardrail.

Update an observability destination

Update an existing observability destination.

Update organization settings

Update the settings of the organization associated with the authenticated management key.

Update a private endpoint

Change any of the endpoint fields you own in one call; only the fields present change, and the response is the whole endpoint.

Update a SCIM group mapping

Update a SCIM group mapping role.

Update a workspace

Update an existing workspace by ID or slug.

Upload File

Upload a file for future API calls under the authenticating key's workspace.

Create or update a workspace budget

Create or update the budget for a given interval.

Validate a draft private endpoint

Send a live test request to the draft endpoint using the given workspace's BYOK credential for its provider.

FAQ

Frequently asked questions

With a standalone Openrouter MCP server, the agents and LLMs can only access a fixed set of Openrouter tools tied to that server. However, with the Composio Tool Router, agents can dynamically load tools from Openrouter and many other apps based on the task at hand, all through a single MCP endpoint.

Yes, you can. Claude Code fully supports MCP integration. You get structured tool calling, message history handling, and model orchestration while Tool Router takes care of discovering and serving the right Openrouter tools.

Yes, absolutely. You can configure which Openrouter scopes and actions are allowed when connecting your account to Composio. You can also bring your own OAuth credentials or API configuration so you keep full control over what the agent can do.

All sensitive data such as tokens, keys, and configuration is fully encrypted at rest and in transit. Composio is SOC 2 Type 2 compliant and follows strict security practices so your Openrouter data and credentials are handled as safely as possible.

Start with Openrouter.It takes 30 seconds.

Managed auth, hosted MCP servers, and every Openrouter tool your agent needs.Free to start.

Start building