Thelsy
Claude Code

Use Claude Code with your own API endpoint

Claude Code can talk to any service that speaks the Anthropic Messages API — two environment variables and it points somewhere else. But "compatible" is doing a lot of work in that sentence: some endpoints answer a test request and still fall over the moment an agent starts working. Here is what to check, in the order that saves you time.

1. The setup is two variables

ANTHROPIC_BASE_URL is the root of the API — Claude Code appends /v1/messages itself, so do not add the path yourself.

terminal
export ANTHROPIC_BASE_URL="https://your-endpoint.example.com"
export ANTHROPIC_AUTH_TOKEN="your-key"
claude

On Windows PowerShell the same two variables are set with $env::

PowerShell
$env:ANTHROPIC_BASE_URL = "https://your-endpoint.example.com"
$env:ANTHROPIC_AUTH_TOKEN = "your-key"
claude
If the client complains about authentication, some builds read ANTHROPIC_API_KEY instead of ANTHROPIC_AUTH_TOKEN. Try the other name before you start debugging the endpoint.

2. What the endpoint actually has to support

A chatbot that answers one question proves almost nothing. Claude Code is an agent, and it needs all of these:

Two things are not required: prompt caching and returned thinking blocks. Both improve cost and quality, but their absence does not break the client.

3. Verify it in one request

Before touching your environment variables, ask the endpoint directly. This is the smallest request that exercises the whole path:

terminal
curl https://your-endpoint.example.com/v1/messages \
  -H "x-api-key: $YOUR_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "your-model-id",
    "max_tokens": 128,
    "messages": [{"role": "user", "content": "Say hello in one sentence."}]
  }'

A working endpoint answers with Anthropic's shape — type: "message", a content array, stop_reason, and usage.input_tokens / usage.output_tokens. If you get an OpenAI-style chat.completion object instead, the endpoint is not speaking the Anthropic protocol and Claude Code will not work with it.

Then test the two things that actually break agents — add "stream": true to the body and confirm you receive SSE events, and add a "tools" array and confirm you get back a tool_use block.

4. The part most guides leave out: token burn

An agent resends the context on every turn. One ordinary task — read a file, edit it, run the tests, fix the failure — can move several hundred thousand tokens, and a long session can move millions. Two consequences:

5. A checklist for choosing the endpoint

Where Thelsy fits

We serve an Anthropic-compatible endpoint on the same host as our OpenAI-compatible one, so Claude Code runs on deepseek-flash through a monthly card subscription. Streaming, tool use and system prompts are all supported and tested; the usage log itemises input, output and cache tokens per request. When a plan's included tokens run out, calls stop — there is no automatic overage charge.