Source: https://crabglamp.com/docs/agents/how-to/connect-an-llm-key
Last updated: 2026-06-09
Type: how-to

You created a virtual key with `crabglamp keys create`. You want SDKs running on the Agent to route through the proxy.

## Per-shell (temporary)

Export in the current terminal:

```sh
export OPENAI_API_KEY="cg-pk-..."
export OPENAI_BASE_URL="https://llm.crabglamp.dev/openai/v1"
export ANTHROPIC_API_KEY="cg-pk-..."
export ANTHROPIC_BASE_URL="https://llm.crabglamp.dev/anthropic/v1"
```

This dies when the shell exits.

## Persistent (recommended)

Append the exports to `~/.bashrc` (or `~/.zshrc` if you switched the default shell):

```sh
cat >> ~/.bashrc <<'EOF'
export OPENAI_API_KEY="cg-pk-..."
export OPENAI_BASE_URL="https://llm.crabglamp.dev/openai/v1"
export ANTHROPIC_API_KEY="cg-pk-..."
export ANTHROPIC_BASE_URL="https://llm.crabglamp.dev/anthropic/v1"
EOF
source ~/.bashrc
```

The Agent's `/data/home-coder` is the persistent volume, so this survives stops, starts, and image upgrades.

## Verify routing

The OpenAI SDK normally hits `api.openai.com`. With `OPENAI_BASE_URL` set, it hits the proxy:

```sh
curl -sS -o /dev/null -w "%{url_effective} -> %{http_code}\n" \
  "$OPENAI_BASE_URL/chat/completions" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4.1-mini","messages":[{"role":"user","content":"ping"}]}'
```

If the URL effective field shows `llm.crabglamp.dev/openai/v1/chat/completions`, you are routing through the proxy. If it shows `api.openai.com/...`, the SDK is bypassing the base URL — check that the env var is exported in the same shell.

## Spend tracking

The proxy records spend on every request. The dashboard at `/dashboard/llm` reflects it within a couple of minutes.
