OpenRouter Tutorial: Getting Started the Right Way
OpenRouter tutorial: create an API key, set a spending limit, and send your first request through one OpenAI-compatible endpoint that covers hundreds of models.
By Galactic News Editorial · Published 2026-11-10T16:22:44+00:00 · Updated 2026-11-10T16:22:44+00:00
OpenRouter Tutorial: Getting Started the Right Way
OpenRouter gives you access to hundreds of AI models through one API endpoint. One key, one base URL, and one balance cover models from OpenAI, Anthropic, Google, DeepSeek, xAI, and many smaller labs. This OpenRouter tutorial walks through setup the right way: create a key, set a spending limit, send a first request, and avoid the mistakes that drain a balance. It follows the official quickstart and documentation.
What OpenRouter is
OpenRouter is a unified API gateway for large language models. Instead of registering with each provider separately, you send all requests to one OpenAI-compatible endpoint. OpenRouter handles authentication, provider selection, failover, and billing. The base URL is https://openrouter.ai/api/v1. It supports both the /chat/completions and /responses endpoints. That means code already written against the OpenAI SDK needs only two lines changed: the base URL and the API key. OpenRouter passes provider prices through with no inference markup. It charges a platform fee of 5.5% on credit purchases, with a $0.80 minimum. Free models exist too. Model IDs ending in :free cost nothing, but they carry strict rate limits.
OpenRouter tutorial: setup in 6 steps
- Create an account. Go to openrouter.ai and sign in with Google, GitHub, or email. The account is free. No credit card is needed for free-tier models.
- Open the Keys page. Go to openrouter.ai/keys after signing in. Since April 2026, every key lives inside a workspace.
- Create a key. Click Create Key. Give it a name you will recognize later, such as the app it belongs to. Keys created during onboarding get a $100 credit limit and expire after 180 days.
- Set a credit limit. Give the key a spending limit when you create it. The limit can reset daily, weekly, or monthly at midnight UTC. Once a key has used its limit, requests are rejected until you raise it or it resets. This one step stops a runaway script from draining your balance.
- Copy the key immediately. The key starts with sk-or-v1- followed by 64 more characters. OpenRouter shows the full string only once. If you lose it, you cannot view it again. Create a new key and delete the old one.
- Store it safely. Put the key in an environment variable. Never commit it to Git. OpenRouter is a GitHub secret scanning partner and emails you if it determines a key was exposed.
Your first request
Send a minimal request to confirm the key works. Use curl or the OpenAI SDK. The endpoint is https://openrouter.ai/api/v1/chat/completions. Put the key in an Authorization header as a Bearer token. A working call returns JSON with choices[0].message.content holding the model's reply. With the OpenAI SDK in Python, the setup is short:
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="<OPENROUTER_API_KEY>",
)
completion = client.chat.completions.create(
model="openrouter/free",
messages=[{"role": "user", "content": "Say hello."}],
)Two optional headers, HTTP-Referer and X-Title, identify your app for OpenRouter's public rankings. Requests work without them. Business and Enterprise accounts that need EU in-region processing use https://eu.openrouter.ai/api/v1 instead. To check a key's own numbers, send a GET request to https://openrouter.ai/api/v1/key with the same header.
Free models and their limits
Free models are identified by the :free suffix on the model ID. You can filter them on openrouter.ai/models, or pull the list from the /api/v1/models endpoint. The limits are strict. Free models are capped at 20 requests per minute and 50 requests per day when your account has purchased less than $10 in credits. Once you have purchased $10 or more in credits, all time, the daily cap rises to 1,000 requests per day. That $10 threshold counts credits purchased all time, not your current balance. If your balance goes negative, even free models are blocked and you get a 402 error. The minimum credit purchase is $5. Paying by card adds the 5.5% fee, so a $5 top-up costs $5.80 at checkout. Unused credits expire 365 days after purchase.
How billing and model choice work
Paid models bill at provider list prices, passed through with no markup. Each model has its own per-token price, listed on the OpenRouter models page. Check the price of a model before you use it in production. A cheap model and an expensive model can differ by a large factor per million tokens. Model IDs use a provider/model format, such as openai/gpt-4o or anthropic/claude-sonnet-4. OpenRouter also offers automatic fallbacks. If one provider fails, the request can route to another provider for the same model. That is the main reason to use a gateway instead of calling each provider directly. For production use, set per-key limits, watch the usage dashboard, and pick a default model with a fallback. For experiments, start with a free model and move to a paid model only when you need its quality.
Mistakes to avoid
- No spending limit on the key. Always set one. An unlimited key in a loop can spend fast.
- Losing the key. It is shown once. Save it in a password manager or secrets vault before closing the dialog.
- Assuming free means unlimited. Free models stop at 50 requests a day until you have bought $10 in credits.
- Ignoring the negative balance rule. A negative balance blocks free models too, with a 402 error.
- Hard-coding a model ID. Models change. Check the catalog and pricing before a release, and set a fallback.
- Committing the key to Git. Use an environment variable. Rotate the key if it ever leaks.
Bottom line
OpenRouter is the fastest way to try many models behind one key. Create an account, make a key at openrouter.ai/keys, set a credit limit, and copy the key once. Point the OpenAI SDK at https://openrouter.ai/api/v1 and send a first request through a free model. Add $5 in credits when you need paid models, and keep the per-key limit in place. That is the whole setup. Everything after that is choosing models and watching spend.