GuidesGetting started

OpenRouter API key: create, use and secure it

Create an OpenRouter API key, use it with curl, the OpenAI SDK, coding agents and OpenClaw, set credit limits, check usage and replace a key that leaked.

November 25, 2026The Everpod team
The short answer

Sign in at OpenRouter and create a key on the keys page: give it a name and a credit limit (or none). The key starts with sk-or-v1- and is 73 characters long. Send it as Authorization: Bearer <key> to the base URL https://openrouter.ai/api/v1; any OpenAI SDK works by setting its base URL to that address and its API key to the OpenRouter key. Keep it in an environment variable such as OPENROUTER_API_KEY, set a credit limit on it, and check it with GET /api/v1/key.

Creating the key

OpenRouter’s API keys guide sends you to openrouter.ai/keys to create one: “Give it a name and choose a credit limit (or no limit).” The same keys live under Settings, Keys, which is where you later raise a key’s limit or delete a leaked one. Copy the key into wherever it will live as soon as it appears.

Every OpenRouter API key, as of November 2026, is sk-or-v1- followed by 64 lowercase hexadecimal characters. A key that starts sk- but not sk-or-, such as an OpenAI or Anthropic key, is another company’s, and OpenRouter answers it with a 401 saying so. A key OpenRouter created for you during onboarding comes with a $100 credit limit and expires after 180 days, after which requests get “API key expired” and a new key is the fix.

Credit limits, resets and whether you need credits

A key’s credit limit is a cap in dollars on what that key can spend, separate from your account’s balance. OpenRouter recommends one on every key, because without it “a leaked key or a runaway agent” can spend the whole balance, auto top-ups included. A limit can be total, or reset daily, weekly or monthly; a periodic one resets at midnight UTC, weeks running Monday to Sunday. Once a key reaches a total limit, its requests are refused until you raise the limit on the key’s page. The 403 that results, and how it differs from the organisation budgets that look like it, is covered in “Key limit exceeded”.

A key works with no credit on the account, but only for the free models, the ones whose ID ends in :free. OpenRouter’s limits page caps them at 20 requests a minute and 50 a day, or 1,000 a day once the account has bought at least 10 credits in total, and a negative balance can stop even free models. Paid models need credit, and a request is checked against the most it could cost, which is why one can be refused with money still showing; the requires-more-credits guide has the arithmetic.

Using it: base URL, header, a first request

The base URL is https://openrouter.ai/api/v1, and the key goes in the Authorization header as a Bearer token, one space after Bearer, no quotes. With the key in an environment variable:

export OPENROUTER_API_KEY="sk-or-v1-..."   # or load it from a file only you can read

curl https://openrouter.ai/api/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -d '{"model": "~openai/gpt-sol-latest", "input": "Say hello."}'
Copied

That is the Responses endpoint the quickstart uses; ~openai/gpt-sol-latest is OpenRouter’s alias for the newest model in that family, and any model ID from the models list goes in its place (how IDs, suffixes and routers work: OpenRouter models). Tools written for OpenAI’s older API use POST /api/v1/chat/completions, which OpenRouter also serves on the OpenAI Chat API’s schema.

In an OpenAI SDK, the two settings are the base URL and the key, as on OpenRouter’s authentication page, here with the key read from the environment:

from openai import OpenAI
import os

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

In TypeScript the options are baseURL and apiKey. Passing the key explicitly matters: an SDK left to find a key by itself reads OPENAI_API_KEY, sends OpenAI’s key to OpenRouter, and gets the 401 described in OpenRouter’s 401 errors. Two optional headers, HTTP-Referer with your site’s URL and X-OpenRouter-Title with its name, only list your app in OpenRouter’s public rankings.

Giving it to an agent

Claude Code, Codex and OpenCode each take the key their own way: Claude Code through ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN, Codex through a provider block in ~/.codex/config.toml, OpenCode through /connect. The exact settings and what each maker does not support are in OpenRouter with Codex, OpenCode and Claude Code.

OpenClaw has OpenRouter built in. Its provider page reads the key from OPENROUTER_API_KEY and sets it up during onboarding, where the default model is openrouter/auto:

openclaw onboard --auth-choice openrouter-api-key

# on an install that is already set up
openclaw models auth login --provider openrouter --method api-key
Copied

Models are then named openrouter/<provider>/<model>. Whatever the agent, on a server the variable has to reach the agent’s own process: a key exported in your shell is not seen by a service or a cron job.

Checking a key’s usage and limit

GET /api/v1/key reports on the key that calls it, without printing the key:

curl https://openrouter.ai/api/v1/key \
  -H "Authorization: Bearer $OPENROUTER_API_KEY"
Copied

Among the fields in its data: label, the key’s name; limit, limit_remaining and limit_reset; usage in dollars, with usage_daily, usage_weekly and usage_monthly for the current UTC periods; expires_at, null for a key with no expiry; is_free_tier; and free_model_daily_requests, how many of today’s free model requests are used and left. A 401 from this call means the key itself is wrong. If you bring your own provider keys to OpenRouter (BYOK), that spend is reported separately as byok_usage, and include_byok_in_limit says whether it counts against the key’s limit.

To check what a program will send without printing the secret, echo "${OPENROUTER_API_KEY:0:9}" should show sk-or-v1- and echo -n "$OPENROUTER_API_KEY" | wc -c should show 73. A key pasted with an invisible character in it gets “Malformed authentication credential”; copy it again.

Keeping it safe, and a leaked key

OpenRouter’s advice is environment variables, with keys kept out of your codebase. An .env file holding one belongs in .gitignore and readable by you alone (chmod 600 .env); a key written into a config file is a key in that file, so the same applies to the file. Use one key per agent or machine, each with its own credit limit, so one leak or one runaway loop is capped and can be cut off without breaking the rest.

OpenRouter is a GitHub secret scanning partner and has other ways of detecting exposed keys, and it emails you if it determines that a key has been compromised. Whether that email arrives or not, a key that may have been exposed is replaced: create a new key, put it where the old one was, restart whatever reads it, then delete the old key on the key settings page. Removing it from the repository is not enough, since the history and any clone still hold it. Once deleted, the old key gets a 401 “User not found.” or “Invalid API key”. Which data routing settings a key’s requests follow is a separate matter, covered in OpenRouter’s privacy settings.

Management keys

A management key (the API’s older field for it says provisioning) is for creating and administering keys from code, not for calling models: “Management keys cannot be used to make API calls to OpenRouter’s completion endpoints.” An organisation admin creates one on openrouter.ai/settings/management-keys, or a workspace admin under the workspace’s Keys, as read/write, read-only or custom; its expiry is fixed when it is created. With it, GET and POST /api/v1/keys list and create keys, and GET, PATCH and DELETE /api/v1/keys/{hash} read, change and remove one, which is how a script gives each agent its own capped key and rotates it.

Run Claude Code, Codex, OpenCode, Pi, Hermes or OpenClaw on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.