Back to Codexbar

OpenRouter Provider

docs/openrouter.md

0.45.02.5 KB
Original Source

OpenRouter Provider

OpenRouter is a unified API that provides access to multiple AI models from different providers (OpenAI, Anthropic, Google, Meta, and more) through a single endpoint.

Authentication

OpenRouter uses API key authentication. Get your API key from OpenRouter Settings.

Environment Variable

Set the OPENROUTER_API_KEY environment variable:

bash
export OPENROUTER_API_KEY="sk-or-v1-..."

Settings

You can also configure the API key in CodexBar Settings → Providers → OpenRouter.

CLI config

To monitor multiple OpenRouter accounts, add labeled API keys in the same provider settings. CodexBar fetches each key independently. Choose the segmented account switcher or stacked account cards under Settings → Display.

bash
printf '%s' "$OPENROUTER_API_KEY" | codexbar config set-api-key --provider openrouter --stdin

Data Source

The OpenRouter provider fetches usage data from two API endpoints:

  1. Credits API (/api/v1/credits): Returns total credits purchased and total usage. The balance is calculated as total_credits - total_usage.

  2. Key API (/api/v1/key): Returns rate limit information plus current daily, weekly, and monthly spend for your API key.

Display

The OpenRouter menu card shows:

  • Primary meter: API key limit usage when the key has a configured limit
  • Spend notes: Daily, weekly, and monthly API key spend when OpenRouter returns those fields
  • Spend chart: Day/week/month spend can reuse the shared inline dashboard when enough history is available
  • Balance: Displayed in the identity section as "Balance: $X.XX"

CLI Usage

bash
codexbar --provider openrouter
codexbar -p or  # alias
codexbar --provider openrouter --account Personal
codexbar --provider openrouter --all-accounts --format json --pretty

Environment Variables

VariableDescription
OPENROUTER_API_KEYYour OpenRouter API key (required)
OPENROUTER_API_URLOverride the base API URL (optional, defaults to https://openrouter.ai/api/v1)
OPENROUTER_HTTP_REFEREROptional client referer sent as HTTP-Referer header
OPENROUTER_X_TITLEOptional client title sent as X-Title header (defaults to CodexBar)

Notes

  • Credit values are cached on OpenRouter's side and may be up to 60 seconds stale
  • OpenRouter uses a credit-based billing system where you pre-purchase credits
  • Rate limits depend on your credit balance (10+ credits = 1000 free model requests/day)