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.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 --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.1.0.tar.gz (19.8 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.1.0-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

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

Hashes for llm_key_validator-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ab33a1cf7950525a78a5acfedfc304087eb8375e4968517e58fbdc72931beb9e
MD5 47e4cbb4cb72a013ed933bc093e4f4fa
BLAKE2b-256 f938a4a28900bbc3fc06013ff018f0af0eff6c75de5d774d7f383ba373612656

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for llm_key_validator-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 685fbddbb63ae5111628423571a1a76183c16690c62c1c2fbdc7b3270439c8b0
MD5 67370f6c0afccd362231c3f4bf94e481
BLAKE2b-256 1c7685e8b78f5d9b8037470fecfee7066d6ec6b580ab75b4fc26e1c811d3dec0

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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