Skip to content
All posts

How to get a Claude API key (and use it in code and Claude Code)

Two ways to get an API key that calls Claude: from Anthropic's Console, or an Inferray key that calls Claude and every other model at list price. Then how to use it with the Anthropic SDK, the OpenAI SDK and Claude Code.

An API key is what lets your code — or a tool like Claude Code — call Claude and pay per token, instead of using a Claude chat subscription. There are two ways to get one.

Option 1: from Anthropic

Anthropic issues API keys from its Claude Console, where you buy API usage credits; Anthropic's own help center points Claude Code users there for "intensive coding sprints" (Claude Code help). An Anthropic key calls Anthropic's models.

Option 2: an Inferray key

An Inferray key calls Claude at its list price — and GPT, Gemini, DeepSeek, GLM and Kimi with the same key and the same balance:

  1. Sign up. Seats, projects and API keys are free.
  2. Create a key in the dashboard.
  3. Add credit, or pick a Token Plan. Credit never expires, and there is no gateway fee on top.
ModelInput / 1MCached / 1MOutput / 1MContext
Claude Opus 5.5$4$0.2$201M
Claude Sonnet 5.5$2$0.1$101M
Claude Haiku 5.5$0.1$0.01$0.51M

Use it with the Anthropic SDK

import anthropic

client = anthropic.Anthropic(base_url="https://api.inferray.com", api_key="inferray_...")
message = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    messages=[{"role": "user", "content": "ship it"}],
)

Use it with the OpenAI SDK

from openai import OpenAI

client = OpenAI(base_url="https://api.inferray.com/v1", api_key="inferray_...")
reply = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "ship it"}],
)

Use it in Claude Code

export ANTHROPIC_BASE_URL="https://api.inferray.com"
export ANTHROPIC_AUTH_TOKEN="inferray_..."

The Claude Code guide covers the settings file and the VS Code extension. Keep the key out of source control: put it in an environment variable or a secrets manager.

Prices on this page come from the model catalog and were current on November 12, 2026.