Skip to main content

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.10.

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 --stdin or --env over passing keys on argv (shell history).
  • Validation hits live provider APIs and may count toward your rate limits.
  • For untrusted input, pass offline=True to skip the network.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_key_validator-1.0.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_key_validator-1.0.0-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

Details for the file llm_key_validator-1.0.0.tar.gz.

File metadata

  • Download URL: llm_key_validator-1.0.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for llm_key_validator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c38aee473ce4c8271ec22b06de256cd3b102b90d5258678faee42053771e5507
MD5 44acf70f444caf67aa5752e683052324
BLAKE2b-256 c541d02a9e420d1d9603c78f77e15f6691e3201c9eef97cb60986e30d31c88ad

See more details on using hashes here.

File details

Details for the file llm_key_validator-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_key_validator-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 904d1d5bc2c58b78a757a411aaed4073da4b9638ab1f20b1ccc69b8bdbd15282
MD5 6c57bd51a0f55029789474ce30f6bd65
BLAKE2b-256 e808e21dfbefbf0602d1d38b7e9be8575932974da8ff4e82dab0f233674e4f1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page