Skip to content
kenari.

Claude Code

Claude Code speaks the Anthropic API format, which kenari serves at /v1/messages. To connect, set three environment variables. Claude Code needs a chat model that supports tool calling. Check that tool_call is true for the model in the live catalog:

Terminal window
curl -s https://kenari.id/v1/models \
| jq -r '.data[] | select(.tool_call == true) | .id'

A request with tools to a model without tool calling returns 400, and so do image, speech, transcription and video ids.

You need an API key in KENARI_API_KEY. See Quickstart to create one and export it.

Terminal window
export ANTHROPIC_BASE_URL=https://kenari.id
export ANTHROPIC_AUTH_TOKEN=$KENARI_API_KEY
export ANTHROPIC_MODEL=step-3-7-flash:free
VariableValue
ANTHROPIC_BASE_URLhttps://kenari.id, with no /v1. Claude Code adds /v1/messages itself.
ANTHROPIC_AUTH_TOKENYour kenari API key, starting with kn-. See Authentication and API keys.
ANTHROPIC_MODELA model id from Models and pricing. step-3-7-flash:free runs with zero balance.

ANTHROPIC_API_KEY also works in place of ANTHROPIC_AUTH_TOKEN. kenari accepts the key from either the Authorization header or the x-api-key header.

Add the export lines to your shell profile, such as ~/.zshrc or ~/.bashrc, together with export KENARI_API_KEY=kn-... so that the source variable exists in every new terminal. Then open a new terminal. Or put them in the env block of Claude Code’s settings.json:

{
"env": {
"ANTHROPIC_BASE_URL": "https://kenari.id",
"ANTHROPIC_AUTH_TOKEN": "kn-...",
"ANTHROPIC_MODEL": "step-3-7-flash:free"
}
}

A settings.json file stores the key in plain text, so keep it out of version control.

If you set environment variables, check that the key is set without printing it. Use ANTHROPIC_API_KEY in place of ANTHROPIC_AUTH_TOKEN if that is the one you chose. If you use settings.json, skip this check.

Terminal window
test -n "$ANTHROPIC_AUTH_TOKEN" && echo set

Then start Claude Code and send any message:

Terminal window
claude

A reply means the connection works.

Claude Code asks POST /v1/messages/count_tokens before each turn to size its context window. kenari answers with an estimate and does not bill the call. It still needs your key.

The variables above send every Claude Code session to one model. The kenari CLI routes only the sessions you start with kenari claude, and lets you put a different model behind each role, such as opus or subagents. Pick one. If you leave the variables set, kenari claude overrides them for its own session.

SymptomCauseFix
401 with invalid key or missing authorizationThe variable did not load, or the key does not start with kn-.Use the key you saved, then open a new terminal. A lost key cannot be shown again, so create a new one. See Authentication and API keys.
400 with model_not_foundThe model id is misspelled or not in the catalog.Copy the id from Models and pricing.
402 with insufficient_balanceThe model is paid and your balance is empty.Use a :free model, or top up. See How billing works.
405The base URL ends in /v1, so the request goes to /v1/v1/messages.Set ANTHROPIC_BASE_URL to https://kenari.id.
model_not_found for a model you did not chooseClaude Code also sends background requests to a small default model that kenari may not carry.Set ANTHROPIC_DEFAULT_HAIKU_MODEL to a catalog model id.