OpenRouter: one API key for 300+ AI models (account, API, OpenCode, VSCode)

Contents
Introduction
Create an account
Create an API key
Try models on the website
Call models from code
Add OpenRouter to OpenCode
Add OpenRouter to VS Code
Keys, limits and privacy
Troubleshooting

Introduction

OpenRouter is a gateway to 300+ AI models behind one API key and one bill. Instead of registering with every provider, you register once, top up credits, and call any model through an OpenAI-compatible API: flagship commercial models, cheap fast models, open-weight models, and free models for experiments.

Two typical uses on this site: as a model source for the OpenCode coding agent (one OpenRouter key replaces a pocketful of provider keys), and as a cloud alternative to running Qwen locally when you need more quality than your hardware can serve.

Create an account

  1. Open openrouter.ai and sign up (Google or GitHub login works, email works too).
  2. Free models work with just the account — no payment needed to start.
  3. Paid models need topped-up credits: open the credits/billing page and add funds with a card. Usage is pay-as-you-go, billed per million tokens; exact prices sit next to every model on the models page and do change, so check them there, not in blog posts.

Create an API key

  1. Open openrouter.ai/settings/keys and create a key. It starts with sk-or- — copy it immediately, it is shown once.
  2. Put the key in an environment variable instead of pasting it into files:

export OPENROUTER_API_KEY="sk-or-your-key-here"

Treat the key like a password: never commit it to git, never paste it into chats or screenshots. If a key leaks, delete it on the keys page and create a new one.

Try models on the website

Before wiring anything, try a model in the browser:

  1. Open openrouter.ai/models: every model shows price per million tokens, context length, and whether a free variant exists (free variants end with :free).
  2. Open a model and use the chat view to ask a few questions from your own domain — this is the cheapest way to compare quality before spending credits in an agent loop.
  3. Copy the exact model id (format provider/model, for example openai/gpt-4o) — you will need it verbatim in code and configs below.

Call models from code

The API endpoint is https://openrouter.ai/api/v1 and speaks the OpenAI chat format. Minimal request with curl:

curl https://openrouter.ai/api/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer $OPENROUTER_API_KEY" -d '{"model": "openai/gpt-4o", "messages": [{"role": "user", "content": "Hi"}]}'

Same call from Python (needs openai package):

pip install openai

import os from openai import OpenAI client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"], ) answer = client.chat.completions.create( model="openai/gpt-4o", messages=[{"role": "user", "content": "Say hi"}], ) print(answer.choices[0].message.content)

Add OpenRouter to OpenCode

Full agent setup lives in OpenCode: download, install and use — here is only the OpenRouter part:

  1. Start OpenCode (opencode) and type /connect.
  2. Pick the OpenRouter provider and paste your key (the sk-or- one from above).
  3. Type /models to list the model ids available to you, then pin your default in opencode.json with the exact id from that list.

Add OpenRouter to VS Code

Any VS Code AI extension that accepts a custom provider works; three common ones:

models: - name: OpenRouter GPT-4o provider: openrouter model: openai/gpt-4o apiKey: YOUR_OPENROUTER_KEY

Prefer an environment variable over a hardcoded key where the extension supports it, and check the extension docs for the current field names.

Keys, limits and privacy

Troubleshooting

Official sources:

Article author: Andrei Olegovich

Related articles
AI
OpenRouter: one API key for 300+ AI models (account, API, OpenCode, VSCode)

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: