Ravindra BagaleCourses & study guides Track your progress

Guides · Generative AI

OpenRouter: One API Key for Many AI Models (Beginner)

OpenRouter is a router that lets you call many AI models with one API key. You pay for what you use (credits). As of 23 October 2026, sign-up and credit top-ups are managed on openrouter.ai — model prices are listed per million tokens and change often. There is no single "₹999/month Pro" to invent. Start with a small credit top-up, never paste the key into public GitHub, and prefer cheap models while learning.

Suppose you want to try Claude, GPT and Gemini from one place without three separate dashboards. You create an OpenRouter key, add a little credit, and call one model from a tiny Python script. This guide is that first safe path for beginners in India.

Full course chapter

For Claude Code install, see Claude Code for Beginners. For Cursor pricing, see Cursor AI Free Plan. This page is OpenRouter API basics.

What you will learn in this guide

  • What OpenRouter is
  • Credits vs "monthly Pro" myth
  • Create a key safely
  • First Python chat call
  • Switch models with one key
  • Cost and safety checklist

1. Suppose Kavya wants one key for class demos

Suppose Kavya teaches a weekend coding club. She does not want five API dashboards. She creates one OpenRouter key, stores it in a local .env (never committed), and shows students how to change the model name only.

2. What is OpenRouter?

Word Simple meaning
OpenRouter API gateway to many models
API key Secret string that proves it is you
Tokens Pieces of text the model reads/writes (billing unit)
Credits Money balance you top up
Model ID String like a provider/model name you put in the request
OpenRouter beginner path in five steps Steps from top to bottom: 1 Create an account, OpenRouter web signup; 2 Add a small credit, Only what you can lose learning; 3 Create an API key, Store it in a local env file; 4 Call one cheap model, Tiny Python chat script; 5 Switch model IDs, Same key different models. 1Create an accountOpenRouter web signup 2Add a small creditOnly what you can lose learning 3Create an API keyStore it in a local env file 4Call one cheap modelTiny Python chat script 5Switch model IDsSame key different models

Figure 1. OpenRouter beginner path in five steps: create an account, add a small credit, create an API key, call one cheap model from a script, then switch model IDs without new keys.

3. Pricing habit (checked 23 October 2026)

  1. Open openrouter.ai → Models / Pricing.
  2. Pick a cheap model for learning (look at $ per million tokens).
  3. Top up a small credit amount first.
  4. Do not invent a flat "India student plan" if the site does not show one.
  5. Re-check prices the day you run a big batch job — rates move.

4. Worked example 1: create a key (safe)

  1. Sign up on openrouter.ai.
  2. Add a small credit top-up (only what you can lose while learning).
  3. Create an API key. Copy it once.
  4. On your laptop, create .env (never commit):
OPENROUTER_API_KEY=sk-or-v1-REPLACE_ME
  1. Add .env to .gitignore.

Expected output: a key that works only on your machine, not in a public repo.

Ravindra Bagale's Tip

Students paste keys into WhatsApp "for backup". That is how credits vanish. Treat the key like a UPI PIN.

5. Worked example 2: first Python chat call

Install once: pip install openai (OpenRouter is often used with the OpenAI-compatible client).

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
)

resp = client.chat.completions.create(
    model="openai/gpt-4o-mini",  # change if this ID is renamed — check Models page
    messages=[
        {"role": "user", "content": "Explain UPI in two short sentences for a beginner."}
    ],
)
print(resp.choices[0].message.content)
  1. Export the key in your shell or use a dotenv loader.
  2. Run the script once.
  3. If the model ID fails, open the Models page and paste a current cheap ID.

Expected output: a short UPI explanation. Cost should be tiny for one call.

6. Worked example 3: switch models with the same key

  1. Keep the same client and key.
  2. Change only model= to another listed ID (example pattern: google/gemini-... or anthropic/claude-... — use live IDs from the Models page).
  3. Ask the same question twice and compare answers.
  4. Note which model cost more in the OpenRouter activity/usage screen.
  5. For class demos, prefer the cheaper model that still answers clearly.

Expected output: two answers from two models, one key, visible usage.

7. Cost and safety checklist

OPENROUTER CHECKLIST
[ ] Small credit only while learning
[ ] Key in .env — not in GitHub
[ ] Model ID copied from live Models page
[ ] No customer PII in prompts
[ ] Stop if usage looks wrong
[ ] Rotate/delete key if it leaks

8. Beginner mistakes and quick fixes

Mistake What happens Quick fix
Key in public repo Credits stolen Rotate key now
Expensive model for hello-world Bill shock Cheap model first
Invented flat monthly fee Wrong budget Pay-as-you-go credits
Huge loops in scripts Burned balance Cap max tokens / retries
Sharing one key with 20 friends Abuse One person, one key

9. Try at home

Try at home

  1. Create a key and store it in .env.
  2. Run example 2 once with a cheap model.
  3. Switch model IDs once and compare cost in the dashboard.

Recap

In short

  1. OpenRouter = one key, many models.
  2. You pay credits; check live model prices.
  3. Keep the key secret.
  4. Start with one cheap chat call.
  5. Switch model IDs without new keys.

Small credit, secret key, cheap model, then compare. That is OpenRouter for beginners.

Frequently asked questions

Is OpenRouter free?

You typically need credits for model calls. Any free allowance changes — check your account dashboard.

Is it legal for students in India?

Using the API for learning is common. Follow college rules for graded work and never put secrets in prompts.

Do I need a US card?

Payment methods depend on OpenRouter's checkout. If a method fails, use whatever options the site shows that day — do not use shady "virtual card" sites.

Can I use OpenRouter inside Cursor?

Some workflows allow custom providers. Prefer Cursor's built-in plans for day-one coding unless you already know APIs.