# OpenRouter (`apify/openrouter`) Actor

You can use any AI LLM model without accounts in AI providers. Use this Actor as a proxy for all requests. Use pay-per-event pricing to pay only for the real credit used.

- **URL**: https://apify.com/apify/openrouter.md
- **Developed by:** [Apify](https://apify.com/apify) (Apify)
- **Categories:** AI, Agents
- **Stats:** 5,807 total users, 177 monthly users, 99.7% runs succeeded, 33 bookmarks
- **User rating**: 4.72 out of 5 stars

## Pricing

Pay per event + usage

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## OpenRouter Proxy

This Apify Actor proxies the [OpenRouter](https://openrouter.ai) API over an OpenAI-compatible interface, billed to your Apify account on a pay-per-event basis.

### What this Actor does

- **Proxy access**: Forwards API requests to OpenRouter's models
- **OpenRouter SDK compatible**: Works with the official [`@openrouter/sdk`](https://www.npmjs.com/package/@openrouter/sdk) (TypeScript) and any OpenAI-compatible HTTP client
- **Billing**: Charges your Apify account at OpenRouter's rates (see [Pricing](#pricing))
- **Supports**: chat completions, embeddings, streaming, and image generation via `modalities`
- **Multiple API formats**: OpenAI (`/chat/completions`), Anthropic (`/messages`), and OpenAI Responses (`/responses`)
- **Standby mode**: Runs in Standby mode with a static URL, like a standard web server

### Supported endpoints

| Method | Endpoint                                   | Description                      |
| ------ | ------------------------------------------ | -------------------------------- |
| POST   | `/api/v1/chat/completions`                 | Chat completions (OpenAI format) |
| POST   | `/api/v1/messages`                         | Messages (Anthropic format)      |
| POST   | `/api/v1/responses`                        | Responses (OpenAI Responses API) |
| POST   | `/api/v1/embeddings`                       | Text embeddings                  |
| GET    | `/api/v1/models`                           | List available models            |
| GET    | `/api/v1/models/count`                     | Model count                      |
| GET    | `/api/v1/models/user`                      | User model preferences           |
| GET    | `/api/v1/models/{author}/{slug}/endpoints` | Model endpoints                  |
| GET    | `/api/v1/embeddings/models`                | Embedding models                 |
| GET    | `/api/v1/providers`                        | Available providers              |
| GET    | `/api/v1/endpoints/zdr`                    | Zero-data-retention endpoints    |
| GET    | `/api/v1/generation`                       | Generation details               |

For full API documentation, see the [OpenRouter API docs](https://openrouter.ai/docs/api-reference).

### Pricing

This Actor uses a pay-per-event pricing model on the Apify platform. You pay for the tokens used by the OpenRouter API.
Free tier users pay 10x more than paying users and are limited to 2,048 tokens per response.

#### Pricing structure

- **Event**: `openrouter-api-usage`
- **Paying users**: Pay the exact OpenRouter cost (rounded up to nearest $0.00001)

#### Pricing examples

| OpenRouter cost | Calculation            | Charged events | You pay  | Markup factor |
| --------------- | ---------------------- | -------------- | -------- | ------------- |
| $0.00001212     | `0.00001212 / 0.00001` | 2              | $0.00002 | 1.65x         |
| $0.0001         | `0.0001 / 0.00001`     | 10             | $0.0001  | 1x (exact)    |
| $0.001          | `0.001 / 0.00001`      | 100            | $0.001   | 1x (exact)    |
| $0.01           | `0.01 / 0.00001`       | 1,000          | $0.01    | 1x (exact)    |

### Quick start

The proxy only accepts calls from inside the Apify platform (caller type `APIFY_ACTOR`). The examples below use the official [OpenRouter TypeScript SDK](https://openrouter.ai/docs/client-sdks/typescript/overview); any OpenAI-compatible HTTP client also works — point it at the same base URL and pass your Apify token as the bearer.

#### 1. Install [`@openrouter/sdk`](https://www.npmjs.com/package/@openrouter/sdk)

```bash
npm install @openrouter/sdk
````

#### 2. Basic usage

Point the SDK at the proxy with `serverURL`, and pass your Apify token as `apiKey` — the SDK sends it as `Authorization: Bearer <token>`, which is what the proxy expects.

```typescript
import { OpenRouter } from '@openrouter/sdk';

const client = new OpenRouter({
    serverURL: 'https://openrouter.apify.actor/api/v1',
    apiKey: process.env.APIFY_TOKEN, // Apify token is loaded automatically in runtime
});

const result = await client.chat.send({
    chatRequest: {
        model: 'openrouter/auto',
        messages: [
            {
                role: 'user',
                content: 'What is the meaning of life?',
            },
        ],
    },
});

console.log(result.choices[0].message.content);
```

#### 3. Streaming responses

Set `stream: true` inside `chatRequest`. The SDK returns an async iterable of SSE chunks; the final chunk carries the `usage` object the proxy uses for billing.

```typescript
const stream = await client.chat.send({
    chatRequest: {
        model: 'openrouter/auto',
        messages: [
            {
                role: 'user',
                content: 'Write a short story about a robot.',
            },
        ],
        stream: true,
    },
});

for await (const chunk of stream) {
    process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}
```

#### 4. Image generation

OpenRouter generates images through chat completions on image-capable models, using the `modalities` parameter:

```typescript
const result = await client.chat.send({
    chatRequest: {
        model: 'google/gemini-2.5-flash-image', // Image-capable model
        messages: [
            {
                role: 'user',
                content: 'Generate an image of a cute baby sea otter',
            },
        ],
        modalities: ['text', 'image'], // Enable image generation
    },
});

// Generated image data lives on the assistant message
console.log(result.choices[0].message);
```

**Note:** OpenRouter does not expose an OpenAI-style `/images/generations` endpoint. Image generation goes through compatible chat-completion models. Check available image-capable models on [OpenRouter's models page](https://openrouter.ai/models).

#### Using a different client

The proxy is OpenAI-compatible, so any client that lets you set the base URL and the `Authorization` header works — point it at `https://openrouter.apify.actor/api/v1` and pass `Authorization: Bearer <APIFY_TOKEN>`. The [OpenAI SDK](https://www.npmjs.com/package/openai) can be wired up this way, but it currently rejects some of the SSE events OpenRouter emits on streamed responses; prefer `@openrouter/sdk` above.

Raw `fetch` works too:

```typescript
const res = await fetch('https://openrouter.apify.actor/api/v1/chat/completions', {
    method: 'POST',
    headers: {
        'content-type': 'application/json',
        Authorization: `Bearer ${process.env.APIFY_TOKEN}`,
    },
    body: JSON.stringify({
        model: 'openrouter/auto',
        messages: [{ role: 'user', content: 'Hello' }],
    }),
});
```

### Available models

Every model OpenRouter serves is reachable through this proxy. For the full list, see [OpenRouter's models page](https://openrouter.ai/models) or call `GET /api/v1/models`.

### Authentication

The Actor uses your Apify token for authentication. In Actor environments on the Apify platform, `APIFY_TOKEN` is automatically available.

### Support

For issues related to this Actor, please [open an issue](https://github.com/apify/actor-openrouter-proxy/issues) or contact the Actor developer on [Apify Store](https://apify.com/apify/openrouter).

# Actor input Schema

## Actor input object example

```json
{}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("apify/openrouter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("apify/openrouter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call apify/openrouter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=apify/openrouter",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "OpenRouter",
        "description": "You can use any AI LLM model without accounts in AI providers. Use this Actor as a proxy for all requests. Use pay-per-event pricing to pay only for the real credit used.",
        "version": "1.0",
        "x-build-id": "kB6aPu5d1A5C810Lu"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/apify~openrouter/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-apify-openrouter",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/apify~openrouter/runs": {
            "post": {
                "operationId": "runs-sync-apify-openrouter",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/apify~openrouter/run-sync": {
            "post": {
                "operationId": "run-sync-apify-openrouter",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {}
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
