> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getunbound.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Fixing API Key Not Working or Invalid Key Errors

> Troubleshooting guide for when your Unbound API key is rejected, shows as invalid, or fails to connect in Claude Code, Roo Code, or other tools

## Quick Checklist

Before diving deeper, check these common causes:

<Steps>
  <Step title="No extra spaces">
    Ensure there are no leading or trailing spaces when you paste your API key. Copy it fresh from **Connect → AI Coding Tools → \[Your Tool]**.
  </Step>

  <Step title="Correct tool selected">
    Verify you're using the key from the right tool. Different tools may show different keys in the **Connect → AI Coding Tools** section.
  </Step>

  <Step title="Credits available">
    A **402 error** means your credits are exhausted — this is NOT an invalid key error. See [Credits & Budget](/support/billing/credits-usage-and-budgets) for resolution.
  </Step>

  <Step title="Key not regenerated">
    If someone (including you) regenerated the key, your old key is now **permanently invalid**. Copy the new key from the dashboard.
  </Step>
</Steps>

## "Invalid API key" in Roo Code

| Check                       | Fix                                                                                                     |
| --------------------------- | ------------------------------------------------------------------------------------------------------- |
| Wrong API provider selected | Select **"unbound"** as the API provider (not "OpenAI" or "Anthropic")                                  |
| Wrong key pasted            | Paste the key from **Connect → AI Coding Tools → Roo Code** — not an Anthropic or OpenAI key            |
| Wrong Roo Code version      | You must use the **Unbound-modified version** of Roo Code, not the standard VS Code marketplace version |
| Cached old key              | Remove the key, save settings, re-enter the key, save again                                             |
| Stale session               | Restart VS Code completely after changing the key                                                       |

## "Invalid API key" in Claude Code CLI

### 1. Wrong base URL (most common cause)

Your base URL must point to Unbound, not Anthropic. Verify your current settings:

```bash theme={null}
echo $ANTHROPIC_API_KEY
echo $ANTHROPIC_BASE_URL
```

The base URL **must** be `https://api.getunbound.ai`. If it's set to `https://api.anthropic.com` or is empty, that's the problem.

### 2. Environment variables not loaded

After setting environment variables, you must restart your terminal. If using `~/.bashrc` or `~/.zshrc`:

```bash theme={null}
source ~/.zshrc  # or source ~/.bashrc
```

### 3. Config file conflict

If using a config file at `~/.config/claude-code/config`, verify both the API key and base URL are correct there too. The config file may override your environment variables.

## "API Key Is Incorrect, But It's Correct"

This frustrating error almost always means one of these:

* **Base URL is wrong** — Your requests are going to Anthropic's API (which doesn't recognize Unbound keys) instead of Unbound's API. Fix: `export ANTHROPIC_BASE_URL="https://api.getunbound.ai"`
* **Key from wrong tool** — Double-check which tool's key you copied from **Connect → AI Coding Tools**
* **Key was recently regenerated** — Someone on your team may have regenerated the key. Check the current key in the dashboard
* **Invisible characters** — Some terminals or password managers add invisible characters. Try typing the key manually or pasting from a plain text editor

## How to Verify Your API Key

Run this quick test in your terminal:

```bash theme={null}
curl https://api.getunbound.ai/models \
  -H "Authorization: Bearer YOUR_API_KEY"
```

**Expected results:**

* **Valid key** → Returns a JSON list of available models
* **Invalid key** → Returns an authentication error message
* **No credits** → Returns a 402 error (key is valid, but credits are exhausted)

## Still Not Working?

Contact support with:

1. The **exact error message** you're seeing (screenshot preferred)
2. Which **tool** you're using (Claude Code, Roo Code, Cursor, etc.)
3. Your **email address** associated with your Unbound account
