Zilmac 블로그
← 기술 실천으로

OpenRouter API 튜토리얼 2026: 가입, 충전, API Key, 모델 선택과 GPT/Claude/Gemini 호출

API & Agent ·약 12분

OpenRouter 멀티모델 API 게이트웨이와 GPT Claude Gemini 라우팅

OpenRouter routes OpenAI, Anthropic, Google, and more through a single OpenAI-compatible API: change base_url and model to switch between GPT, Claude, and Gemini without opening separate vendor accounts. This 2026 walkthrough covers openrouter.ai signup, adding credits, creating an API key, picking models in the catalog, and your first calls with curl and Python. For per-token rates and monthly math, see OpenRouter pricing comparison; for Claude Code subscriptions, see Claude Code 2026 costs.

1
API base: https://openrouter.ai/api/v1
300+
Routable models (GPT / Claude / Gemini and more)
Prepaid
Pay per token; top-up fees may apply

Who OpenRouter is for vs. direct vendor APIs

OpenRouter is a hosted aggregator: you prepay credits; requests are routed to providers and billed at the listed input/output token rates. Good fit when you want:

  • One key, many models (e.g. cheap Gemini Flash by day, Claude Sonnet for coding at night)
  • One billing path when separate OpenAI / Anthropic / Google accounts are awkward
  • Agents or scripts already built on the openai SDK—only the endpoint changes

Poor fit when data must not pass a third-party proxy, or you have enterprise discounts with a single vendor—use direct APIs or a self-hosted gateway instead.

OpenRouter vs. Claude Pro only?

Claude Code Pro/Max is flat monthly + usage pools—great for daily terminal coding. OpenRouter is pure usage—better for scripts, multi-model routing, or spiky experiments. Stack both if needed. See real monthly AI programming costs.

Sign up and sign in

  1. Go to openrouter.ai and click Sign in.
  2. Use Google, GitHub, or email; teams should use a company email and enable 2FA under Account → Security.
  3. After login, the Dashboard shows Credits, Keys, and Activity.

Signup is free; some free models may work with zero balance, but production should assume paid models need credits.

Credits, balance, and usage

Use Settings → Credits or Add Credits on the dashboard. Payment methods depend on what the console offers at checkout.

  • Prepaid: requests fail when balance is empty—no post-paid invoice.
  • Top-up fees: some payment rails add ~5.5%—factor that into effective $/M tokens; see our pricing article.
  • Activity: filter by key, model, and time to debug spend.
Developer reviewing OpenRouter API usage dashboard and multi-model token billing
Before scaling Agent concurrency, check Credits and Activity so weekend jobs do not drain the balance

Create and manage API keys

  1. Keys → Create Key.
  2. Name keys (cursor-dev, ci-nightly) for Activity attribution.
  3. Set limits or expiry for CI or intern keys when the UI allows it.
  4. Store the secret in a password manager—never commit to Git.
Authorization: Bearer <OPENROUTER_API_KEY>

Recommended optional headers:

HTTP-Referer: https://your-app.example
X-Title: Your App Name

Pick GPT, Claude, and Gemini in the catalog

Open Models and use slash IDs in model:

FamilyExample model ID (2026 catalog)Notes
Claudeanthropic/claude-sonnet-4.5Balanced coding; verify latest ID in catalog
GPTopenai/gpt-5 or openai/gpt-5-miniFlagship vs. cost-saving mini
Geminigoogle/gemini-2.5-pro, google/gemini-2.5-flashFlash for throughput

First call: curl and Python

POST https://openrouter.ai/api/v1/chat/completions

Call Claude

curl https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"anthropic/claude-sonnet-4.5","messages":[{"role":"user","content":"Explain OpenRouter in three sentences"}]}'

Call GPT

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

Call Gemini

curl https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"google/gemini-2.5-flash","messages":[{"role":"user","content":"One pro of REST vs GraphQL"}]}'

Python with the OpenAI SDK:

from openai import OpenAI
import os

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
)
resp = client.chat.completions.create(
    model="anthropic/claude-sonnet-4.5",
    messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)

Wire up Cursor, Claude Code, and other clients

  • Cursor / Cline: set OpenAI-compatible base URL to https://openrouter.ai/api/v1, key = OpenRouter key, model = slash ID.
  • Claude Code: defaults to Anthropic subscription; custom OpenRouter endpoints change often—check CLI docs. Many teams use Claude Code for daily work, OpenRouter for scripts.
  • CI / cloud Mac: inject OPENROUTER_API_KEY via secrets, not the repo.

FAQ

Does an OpenRouter key replace an OpenAI key?

In compatible clients, yes—point base URL to OpenRouter. Billing and model list follow OpenRouter, not the OpenAI dashboard.

Streaming?

Set "stream": true and consume SSE like OpenAI.

Cost control?

Per-environment keys, limits, default to Flash/mini, upgrade only after eval—see pricing.

Same as Anthropic /v1/messages?

Primary path is /v1/chat/completions; check OpenRouter docs if you need Messages-native clients.

한정 혜택

Zilmac

클라우드 Mac, 원격 개발, Mac VPS로 Apple 툴체인을 보완합니다.

홈으로
한정 혜택 플랜 보기