Skip to main content

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

Metadata

Release files for llm-key-validator 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llm-key-validator 1.1.0
File Size Uploaded
llm_key_validator-1.1.0.tar.gz 19.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llm-key-validator 1.1.0
File Interpreter ABI Platform
llm_key_validator-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.3 kB

Release files / llm_key_validator-1.1.0.tar.gz

Download URL llm_key_validator-1.1.0.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ab33a1cf7950525a78a5acfedfc304087eb8375e4968517e58fbdc72931beb9e
BLAKE2b-256 checksum
How to use checksums
f938a4a28900bbc3fc06013ff018f0af0eff6c75de5d774d7f383ba373612656
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 14, 2026.

Transparency log

Release files / llm_key_validator-1.1.0-py3-none-any.whl

Download URL llm_key_validator-1.1.0-py3-none-any.whl
Size 24.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
685fbddbb63ae5111628423571a1a76183c16690c62c1c2fbdc7b3270439c8b0
BLAKE2b-256 checksum
How to use checksums
1c7685e8b78f5d9b8037470fecfee7066d6ec6b580ab75b4fc26e1c811d3dec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page