A lightweight, dependency-minimal Python library designed to validate API keys and retrieve available models across multiple LLM providers.
When building AI-integrated applications, managing multiple API keys can be error-prone. This tool provides a unified interface to:
- Instantly Validate Keys: Verify if an API key is active and has the necessary permissions without sending complex prompts.
- Auto-Detect Providers: Automatically identify whether a key belongs to OpenAI, Anthropic, or Groq based on its format.
- List & Classify Models: Fetch all available models for a specific key and categorize them by type (Chat, Embedding, Image, Audio, etc.).
- Minimal Overhead: Built with modern Python and
httpxfor high-performance asynchronous validation.
Currently, the library supports:
- OpenAI: Validates
sk-format keys. - Anthropic: Validates
sk-ant-format keys. - Google Gemini: Validates API keys for the Generative Language API.
- Groq: Validates
gsk_format keys.
This project uses uv for modern, fast dependency management.
# Using uv (recommended)
uv pip install llm-key-validator
# Using standard pip
pip install llm-key-validator
If you have a string and don't know which provider it belongs to, use detect_provider.
from llm_key_validator import detect_provider
key = "sk-ant-..."
provider = detect_provider(key)
print(f"Detected: {provider}") # Output: Provider.ANTHROPICUse the create_validator factory to get the correct validator and audit the key's capabilities.
import asyncio
from llm_key_validator import create_validator, Provider
async def check_key():
# Initialize the validator
validator = create_validator(Provider.OPENAI, "your-api-key-here")
# Check if the key is valid
if await validator.validate():
print(f"Key for {validator.masked_key} is valid!")
# Get models grouped by their purpose (Chat, Image, etc.)
models = await validator.get_models_grouped()
for model_type, names in models.items():
print(f"{model_type.value}: {len(names)} models available")
else:
print("Invalid API Key.")
asyncio.run(check_key())factory.py: The main entry point for creating validators and detecting types.base.py: Abstract base class defining the validation interface.providers/: Specific implementations for each API (OpenAI, Gemini, etc.).enums.py: Strongly typedProviderandModelTypedefinitions.
This project adheres to high code-quality standards using ruff for linting and black for formatting.
# Run linting
uv run ruff check .
# Run formatting
uv run black .
This project is licensed under the MIT License - see the LICENSE file for details.