跳到正文
openrouter blog(openrouter.ai)·· 20 小時前精選AI 評分77

Claude Code 使用限制?如何繼續編碼

Hit Your Claude Code Usage Limit? How to Keep Coding

AI 導讀

在 Claude Code 遇到使用限制時,可透過 OpenRouter API 金鑰繼續編碼,並可自行設定成本與模型。

  • 成本:Sonnet 5.5 兩到九訊息會話平均 $0.155,Opus 5.5 $0.305,Haiku 5.5 $0.007。
推薦理由

本教學說明如何在 Claude Code 觸發使用限制時,透過 OpenRouter API 金鑰繼續編碼,並提供成本與設定細節,協助使用者在限制內持續開發。

正文 · 原文

When you hit your Claude Code usage limit, you can keep coding by running Claude Code on an OpenRouter API key. Through OpenRouter, Claude Code runs on a pay-per-token API key with the same Claude models and no five-hour window. You set three environment variables, and you switch back to your plan when it resets.

We tested this setup with Claude Code. The outputs and costs below come from those runs.

Tl;dr

  • Your Claude plan has a five-hour limit and a weekly limit. An OpenRouter API key has neither. You pay for the tokens you use instead.
  • The quickest setup is Ori Harness: ori claude starts Claude Code on OpenRouter for that session, with a browser sign-in and no key to paste.
  • To do it by hand, three environment variables point Claude Code at OpenRouter. We put them in a shell function called claude-or, so claude still uses your plan.
  • Start with Claude Sonnet 5.5. A typical short Claude Code session costs $0.16 on Sonnet 5.5, $0.31 on Opus 5.5, and less than one cent on Haiku 5.5.
  • Don’t trust the cost Claude Code prints. In our test, it showed $0.375 for a run we were billed $0.008 for. Check your key or the Activity page instead.
  • When your plan resets, type claude again. There is nothing to undo.

Why does Claude Code hit a usage limit?

Claude plans have two limits that run at the same time. The first resets five hours after your first prompt. The second resets every seven days. Anthropic does not publish an exact number of prompts for either one. Claude Code uses many more tokens than a normal chat, so you can run out in the middle of a task. When that happens, Claude Code stops and tells you when your limit resets. Anthropic’s help article on usage limits explains both limits.

An OpenRouter API key does not work this way. You pay for each token you use, and you can keep going as long as you have credit.

The quickest way: run Claude Code through Ori Harness

Ori Harness starts the Claude Code already on your machine with OpenRouter settings in place. Install it and start Claude Code through it:

curl -fsSL https://openrouter.ai/labs/ori/install.sh | bash
ori claude --model anthropic/claude-sonnet-5.5

Ori opens a browser so you can sign in with your OpenRouter account. It uses OAuth, so there is no key to create or paste. Only sessions you start with ori claude run on OpenRouter, so plain claude keeps using your plan, and you switch back by typing claude when your plan resets. The usage goes on your OpenRouter bill. If you are in an organization, a guardrail with a budget limit on your account caps what it can spend, and OpenRouter applies it to Ori sessions too.

The steps below do the same thing by hand, with an API key and a shell function. Use them if you want a key with its own credit limit, which works on any account. The cost advice in Step 4 applies either way.

Step 1: Get an OpenRouter API key and set a limit

Create a key on the API keys page and give it a credit limit. We set ours to $4. That way, even a long session cannot spend more than $4. A credit limit is one of several ways to control spending on OpenRouter. Our guide to governing AI spend across a team covers the others.

To check the limit, ask our API about your key:

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

This is the part of the response that matters:

{
  "data": {
    "limit": 4,
    "limit_remaining": 4,
    "usage": 0
  }
}

The limit_remaining number tells you how much money is left on the key. You can run this check at any time. After a request, it can take a few seconds for the new total to show.

Step 2: Add a command that switches to your key

You could add the variables to your shell profile, but then every Claude Code session would charge your key. We want your normal claude command to keep using your plan, so we put the variables in a small shell function instead. Add this to ~/.zshrc or ~/.bashrc:

claude-or() {
  ANTHROPIC_BASE_URL="https://openrouter.ai/api" \
  ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" \
  ANTHROPIC_API_KEY="" \
  ANTHROPIC_DEFAULT_SONNET_MODEL="anthropic/claude-sonnet-5.5" \
  ANTHROPIC_DEFAULT_OPUS_MODEL="anthropic/claude-opus-5.5" \
  ANTHROPIC_DEFAULT_HAIKU_MODEL="anthropic/claude-haiku-5.5" \
  CLAUDE_CODE_SUBAGENT_MODEL="anthropic/claude-haiku-5.5" \
  claude "$@"
}

The first three lines are the ones that matter:

  • ANTHROPIC_BASE_URL tells Claude Code to send its requests to us.
  • ANTHROPIC_AUTH_TOKEN holds your OpenRouter key.
  • ANTHROPIC_API_KEY must be empty. If it is not, Claude Code may try to sign in to Anthropic instead.

The other four lines are optional. They tell Claude Code which Claude model to use for Sonnet, Opus, and Haiku. They also send sub-agents, the smaller helper tasks Claude Code starts on its own, to Haiku 5.5.

These variables only apply when you type claude-or. Save the file and open a new terminal so the function is ready.

Diagram: typing claude in your terminal uses your Claude plan, with its five-hour and weekly limits. Typing claude-or sends the same session to OpenRouter on your API key, pay per token with no usage window, and OpenRouter serves the same Claude models from Anthropic, Amazon Bedrock and Google Vertex.

Step 3: Check that Claude Code is using your key

Before you start real work, check that Claude Code is sending its requests to OpenRouter and not to your plan. The quickest way is to send one short prompt and look at which model answered. Run this in your terminal:

claude-or --model sonnet -p "Reply with exactly: ok" --output-format json

This is the part of our response that matters:

{
  "is_error": false,
  "result": "ok"
}

The reply came back with no error. The modelUsage field in the full output names the model that answered, and in our run it was anthropic/claude-sonnet-5.5. We ran the same prompt with --model haiku, and modelUsage named anthropic/claude-haiku-5.5.

Then run the key check from Step 1 again. If usage has gone up, the requests were billed to your key and not to the plan. If it hasn’t, Claude Code did not pick up the variables. Open a new terminal and try again.

Step 4: Keep the cost down

On a key, you pay for every message. The table shows our prices for the three Claude 5.5 models. It also shows the median cost of a real Claude Code session of two to nine messages on OpenRouter.

ModelPrice per 1M input tokensPrice per 1M output tokensMedian session cost (2 to 9 messages)
Claude Opus 5.5$4.00$20.00$0.305
Claude Sonnet 5.5$2.00$10.00$0.155
Claude Haiku 5.5$0.10$0.50$0.007

Prices as of October 21, 2026. Session costs come from our session-cost dataset and cover the 30 days to October 18, 2026.

Start with Sonnet 5.5. It costs about half as much per session as Opus 5.5 and handles most everyday coding. When a problem is hard, type /model opus to switch, and switch back when you are done. If you build your own app on our API, you can also move a request to a stronger model automatically when the cheaper model is not confident in its answer.

Every new session starts with about 28,000 tokens of Claude Code’s own instructions and tool list (28,156 in our run on Claude Code 2.1.307, and the number changes between versions). They are written to the prompt cache on the first request, so a one-word prompt in Step 3 costs about $0.07 on Sonnet 5.5 and less than half a cent on Haiku 5.5.

Sub-agents are cheap on Haiku. When we asked Sonnet 5.5 to start a sub-agent, the main agent ran on Sonnet 5.5, and the sub-agent ran on Haiku 5.5, as the function sets.

Haiku can also handle small fixes on its own. We gave Haiku 5.5 a shopping-cart file with two bugs and three failing tests. It fixed both bugs, all three tests passed, and we were billed $0.008 for the run.

Don’t rely on the cost Claude Code prints. For that Haiku run, Claude Code reported $0.375, but we were billed $0.008. Claude Code prices the session with Anthropic’s own price table, and it guesses when it doesn’t recognize an OpenRouter model name. To see what you are really spending, check limit_remaining with the Step 1 command, or open your Activity page.

Step 5: Switch back when your plan resets

When your plan’s limit resets, type claude instead of claude-or. You do not need to change anything, because the OpenRouter settings only live inside the function. In our test, plain claude answered on the plan’s model, and the usage on our OpenRouter key did not change.

What happens if the API key runs out?

When your key reaches its credit limit, or your account runs out of credit, we stop the request before it reaches the model and return an error. The error includes a limit_source field that tells you why:

  • openrouter_key_limit means the key has used up its limit.
  • openrouter_credits means your account is out of credit.

To keep going, raise the key’s limit on the API keys page or add credit to your account. Our limits page explains every kind of limit, including ones a team admin can set.

Frequently asked questions

Does OpenRouter have usage limits for Claude Code?

There are no five-hour or weekly limits. The only limits are on spending: how much credit you have, the limit you set on your key, and any budget your team admin has set.

Are the models the same as on my Claude plan?

Yes. They are Anthropic’s Claude models. We get them from Anthropic and from cloud providers like Amazon Bedrock and Google Vertex, and if one provider has a problem, we send your request to another. For Claude Code, we recommend setting Anthropic as your first choice of provider, because Claude Code is only guaranteed to work with Anthropic.

Can I use a cheaper model when I hit the limit?

Yes. Sonnet 5.5 costs about half as much per session as Opus 5.5, and Haiku 5.5 costs less than a cent per session. You can also put a different model in one of the variables in the function. Many people use other models in Claude Code through OpenRouter. This month, GLM 5.3 Flash is the second most used model in Claude Code on our apps page, after Claude Opus 5.5. Claude Code is built for Claude models, though, so try any other model on a small task first. If you call our API from your own code, you can also list fallback models so a request moves to a second model when the first one fails. For more ways to lower what you pay per request, see our guide to the lowest-cost LLM inference on OpenRouter.

When does the Claude Code usage limit reset?

The five-hour limit resets five hours after the first prompt in that window. The weekly limit resets seven days after it starts. Claude Code shows the reset time when it stops you, so you know when to type claude again.

How do I check how much usage I have left?

On your Claude plan, Claude Code tells you when your limit resets when it stops you. On OpenRouter, check limit_remaining with GET /api/v1/key, or open your Activity page.

Next steps

Our Claude Code setup guide has the full setup, including a status line that shows your cost as you work. If you want to use OpenRouter with Claude Code every day, not only when you hit a limit, our Claude Code tutorial walks you through it. To run it on OpenRouter without managing a key, Ori Harness starts Claude Code, or another agent CLI, with one command. If you are setting this up for a team, workspace budgets let you limit how much each team can spend.

來源: openrouter blog (openrouter.ai)
開啟原文