Registry for OpenAI models with capability and parameter validation
Project description
OpenAI Model Registry
A Python package that provides information about OpenAI models and validates parameters before API calls.
Why Use OpenAI Model Registry?
OpenAI's models have different context-window sizes, parameter ranges, and feature support. If you guess wrong, the API returns an error—often in production.
OpenAI Model Registry keeps an up-to-date, local catalog of every model's limits and capabilities, letting you validate calls before you send them.
Typical benefits:
- Catch invalid
temperature,top_p, andmax_tokensvalues locally. - Swap models confidently by comparing context windows and features.
- Work fully offline—perfect for CI or air-gapped environments.
What This Package Does
- Helps you avoid invalid API calls by validating parameters ahead of time
- Provides accurate information about model capabilities (context windows, token limits)
- Handles model aliases and different model versions
- Works offline with locally stored model information
- Keeps model information up-to-date with optional updates
Installation
pip install openai-model-registry
Simple Example
from openai_model_registry import ModelRegistry
# Get information about a model
registry = ModelRegistry.get_default()
model = registry.get_capabilities("gpt-4o")
# Access model limits
print(f"Context window: {model.context_window} tokens")
print(f"Max output: {model.max_output_tokens} tokens")
# Expected output: Context window: 128000 tokens
# Max output: 16384 tokens
# Check if parameter values are valid
model.validate_parameter("temperature", 0.7) # Valid - no error
try:
model.validate_parameter("temperature", 3.0) # Invalid - raises ValueError
except ValueError as e:
print(f"Error: {e}")
# Expected output: Error: Parameter 'temperature' must be between 0 and 2...
# Check model features
if model.supports_structured:
print("This model supports Structured Output")
# Expected output: This model supports Structured Output
➡️ **Keeping it fresh:** run `openai-model-registry-update` (CLI) or `registry.refresh_from_remote()` whenever OpenAI ships new models.
> **🔵 Azure OpenAI Users:** If you're using Azure OpenAI endpoints, be aware of platform-specific limitations, especially for web search capabilities. See our [Azure OpenAI documentation](docs/user-guide/azure-openai.md) for guidance.
## Practical Use Cases
### Validating Parameters Before API Calls
```python
import openai
from openai_model_registry import ModelRegistry
# Initialize registry and client
registry = ModelRegistry.get_default()
client = openai.OpenAI() # Requires OPENAI_API_KEY environment variable
def call_openai(model, messages, **params):
# Validate parameters before making API call
capabilities = registry.get_capabilities(model)
for param_name, value in params.items():
capabilities.validate_parameter(param_name, value)
# Now make the API call
return client.chat.completions.create(model=model, messages=messages, **params)
# Example usage
messages = [{"role": "user", "content": "Hello!"}]
response = call_openai("gpt-4o", messages, temperature=0.7, max_tokens=100)
# Expected output: Successful API call with validated parameters
Managing Token Limits
from openai_model_registry import ModelRegistry
# Initialize registry
registry = ModelRegistry.get_default()
def truncate_prompt(prompt, max_tokens):
"""Simple truncation function (you'd implement proper tokenization)"""
# This is a simplified example - use tiktoken for real tokenization
words = prompt.split()
if len(words) <= max_tokens:
return prompt
return " ".join(words[:max_tokens])
def prepare_prompt(model_name, prompt, max_output=None):
capabilities = registry.get_capabilities(model_name)
# Use model's max output if not specified
max_output = max_output or capabilities.max_output_tokens
# Calculate available tokens for input
available_tokens = capabilities.context_window - max_output
# Ensure prompt fits within available tokens
return truncate_prompt(prompt, available_tokens)
# Example usage
long_prompt = "This is a very long prompt that might exceed token limits..."
safe_prompt = prepare_prompt("gpt-4o", long_prompt, max_output=1000)
# Expected output: Truncated prompt that fits within token limits
Key Features
- Model Information: Get context window size, token limits, and supported features
- Parameter Validation: Check if parameter values are valid for specific models
- Version Support: Works with date-based models (e.g., "o3-mini-2025-01-31")
- Offline Usage: Functions without internet using local registry data
- Updates: Optional updates to keep model information current
Command Line Usage
Update your local registry data:
openai-model-registry-update
Configuration
The registry uses local files for model information:
# Default locations (XDG Base Directory spec)
Linux: ~/.config/openai-model-registry/
macOS: ~/Library/Application Support/openai-model-registry/
Windows: %LOCALAPPDATA%\openai-model-registry\
You can specify custom locations:
import os
# Use custom registry files
os.environ["MODEL_REGISTRY_PATH"] = "/path/to/custom/models.yml"
os.environ["PARAMETER_CONSTRAINTS_PATH"] = "/path/to/custom/parameter_constraints.yml"
# Then initialize registry
from openai_model_registry import ModelRegistry
registry = ModelRegistry.get_default()
Documentation
For more details, see:
Development
# Install dependencies (requires Poetry)
poetry install
# Run tests
poetry run pytest
# Run linting
poetry run pre-commit run --all-files
Next Steps
- 📚 Examples – real-world scripts in
examples/. - 🤝 Contributing – see CONTRIBUTING.md.
- 📝 Changelog – see CHANGELOG.md for recent updates.
Contributing
We 💜 external contributions! Start with CONTRIBUTING.md and our Code of Conduct.
Need Help?
Open an issue or start a discussion—questions, ideas, and feedback are welcome!
License
MIT License - See LICENSE for details.
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 openai_model_registry-0.7.3.tar.gz.
File metadata
- Download URL: openai_model_registry-0.7.3.tar.gz
- Upload date:
- Size: 28.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ce0460b99ea53608314b10b1d89c2f517301ae50f7391a1c0208cfdec93b085
|
|
| MD5 |
ae3fa32773d00d4441fd1934cc8de059
|
|
| BLAKE2b-256 |
bb5199e73968aacfe57f4e39551532ee47e738c3a3d0cf7e67511d0366a05b0c
|
Provenance
The following attestation bundles were made for openai_model_registry-0.7.3.tar.gz:
Publisher:
publish-poetry.yml on yaniv-golan/openai-model-registry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openai_model_registry-0.7.3.tar.gz -
Subject digest:
2ce0460b99ea53608314b10b1d89c2f517301ae50f7391a1c0208cfdec93b085 - Sigstore transparency entry: 264386623
- Sigstore integration time:
-
Permalink:
yaniv-golan/openai-model-registry@5bf8f8e9be37e1ef0998e7afa8b5dc577dd933ea -
Branch / Tag:
refs/tags/v0.7.3 - Owner: https://github.com/yaniv-golan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-poetry.yml@5bf8f8e9be37e1ef0998e7afa8b5dc577dd933ea -
Trigger Event:
release
-
Statement type:
File details
Details for the file openai_model_registry-0.7.3-py3-none-any.whl.
File metadata
- Download URL: openai_model_registry-0.7.3-py3-none-any.whl
- Upload date:
- Size: 31.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb98a63593464ccf451615272d7d05e854c96c8f70b6c07f2331a1d655b73a97
|
|
| MD5 |
71ebdc9c613105919212867657a3eb73
|
|
| BLAKE2b-256 |
0f54224f72bc2cb3b7e02f52a2ed9566928f8356982c8a48821a930babc7f98c
|
Provenance
The following attestation bundles were made for openai_model_registry-0.7.3-py3-none-any.whl:
Publisher:
publish-poetry.yml on yaniv-golan/openai-model-registry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openai_model_registry-0.7.3-py3-none-any.whl -
Subject digest:
fb98a63593464ccf451615272d7d05e854c96c8f70b6c07f2331a1d655b73a97 - Sigstore transparency entry: 264386624
- Sigstore integration time:
-
Permalink:
yaniv-golan/openai-model-registry@5bf8f8e9be37e1ef0998e7afa8b5dc577dd933ea -
Branch / Tag:
refs/tags/v0.7.3 - Owner: https://github.com/yaniv-golan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-poetry.yml@5bf8f8e9be37e1ef0998e7afa8b5dc577dd933ea -
Trigger Event:
release
-
Statement type: