mirror of
https://github.com/instructkr/claw-code.git
synced 2026-04-09 01:24:49 +08:00
fix(api): auth-provider error copy — prefix-routing hints + sk-ant-* bearer detection — closes ROADMAP #28
Two live users in #claw-code on 2026-04-08 hit adjacent auth confusion: varleg set OPENAI_API_KEY for OpenRouter but prefix routing didn't activate without openai/ model prefix, and stanley078852 put sk-ant-* in ANTHROPIC_AUTH_TOKEN (Bearer path) instead of ANTHROPIC_API_KEY (x-api-key path) and got 401 Invalid bearer token. Changes: 1. ApiError::MissingCredentials gained optional hint field (error.rs) 2. anthropic_missing_credentials_hint() sniffs OPENAI/XAI/DASHSCOPE env vars and suggests prefix routing when present (providers/mod.rs) 3. All 4 Anthropic auth paths wire the hint helper (anthropic.rs) 4. 401 + sk-ant-* in bearer token detected and hint appended 5. 'Which env var goes where' section added to USAGE.md Tests: unit tests for all three improvements (no HTTP calls needed). Workspace: all tests green, fmt clean, clippy warnings-only. Source: live users varleg + stanley078852 in #claw-code 2026-04-08. Co-authored-by: gaebal-gajae <gaebal-gajae@layofflabs.com>
This commit is contained in:
14
USAGE.md
14
USAGE.md
@@ -109,6 +109,20 @@ cd rust
|
||||
./target/debug/claw logout
|
||||
```
|
||||
|
||||
### Which env var goes where
|
||||
|
||||
`claw` accepts two Anthropic credential env vars and they are **not interchangeable** — the HTTP header Anthropic expects differs per credential shape. Putting the wrong value in the wrong slot is the most common 401 we see.
|
||||
|
||||
| Credential shape | Env var | HTTP header | Typical source |
|
||||
|---|---|---|---|
|
||||
| `sk-ant-*` API key | `ANTHROPIC_API_KEY` | `x-api-key: sk-ant-...` | [console.anthropic.com](https://console.anthropic.com) |
|
||||
| OAuth access token (opaque) | `ANTHROPIC_AUTH_TOKEN` | `Authorization: Bearer ...` | `claw login` or an Anthropic-compatible proxy that mints Bearer tokens |
|
||||
| OpenRouter key (`sk-or-v1-*`) | `OPENAI_API_KEY` + `OPENAI_BASE_URL=https://openrouter.ai/api/v1` | `Authorization: Bearer ...` | [openrouter.ai/keys](https://openrouter.ai/keys) |
|
||||
|
||||
**Why this matters:** if you paste an `sk-ant-*` key into `ANTHROPIC_AUTH_TOKEN`, Anthropic's API will return `401 Invalid bearer token` because `sk-ant-*` keys are rejected over the Bearer header. The fix is a one-line env var swap — move the key to `ANTHROPIC_API_KEY`. Recent `claw` builds detect this exact shape (401 + `sk-ant-*` in the Bearer slot) and append a hint to the error message pointing at the fix.
|
||||
|
||||
**If you meant a different provider:** if `claw` reports missing Anthropic credentials but you already have `OPENAI_API_KEY`, `XAI_API_KEY`, or `DASHSCOPE_API_KEY` exported, you most likely forgot to prefix the model name with the provider's routing prefix. Use `--model openai/gpt-4.1-mini` (OpenAI-compat / OpenRouter / Ollama), `--model grok` (xAI), or `--model qwen-plus` (DashScope) and the prefix router will select the right backend regardless of the ambient credentials. The error message now includes a hint that names the detected env var.
|
||||
|
||||
## Local Models
|
||||
|
||||
`claw` can talk to local servers and provider gateways through either Anthropic-compatible or OpenAI-compatible endpoints. Use `ANTHROPIC_BASE_URL` with `ANTHROPIC_AUTH_TOKEN` for Anthropic-compatible services, or `OPENAI_BASE_URL` with `OPENAI_API_KEY` for OpenAI-compatible services. OAuth is Anthropic-only, so when `OPENAI_BASE_URL` is set you should use API-key style auth instead of `claw login`.
|
||||
|
||||
Reference in New Issue
Block a user