Claude API Key: How to Get, Configure, and Use It
Set up a Claude API key on OurToken. Copy the exact Messages API endpoint, model ID, and Bearer auth, then test with cURL and Python.

A Claude API key authenticates every request to Claude models on OurToken, from the Claude 5 generation (Sonnet 5 and Opus 5) back to Opus 4.8, Opus 4.7, and Sonnet 4.6. One key works across all of them through a shared Messages API endpoint. The only thing that changes between models is the model ID.
This guide covers the full lifecycle: how to get a Claude API key, the exact endpoint and model IDs to configure, how a request is routed, a cURL smoke test, a Python client, token-by-token pricing across five models, a realistic monthly cost scenario, and the most common "key works but request fails" fixes. Each model generation also has its own setup article, linked in the sections below.
The current route shared by every Claude model on OurToken is:
Base URL: https://api.ourtoken.ai/v1
Full URL: https://api.ourtoken.ai/v1/messages
Model ID: varies by model (see table below)
Auth header: Authorization: Bearer YOUR_API_KEY
The configuration follows the current Claude Sonnet 5 model page, and the request and response shapes follow the public Anthropic Messages API reference.
Verification status: The route, model IDs, prices, and request shape were checked against current OurToken model pages and published blog posts on 2026-09-11. The examples are documentation-verified and require your own OurToken API key for live execution. Confirm current prices on the live model page before budgeting production traffic.
How to Get a Claude API Key
There are two ways to obtain a Claude API key:
- OurToken (recommended for multi-model access) — a single key works with Claude models from every generation at 40% of the official comparison price, through a unified Messages API endpoint.
- Anthropic Console — creates a native
x-api-keycredential limited to Anthropic-hosted routes at official rates.
The OurToken route starts on the API Keys page. The protected page may direct to login before key management is available. Once you create a key, store it in a server-side environment variable. One key authorises every Claude model on the platform.
Store the key as an environment variable
macOS / Linux
export OURTOKEN_API_KEY="paste-your-key-locally"
Windows PowerShell
$env:OURTOKEN_API_KEY = "paste-your-key-locally"
Do not paste the key into frontend JavaScript, a public repository, a shared notebook, or a bug report. Treat it like a production password: server-side storage, scoped access, and rotation on suspicion of exposure.
How a Claude API Request Is Routed
A Claude API key looks like a single credential, but every request crosses four stages between your application and the model output:
Your app / SDK / CI job
|
| POST /v1/messages Authorization: Bearer <key>
v
OurToken endpoint -> authenticates the key
-> applies quota, routing, and logging
v
Claude model route -> claude-sonnet-5 | claude-opus-5 | claude-opus-4-8 | ...
v
Response -> content[].text + usage { input_tokens, output_tokens,
cache_read_input_tokens }
Each stage has one job:
- Client — sends the full
/v1/messagesURL with the Bearer header. Raw HTTP,httpx, or any client that lets you set a base URL and an auth header works the same way. - Endpoint — authenticates the key, then applies account-level rules (quota, rate limits, logging) before the model sees the request.
- Model route — the
modelfield selects the generation. The key does not change; the route does. - Response — text arrives as typed
contentblocks, and theusageobject carries token counts for cost tracking.
The practical consequence: routing, retries, and budget controls live in one
place in your codebase. A fallback from Sonnet 5 to Opus 5, or a retry of the
same body against another Claude model, is a one-line change to the model
field rather than a second provider integration. Cached system prompts follow
the same path and are billed at the cache-read rate covered in the pricing
section.
Claude API Key Endpoint and Configuration
The OurToken Claude route uses the Anthropic Messages API shape---the
/messages path, a messages array, a top-level system field, and typed
content blocks in the response. It authenticates with Authorization: Bearer, the same header used by every other OurToken route. The native
Anthropic headers (x-api-key, anthropic-version) belong to
Anthropic-hosted routes and are not part of the configuration shown here.
Exact values to copy
| Setting | OurToken value | What it controls |
|---|---|---|
| API key source | OurToken API Keys | Creates the Bearer credential |
| SDK base URL | https://api.ourtoken.ai/v1 | Root URL for an HTTP client |
| Full endpoint | https://api.ourtoken.ai/v1/messages | URL for cURL or raw HTTP |
| Model ID | Varies by model | Selects the Claude model |
| Auth header | Authorization: Bearer | Authenticates the request |
| Required body | model, messages, max_tokens | Minimum Messages API body |
| Response text | content[].text | Messages API response parser |
The most common setup mistake is confusing the base URL with a full endpoint.
cURL does not construct paths; it must use the complete /v1/messages URL.
The second most common mistake is reaching for the OpenAI SDK: this route does
not return a choices array, so client.chat.completions.create will not
parse the response even if the request reaches the server. The platform-wide
route list lives in the API documentation if you
also call OpenAI-compatible or embedding endpoints with the same key.
The Messages API shape differs from OpenAI Chat Completions in four areas:
systemis a top-level parameter, not arole: "system"message.max_tokensis required on every request.- Response
contentis an array of typed blocks, not a single string. - Usage reports
input_tokensandoutput_tokens, notprompt_tokensandcompletion_tokens.
Model IDs for every Claude model
Every Claude model on OurToken uses the same endpoint and the same key. Change only the model ID.
| Model | Model ID | Context | Max output |
|---|---|---|---|
| Claude Sonnet 5 | claude-sonnet-5 | 1M tokens | 128K tokens |
| Claude Opus 5 | claude-opus-5 | 1M tokens | 128K tokens |
| Claude Opus 4.8 | claude-opus-4-8 | 200K tokens | 32K tokens |
| Claude Opus 4.7 | claude-opus-4-7 | 200K tokens | 32K tokens |
| Claude Sonnet 4.6 | claude-sonnet-4-6 | 200K tokens | 32K tokens |
For model-specific setup tutorials that follow the same Messages API pattern:
Model ID mistakes to avoid
| Wrong value | Why it fails |
|---|---|
Claude Sonnet 5 (display name) | Not an API model ID |
claude-sonnet-5.0 (version suffix) | Does not exist |
anthropic/claude-sonnet-5 (catalog path) | Catalog path, not model ID |
claude-sonnet-4.6 (dot) | Dot instead of hyphen |
claude-sonnet-4-6-latest | Not listed on the current model page |
claude-opus-4.8 (dot separator) | Hyphen required, not dot |
Test Your Claude API Key with cURL
Start with a tiny request. It proves the key, endpoint, model ID, and body shape before you write any application code. This example uses Sonnet 5; replace the model ID to test any other Claude model.
curl -sS https://api.ourtoken.ai/v1/messages \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${OURTOKEN_API_KEY}" \
-d '{
"model": "claude-sonnet-5",
"max_tokens": 256,
"messages": [
{"role": "user", "content": "Give me a short checklist for reviewing a pull request."}
]
}'
A successful response contains a type: message, a role: assistant, a
content array, the model ID, a stop_reason, and a usage object. Read
the assistant text from content[0].text, never from
choices[0].message.content.
{
"id": "msg_redacted",
"type": "message",
"role": "assistant",
"model": "claude-sonnet-5",
"content": [{"type": "text", "text": "1. Check the intent.\n2. Review risky code paths.\n3. Confirm tests and rollback."}],
"stop_reason": "end_turn",
"usage": {"input_tokens": 24, "output_tokens": 28}
}
PowerShell smoke test
$payload = @{
model = "claude-sonnet-5"
max_tokens = 256
messages = @(@{role = "user"; content = "Give me a short checklist for reviewing a pull request."})
} | ConvertTo-Json -Depth 5
curl.exe "https://api.ourtoken.ai/v1/messages" `
-H "Content-Type: application/json" `
-H "Authorization: Bearer $env:OURTOKEN_API_KEY" `
--data-raw $payload
If cURL fails, isolate whether the issue is the auth header, the full URL, or the model ID before debugging application code.
Claude API Key Pricing Across All Models
OurToken prices these Claude models at 40% of the official comparison price, so both numbers appear side by side. Cache-read pricing applies when a prompt prefix is served from cache, and cache-write pricing applies when that prefix is first stored; the prompt caching guide covers how cached-input economics work in practice. All values below were verified on 2026-09-11.
| Model | Input (OurToken / official) | Output (OurToken / official) | Cache read (OurToken / official) | Cache write (OurToken / official) | Context |
|---|---|---|---|---|---|
| Claude Sonnet 5 | $0.80 / $2.00 per 1M | $4.00 / $10.00 per 1M | $0.08 / $0.20 per 1M | $1.00 / $2.50 per 1M | 1M, 128K out |
| Claude Opus 5 | $2.00 / $5.00 per 1M | $10.00 / $25.00 per 1M | $0.20 / $0.50 per 1M | $2.50 / $6.25 per 1M | 1M, 128K out |
| Claude Opus 4.8 | $2.00 / $5.00 per 1M | $10.00 / $25.00 per 1M | $0.20 / $0.50 per 1M | $2.50 / $6.25 per 1M | 200K, 32K out |
| Claude Opus 4.7 | $2.00 / $5.00 per 1M | $10.00 / $25.00 per 1M | $0.20 / $0.50 per 1M | $2.50 / $6.25 per 1M | 200K, 32K out |
| Claude Sonnet 4.6 | $1.20 / $3.00 per 1M | $6.00 / $15.00 per 1M | $0.12 / $0.30 per 1M | $1.50 / $3.75 per 1M | 200K, 32K out |
Worked cost examples
These are arithmetic illustrations of the prices above, not measured billing.
A typical agent step with Sonnet 5 (60% cache rate). A request sends 20,000 input tokens, 12,000 served from cache, and receives 2,000 output tokens:
Fresh input: 8,000 / 1,000,000 x $0.80 = $0.0064
Cache read: 12,000 / 1,000,000 x $0.08 = $0.0010
Output: 2,000 / 1,000,000 x $4.00 = $0.0080
Total: $0.0154
The same step with Opus 5:
Fresh input: 8,000 / 1,000,000 x $2.00 = $0.0160
Cache read: 12,000 / 1,000,000 x $0.20 = $0.0024
Output: 2,000 / 1,000,000 x $10.00 = $0.0200
Total: $0.0384
Sonnet 5 costs roughly 40% of Opus 5 per request, which compounds across every hour of agent loop execution. The routing strategy (default to Sonnet, escalate to Opus on difficulty) is a direct consequence of this price gap.
Cost estimator for any Claude model
PRICES_PER_MTOK = {
"claude-sonnet-5": {"input": 0.80, "output": 4.00, "cache_read": 0.08},
"claude-opus-5": {"input": 2.00, "output": 10.00, "cache_read": 0.20},
"claude-opus-4-8": {"input": 2.00, "output": 10.00, "cache_read": 0.20},
"claude-sonnet-4-6": {"input": 1.20, "output": 6.00, "cache_read": 0.12},
}
def request_cost(model_id: str, usage: dict) -> float:
p = PRICES_PER_MTOK.get(model_id)
if not p:
return 0.0
return (
usage.get("input_tokens", 0) * p["input"] / 1_000_000
+ usage.get("output_tokens", 0) * p["output"] / 1_000_000
+ usage.get("cache_read_input_tokens", 0) * p["cache_read"] / 1_000_000
)
Log the return value next to the model ID and request ID on every call. That pairing makes a monthly bill explainable at a glance.
Real Scenario: A PR Review Assistant on One Key
Consider a 12-person engineering team that runs a code-review assistant in CI. Every pull request triggers one review pass: the job caches the system prompt and repository conventions, sends the diff plus related context, and posts findings back to the PR. The workload is modest but recurring:
- 1,500 reviews per month.
- Each review sends 20,000 input tokens: 12,000 cached (system prompt, conventions, repo map) and 8,000 fresh (diff and retrieved context).
- Each review receives 2,000 output tokens.
- 80% of reviews are routine diffs that Sonnet 5 handles well; 20% are cross-module refactors escalated to Opus 5.
| Route | Reviews | Cost per review | Monthly |
|---|---|---|---|
Sonnet 5 (claude-sonnet-5) | 1,200 | $0.0154 | $18.43 |
Opus 5 (claude-opus-5) | 300 | $0.0384 | $11.52 |
| Total | 1,500 | — | $29.95 |
For comparison, the same token mix at official list rates would run about
$74.88 per month, and sending every review to Opus 5 would put the month near
$57.60 even at OurToken's discounted rates. The escalation rule is where the
money is, because claude-opus-5 costs 2.5x claude-sonnet-5 per token.
The engineering side is deliberately boring. The CI job keeps one
OURTOKEN_API_KEY secret, one messages payload template, and a model
value per route. A 429 or 529 on the Sonnet route retries the identical body
on a fallback model ID (for example claude-opus-4-8) after a backoff, and
the response parser, usage logging, and cost attribution do not change.
Every call logs model, input_tokens, output_tokens, and
cache_read_input_tokens next to the pull request ID, so the monthly bill is
explainable per route instead of one opaque number.
That is the practical benefit of a clean Claude API key setup: the review assistant's entire cost surface is one endpoint, two model IDs, and the usage object every response already returns.
Python Example for Every Claude Model
The same Python client handles every Claude model. Install the dependency:
python -m pip install --upgrade httpx
Single request
import os
import httpx
BASE_URL = "https://api.ourtoken.ai/v1"
API_KEY = os.environ["OURTOKEN_API_KEY"]
payload = {
"model": "claude-sonnet-5",
"max_tokens": 512,
"system": "You are a concise engineering assistant.",
"messages": [
{"role": "user", "content": "Explain how to review a database migration safely."}
],
}
response = httpx.post(
f"{BASE_URL}/messages",
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
},
json=payload,
timeout=60.0,
)
response.raise_for_status()
data = response.json()
text_blocks = [
block["text"]
for block in data.get("content", [])
if block.get("type") == "text" and "text" in block
]
print("\n".join(text_blocks))
usage = data.get("usage", {})
print({
"model": data.get("model"),
"input_tokens": usage.get("input_tokens", 0),
"output_tokens": usage.get("output_tokens", 0),
"cache_read_input_tokens": usage.get("cache_read_input_tokens", 0),
})
Switch to a different Claude model
Change only the model ID. Everything else---key, endpoint, parser---stays the same.
payload["model"] = "claude-opus-5" # switching from Sonnet 5 to Opus 5
response = httpx.post(
f"{BASE_URL}/messages",
headers={"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"},
json=payload,
timeout=60.0,
)
response.raise_for_status()
data = response.json()
print(data["content"][0]["text"])
For a step-by-step Claude Messages API Python walkthrough with multi-turn requests and response assertions, see the Claude Opus 4.8 API key setup guide, which follows the same request pattern with Opus 4.8-targeted examples.
Troubleshooting Claude API Key Issues
The most common failures are configuration errors, not key validity. Check in this order: auth header, full URL, model ID, required fields, response parser.
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 unauthorized | x-api-key header or missing key | Use Authorization: Bearer |
| 404 not found | Missing /messages path or /v1 prefix | Full URL: https://api.ourtoken.ai/v1/messages |
model_not_found | Wrong model ID | Use an exact value from the model ID table |
| 400 validation error | Missing max_tokens | Include model, messages, max_tokens |
| 429 or 529 | Rate or capacity limit | Retry with backoff; consider a fallback model ID |
| Parser exception | Reading choices[0].message.content | Read content[].text blocks |
| Unexpected output | stop_reason indicates tool use | Inspect stop_reason, iterate typed blocks |
Start with the cURL smoke test above. If raw HTTP works but an SDK or app fails, the bug is in the SDK's headers, path construction, response parser, or model configuration.
Conclusion
A Claude API key is the entire integration surface on OurToken: one Bearer
credential, one /v1/messages endpoint, and a model field that selects
among Sonnet 5, Opus 5, Opus 4.8, Opus 4.7, and Sonnet 4.6. The failure modes
are equally small in number---wrong header, wrong URL, wrong model ID,
missing max_tokens, wrong parser---and the troubleshooting table resolves
each one in a single step.
If cost is the constraint, start on Sonnet 5 and escalate to Opus 5 only
where difficulty demands it; the scenario above is the difference between a
$30 month and a $75 month for the same workload. Keep the usage object in
your logs from day one, because token counts turn pricing debates into
arithmetic.
When you are ready to wire it up, create a key on the API Keys page and run the cURL smoke test before touching application code.
FAQ
What is a Claude API key and where do I get one?
A Claude API key is a Bearer credential that authenticates your application
to the Claude Messages API endpoint. You can get one from the
OurToken API Keys page (one key for all Claude
models) or from the Anthropic Console (native x-api-key credential).
Is a Claude API key free?
Creating a key is free on both platforms; billing accrues on per-token usage at the model-level prices listed above. Anthropic's Console may include promotional credits for new accounts---confirm the current terms there, since trial offers change.
Does one API key work for all Claude models?
Yes. On OurToken, a single API key authenticates requests to every Claude
model. Change only the model field in the request body.
What is the Claude API key endpoint on OurToken?
The full endpoint is https://api.ourtoken.ai/v1/messages with
Authorization: Bearer YOUR_API_KEY. The SDK base URL is
https://api.ourtoken.ai/v1.
What is the difference between an OurToken Claude API key and an Anthropic key?
An OurToken key uses Authorization: Bearer and works with all Claude models
at 40% of the official price. An Anthropic key uses the native x-api-key
header and is limited to Anthropic-hosted routes at official full rates. Both
produce the same response shapes, but the auth mechanism, base URL, and price
are different.
What is the Claude Sonnet 5 context window?
Sonnet 5 accepts up to 1M tokens of context with a maximum output of 128K tokens---the same 1M class as Opus 5, and five times the 200K window of the Sonnet 4.6, Opus 4.7, and Opus 4.8 generation.
What is the fastest Claude API key setup?
Four steps: create a key on the API Keys page, export it as
OURTOKEN_API_KEY, send the cURL smoke test to
https://api.ourtoken.ai/v1/messages with claude-sonnet-5, then change the
model field to reach every other Claude model. Most failed setups trace
back to the auth header or the request path, not to the key itself.