|
1 |
| -## Standby TypeScript template |
| 1 | +# OpenRouter Proxy |
2 | 2 |
|
3 |
| -Start a new [web scraping](https://apify.com/web-scraping) project quickly and easily in TypeScript (Node.js) with our Standby project template. It provides a basic structure for building an Actor with [Apify SDK](https://docs.apify.com/sdk/js/) and allows you to easily add your own functionality. |
| 3 | +This Apify Actor creates a proxy for the Open Router API, allowing you to access multiple AI models through a unified OpenAI-compatible interface. All requests are charged to your Apify account on a pay-per-event basis. |
4 | 4 |
|
5 |
| -## Included features |
| 5 | +## What this Actor does |
6 | 6 |
|
7 |
| -- **[Apify SDK](https://docs.apify.com/sdk/js/)** - a toolkit for building [Actors](https://apify.com/actors) |
| 7 | +- **Proxy access**: Routes your API requests to Open Router's extensive collection of AI models |
| 8 | +- **OpenAI compatibility**: Works seamlessly with the OpenAI SDK and any OpenAI-compatible client |
| 9 | +- **Transparent billing**: Charges are applied to your Apify account at the same rates as Open Router |
| 10 | +- **Full feature support**: Supports both streaming and non-streaming responses |
| 11 | +- **No API key management**: Uses your Apify token for authentication - no need to manage separate Open Router API keys |
8 | 12 |
|
9 |
| -## Resources |
| 13 | +## Pricing |
10 | 14 |
|
11 |
| -- [Actor Standby documentation](https://docs.apify.com/platform/actors/development/programming-interface/standby) |
| 15 | +This Actor uses a pay-per-event pricing model through Apify. Each API request counts as one event. The underlying Open Router API costs are included in the per-event pricing, plus a 10% fee to cover the cost of running the proxy server. |
12 | 16 |
|
| 17 | +## Quick start |
13 | 18 |
|
14 |
| -## Getting started |
15 |
| - |
16 |
| -For complete information [see this article](https://docs.apify.com/platform/actors/development#build-actor-locally). To run the Actor use the following command: |
| 19 | +### 1. Install the OpenAI package |
17 | 20 |
|
18 | 21 | ```bash
|
19 |
| -apify run |
| 22 | +npm install openai |
20 | 23 | ```
|
21 | 24 |
|
22 |
| -## Deploy to Apify |
23 |
| - |
24 |
| -### Connect Git repository to Apify |
25 |
| - |
26 |
| -If you've created a Git repository for the project, you can easily connect to Apify: |
27 |
| - |
28 |
| -1. Go to [Actor creation page](https://console.apify.com/actors/new) |
29 |
| -2. Click on **Link Git Repository** button |
| 25 | +### 2. Basic usage |
| 26 | + |
| 27 | +```javascript |
| 28 | +import OpenAI from 'openai'; |
| 29 | + |
| 30 | +const openai = new OpenAI({ |
| 31 | + baseURL: 'https://michal-kalita--openrouter-proxy.apify.actor/api/v1', |
| 32 | + apiKey: 'no-key-required-but-must-not-be-empty', // Any non-empty string works; do NOT use a real API key. |
| 33 | + defaultHeaders: { |
| 34 | + Authorization: `Bearer ${process.env.APIFY_TOKEN}`, // Apify token is loaded automatically in runtime |
| 35 | + }, |
| 36 | +}); |
| 37 | + |
| 38 | +async function main() { |
| 39 | + const completion = await openai.chat.completions.create({ |
| 40 | + model: 'openrouter/auto', |
| 41 | + messages: [ |
| 42 | + { |
| 43 | + role: 'user', |
| 44 | + content: 'What is the meaning of life?', |
| 45 | + }, |
| 46 | + ], |
| 47 | + }); |
| 48 | + |
| 49 | + console.log(completion.choices[0].message); |
| 50 | +} |
| 51 | + |
| 52 | +await main(); |
| 53 | +``` |
30 | 54 |
|
31 |
| -### Push project on your local machine to Apify |
| 55 | +### 3. Streaming responses |
| 56 | + |
| 57 | +```javascript |
| 58 | +const stream = await openai.chat.completions.create({ |
| 59 | + model: 'openrouter/auto', |
| 60 | + messages: [ |
| 61 | + { |
| 62 | + role: 'user', |
| 63 | + content: 'Write a short story about a robot.', |
| 64 | + }, |
| 65 | + ], |
| 66 | + stream: true, |
| 67 | +}); |
| 68 | + |
| 69 | +for await (const chunk of stream) { |
| 70 | + process.stdout.write(chunk.choices[0]?.delta?.content || ''); |
| 71 | +} |
| 72 | +``` |
32 | 73 |
|
33 |
| -You can also deploy the project on your local machine to Apify without the need for the Git repository. |
| 74 | +## Available models |
34 | 75 |
|
35 |
| -1. Log in to Apify. You will need to provide your [Apify API Token](https://console.apify.com/account/integrations) to complete this action. |
| 76 | +This proxy supports all models available through Open Router from providers including: |
| 77 | +- OpenAI |
| 78 | +- Anthropic |
| 79 | +- Google |
| 80 | +- Meta |
| 81 | +- Perplexity |
| 82 | +- And many more... |
36 | 83 |
|
37 |
| - ```bash |
38 |
| - apify login |
39 |
| - ``` |
| 84 | +For a complete list of available models, visit [Open Router's models page](https://openrouter.ai/models). |
40 | 85 |
|
41 |
| -2. Deploy your Actor. This command will deploy and build the Actor on the Apify Platform. You can find your newly created Actor under [Actors -> My Actors](https://console.apify.com/actors?tab=my). |
| 86 | +## Authentication |
42 | 87 |
|
43 |
| - ```bash |
44 |
| - apify push |
45 |
| - ``` |
| 88 | +The Actor uses your Apify token for authentication. In Apify Actor environments, `APIFY_TOKEN` is automatically available. For local development, you can: |
46 | 89 |
|
47 |
| -## Documentation reference |
| 90 | +1. Set the environment variable: `export APIFY_TOKEN=your_token_here` |
| 91 | +2. Or pass it directly in the Authorization header |
| 92 | +3. Find your token in the [Apify Console](https://console.apify.com/account/integrations) |
48 | 93 |
|
49 |
| -To learn more about Apify and Actors, take a look at the following resources: |
| 94 | +## Support |
50 | 95 |
|
51 |
| -- [Apify SDK for JavaScript documentation](https://docs.apify.com/sdk/js) |
52 |
| -- [Apify SDK for Python documentation](https://docs.apify.com/sdk/python) |
53 |
| -- [Apify Platform documentation](https://docs.apify.com/platform) |
54 |
| -- [Join our developer community on Discord](https://discord.com/invite/jyEM2PRvMU) |
| 96 | +For issues related to this Actor, please contact the Actor developer. |
0 commit comments