├── .env ├── package.json ├── example-0.js ├── example-1.js └── README.md /.env: -------------------------------------------------------------------------------- 1 | # Get your API Key from: https://openrouter.ai/keys 2 | OPENROUTER_API_KEY=Your_API_Key 3 | YOUR_SITE_URL=http://localhost:3000 4 | YOUR_SITE_NAME=Example 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "openrouter", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "dotenv": "^16.3.1" 14 | }, 15 | "type": "module" 16 | } 17 | -------------------------------------------------------------------------------- /example-0.js: -------------------------------------------------------------------------------- 1 | import dotenv from "dotenv"; 2 | dotenv.config(); 3 | const model = "anthropic/claude-2"; 4 | let res = await fetch("https://openrouter.ai/api/v1/chat/completions", { 5 | method: "POST", 6 | headers: { 7 | Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`, 8 | "HTTP-Referer": process.env.YOUR_SITE_URL, 9 | "X-Title": process.env.YOUR_SITE_NAME, 10 | }, 11 | body: JSON.stringify({ 12 | model, 13 | messages: [ 14 | { role: "system", content: "You are a helpful assistant." }, 15 | { role: "user", content: "Hello what model are you?" }, 16 | ], 17 | }), 18 | }); 19 | let results = JSON.stringify(await res.json()); 20 | console.log(results); -------------------------------------------------------------------------------- /example-1.js: -------------------------------------------------------------------------------- 1 | import dotenv from "dotenv"; 2 | import fs from "fs"; 3 | dotenv.config(); 4 | 5 | const models = [ 6 | "google/palm-2-codechat-bison", 7 | "google/palm-2-chat-bison", 8 | "openai/gpt-3.5-turbo", 9 | "openai/gpt-3.5-turbo-16k", 10 | "openai/gpt-4", 11 | "openai/gpt-4-32k", 12 | "anthropic/claude-2", 13 | "anthropic/claude-instant-v1", 14 | "meta-llama/llama-2-13b-chat", 15 | "meta-llama/llama-2-70b-chat", 16 | ]; 17 | let results = {}; 18 | 19 | (async function () { 20 | for (const model of models) { 21 | let res = await fetch("https://openrouter.ai/api/v1/chat/completions", { 22 | method: "POST", 23 | headers: { 24 | Authorization: `Bearer ${process.env.OPENROUTER_API_KEY}`, 25 | "HTTP-Referer": process.env.YOUR_SITE_URL, 26 | "X-Title": process.env.YOUR_SITE_NAME, 27 | }, 28 | body: JSON.stringify({ 29 | model, 30 | messages: [ 31 | { role: "system", content: "You are a helpful assistant." }, 32 | { role: "user", content: "Hello world" }, 33 | ], 34 | }), 35 | }); 36 | results[model] = { 37 | timestamp: new Date().toISOString(), 38 | response: await res.json(), 39 | }; 40 | console.log(results[model]); 41 | } 42 | fs.writeFileSync( 43 | `responses-${new Date().toISOString()}.json`, 44 | JSON.stringify(results, null, 2) 45 | ); 46 | })(); 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unlock GPT-4-32K & Claude-2-100K API Instantly With Open Router 2 | 3 | This is from my YouTube Video [Unlock GPT-4-32K & Claude-2-100K APIs Instantly!](https://youtu.be/93QLqpfcqjA) 4 | 5 | Getting Started with Rare Models like GPT-4-32k and Claude-2-100k using OpenRouter AI and Node.js 6 | 7 | This README will guide you on how to interact with rare AI models such as GPT-4-32k and Claude-2-100k using the OpenRouter AI API in a Node.js application. Follow the steps below to create chat completions with these powerful language models. 8 | 9 | ## Prerequisites 10 | 11 | Ensure you have Node.js installed on your system. If not, download and install it from [official Node.js website](https://nodejs.org/). 12 | 13 | You also need an OpenRouter AI API key. Refer to the [OpenRouter AI Keys](https://openrouter.ai/keys) to generate your API key. 14 | 15 | ## Getting Started 16 | 17 | 1. Clone this repository to your local machine. 18 | 19 | 2. Install the required packages using npm. Run the following command in the root directory of your project: 20 | 21 | ```bash 22 | npm install 23 | ``` 24 | 25 | 3. Create a .env file in your project root directory and add the following lines: 26 | 27 | ```bash 28 | OPENROUTER_API_KEY=your_openrouter_ai_key 29 | YOUR_SITE_URL=your_site_url 30 | YOUR_SITE_NAME=your_site_name 31 | ``` 32 | 33 | Replace `your_openrouter_ai_key`, `your_site_url`, and `your_site_name` with your actual OpenRouter AI key, your site's URL, and your site's name respectively. 34 | 35 | 4. Run the example scripts: 36 | 37 | - For running a single model (example-0.js): 38 | 39 | ```bash 40 | node example-0.js 41 | ``` 42 | 43 | - For running multiple models including the rare models and saving responses (results-1.js): 44 | 45 | ```bash 46 | node results-1.js 47 | ``` 48 | 49 | The results will be saved in a JSON file named `responses-timestamp.json` in the project root directory. 50 | 51 | That's it! You've successfully set up and interacted with rare models like GPT-4-32k and Claude-2-100k using OpenRouter AI and Node.js. Happy coding! 52 | --------------------------------------------------------------------------------