Validate API keys for OpenAI, Anthropic, Google Gemini, Groq, Mistral, OpenRouter, Cohere, DeepSeek, Together, Fireworks, xAI, and Perplexity. Zero dependencies. CLI + library.
Project description
llm-key-validator (Python)
Validate API keys for 12 LLM providers — OpenAI, Anthropic, Google Gemini, Groq, Mistral, OpenRouter, Cohere, DeepSeek, Together, Fireworks, xAI, and Perplexity. Zero runtime dependencies, stdlib only.
This is the Python sibling of the npm package of the same name. Both packages share provider specs and ship in lockstep.
Install
pip install llm-key-validator
Requires Python ≥ 3.8.
Library
from llm_key_validator import validate_key
result = validate_key("sk-ant-...")
if result.valid:
print(f"Valid {result.provider} key ({result.latency_ms} ms)")
else:
print(f"Invalid: {result.reason} — {result.message}")
Options
validate_key(
key,
provider="openai", # force provider (skip auto-detect)
offline=True, # format-only, no network
timeout_ms=5000,
retries=2,
)
Scoped providers (tree-shake-style)
Skip the global registry; only the providers you pass are considered for detection.
from llm_key_validator.core import validate_key
from llm_key_validator.providers import openai, anthropic
result = validate_key(key, providers=[openai, anthropic])
Custom providers
from llm_key_validator.core import register_provider, Provider, ProviderRawResult, ValidationContext
def my_validate(key: str, ctx: ValidationContext) -> ProviderRawResult:
res = ctx.http("https://api.example.com/v1/me", headers={"Authorization": f"Bearer {key}"})
return ProviderRawResult(status=res.status, ok=res.ok)
register_provider(Provider(
name="my-provider",
display_name="My Provider",
key_env_var="MY_API_KEY",
detect=lambda k: k.startswith("mp_"),
validate=my_validate,
))
CLI
# auto-detect
llm-key-validator sk-ant-...
# force provider
lkv -p openai $OPENAI_API_KEY
# validate every <PROVIDER>_API_KEY in your environment
lkv --env
# format-only (no network)
lkv --offline sk-...
# scan a .env file
lkv scan .env
# pipe a key
echo "$ANTHROPIC_API_KEY" | lkv --stdin
# JSON output
lkv --json --env | jq
lkv and llm-key-validator are aliases.
Exit codes
| Code | Meaning |
|---|---|
| 0 | all keys valid |
| 1 | usage error |
| 2 | one or more keys invalid |
| 3 | unexpected error |
Security
- Prefer
--stdinor--envover passing keys on argv (shell history). - Validation hits live provider APIs and may count toward your rate limits.
- For untrusted input, pass
offline=Trueto skip the network.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llm_key_validator-1.1.0.tar.gz.
File metadata
- Download URL: llm_key_validator-1.1.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab33a1cf7950525a78a5acfedfc304087eb8375e4968517e58fbdc72931beb9e
|
|
| MD5 |
47e4cbb4cb72a013ed933bc093e4f4fa
|
|
| BLAKE2b-256 |
f938a4a28900bbc3fc06013ff018f0af0eff6c75de5d774d7f383ba373612656
|
Provenance
The following attestation bundles were made for llm_key_validator-1.1.0.tar.gz:
Publisher:
python-release.yml on jishnu-mohan/llm-key-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_key_validator-1.1.0.tar.gz -
Subject digest:
ab33a1cf7950525a78a5acfedfc304087eb8375e4968517e58fbdc72931beb9e - Sigstore transparency entry: 1812119166
- Sigstore integration time:
-
Permalink:
jishnu-mohan/llm-key-validator@92953787fac2d9f852490b810fa9dbde7fa1ab1c -
Branch / Tag:
refs/tags/py-v1.1.0 - Owner: https://github.com/jishnu-mohan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@92953787fac2d9f852490b810fa9dbde7fa1ab1c -
Trigger Event:
push
-
Statement type:
File details
Details for the file llm_key_validator-1.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_key_validator-1.1.0-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
685fbddbb63ae5111628423571a1a76183c16690c62c1c2fbdc7b3270439c8b0
|
|
| MD5 |
67370f6c0afccd362231c3f4bf94e481
|
|
| BLAKE2b-256 |
1c7685e8b78f5d9b8037470fecfee7066d6ec6b580ab75b4fc26e1c811d3dec0
|
Provenance
The following attestation bundles were made for llm_key_validator-1.1.0-py3-none-any.whl:
Publisher:
python-release.yml on jishnu-mohan/llm-key-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_key_validator-1.1.0-py3-none-any.whl -
Subject digest:
685fbddbb63ae5111628423571a1a76183c16690c62c1c2fbdc7b3270439c8b0 - Sigstore transparency entry: 1812119213
- Sigstore integration time:
-
Permalink:
jishnu-mohan/llm-key-validator@92953787fac2d9f852490b810fa9dbde7fa1ab1c -
Branch / Tag:
refs/tags/py-v1.1.0 - Owner: https://github.com/jishnu-mohan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yml@92953787fac2d9f852490b810fa9dbde7fa1ab1c -
Trigger Event:
push
-
Statement type: