# 401 Invalid API key in an OpenAI-compatible app

> 401 Invalid API key in an OpenAI-compatible app? The key is missing, mistyped or replaced. How to fix it and test the key with curl.

A 401 "Invalid API key" from an OpenAI-compatible API means the key the app sent is missing, mistyped or was replaced. Copy your current key again, paste it into the app's API key field or environment variable, and open a new terminal so the variable is loaded. The app's base URL must be https://api.outrun.to/v1.

## What causes it?

- The key was replaced, so the old one no longer works.
- A space or line break was copied with the key.
- The environment variable is set in a different terminal or not loaded yet.
- The app sends another provider's key from its own saved settings.

## How do I fix it?

In this order. [The Troubleshooting](https://outrun.to/docs/troubleshooting) has the full setup.

- Copy your current key from API keys on the dashboard.
- Paste it into the app's API key field, or set it in your environment variable.
- Open a new terminal or restart the app.
- Test the key on its own with the request below. It uses a little credit.

**Test your key**

```
curl https://api.outrun.to/v1/chat/completions \
 -H "Authorization: Bearer $OUTRUN_API_KEY" \
 -H "Content-Type: application/json" \
 -d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Reply with OK only."}], "max_tokens": 16}'
```

## Questions

### Does a 401 mean my balance is empty?

No. A low balance returns an insufficient balance error. A 401 is about the key itself.

### Why does it still fail after I set the variable?

Programs read environment variables when they start. Close the terminal or app and open it again.

### Does Outrun keep my prompts or outputs?

Outrun does not store your prompts, images or outputs unless you choose to save them.

## Related pages

- [Model not found (404)](https://outrun.to/fix/model-not-found-404)
- [Anthropic base URL not working](https://outrun.to/fix/anthropic-base-url-not-working)
- [Troubleshooting](https://outrun.to/docs/troubleshooting)
- [All error fixes](https://outrun.to/fix)
- [Get your API key](https://outrun.to/overview)

[Get your API key](https://outrun.to/key) [See all models and prices](https://outrun.to/pricing)
