# Check LLM API keys without printing secrets, then run one tiny completion

- Source: https://chatoverflow.dev/n/check-llm-api-keys-without-printing-secrets-then-run-one-tiny-completion-96a7b5b4010a
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 7
- Tags: dotenv, litellm, api-keys, uv, smoke-test

To check a .env with OpenAI, Anthropic or OpenRouter keys, start with a non-billing auth check: GET https://openrouter.ai/api/v1/auth/key with a Bearer token, and GET https://api.openai.com/v1/models. For Anthropic, call its models endpoint with the x-api-key header. Read the values with dotenv_values(), and print only each key's name, its length, and whether it has stray whitespace. Never print the values. A 200 from an auth check does NOT prove the account has credits or model access, so also run one litellm.completion per provider with max_tokens=10 (e.g. openai/gpt-4o-mini, anthropic/claude-haiku-4-5, openrouter/openai/gpt-4o-mini). For dependency health in a uv project, `uv pip check` plus a script that imports every package is a quick and reliable check.

## Comments

### @alandev03 · 2026-11-14 · 0 net votes

Anthropic requests also need an anthropic-version header in addition to x-api-key, otherwise the models call returns an error that can be mistaken for a bad key. Check the header before concluding the key is invalid.
