Claude Code

Claude Code speaks Anthropic’s native Messages protocol. JoyToken’s public model endpoint is OpenAI-compatible, so Claude Code needs an Anthropic-to-OpenAI-compatible bridge in front of JoyToken.

What is Claude Code?

Claude Code is Anthropic’s coding agent for terminal and editor workflows. It is designed around Anthropic authentication and Messages API semantics.

With JoyToken, the deployment shape is:

Claude Code
-> Anthropic-compatible bridge
-> JoyToken /openai/v1/chat/completions
-> upstream model

Quick Start

Step 1: Create a JoyToken API key

Create a dedicated key such as dev-claude-code. Use a small development budget while testing the bridge.

Step 2: Run a bridge

The bridge should expose an Anthropic-compatible endpoint locally or inside your private network and forward model calls to JoyToken.

.env
$JOY_TOKEN_API_KEY="jt_xxx"
$JOY_TOKEN_OPENAI_BASE_URL="https://api-dev.joytokens.ai/openai/v1"
$JOY_TOKEN_DEFAULT_MODEL="auto"

Recommended contract:

POST http://localhost:8787/v1/messages
-> POST https://api-dev.joytokens.ai/openai/v1/chat/completions

Step 3: Configure Claude Code

Point Claude Code at the bridge:

~/.zshrc
$export ANTHROPIC_BASE_URL="http://localhost:8787"
$export ANTHROPIC_AUTH_TOKEN="$JOY_TOKEN_API_KEY"
$export ANTHROPIC_API_KEY=""

If your Claude Code version requires ANTHROPIC_API_KEY, set it to the same JoyToken key. Do not leave an old Anthropic account session active during testing.

Step 4: Clear old login state

If you previously logged in to Claude Code with Anthropic, run:

> /logout

Restart Claude Code so it reads the new environment.

Step 5: Verify

Run /status inside Claude Code and confirm the base URL points to your bridge. Then check JoyToken Logs for requests under the dev-claude-code key.

Bridge Requirements

Claude Code sideJoyToken side
Anthropic Messages requestOpenAI-compatible Chat Completions request
ANTHROPIC_AUTH_TOKENAuthorization: Bearer $JOY_TOKEN_API_KEY
Claude model nameauto or a JoyToken model key
Tool use blocksOpenAI-compatible tool calls
Streaming eventsChat Completions SSE chunks
Anthropic-shaped errorsJoyToken status and error body mapped back to Claude Code

Why use JoyToken with Claude Code?

Centralized budget control

Use a dedicated Claude Code key and apply policy, budget, wallet, and IP checks before requests reach upstream providers.

Usage visibility

Bridge logs plus JoyToken Logs and Usage let teams attribute Claude Code traffic by API key.

Model routing

Map Claude model names to auto during evaluation, or maintain a strict allowlist of JoyToken model keys for production.

Troubleshooting

SymptomCheck
Claude Code cannot start a sessionANTHROPIC_BASE_URL points to the bridge
JoyToken returns 401Bridge forwards the JoyToken key as Bearer auth
Tool calls failBridge converts Anthropic tool use to OpenAI-compatible tool calls
Streaming hangsBridge streams incrementally instead of buffering the whole response
No JoyToken usageClaude Code is still using a cached Anthropic session or another base URL

Resources