Documentation

Model Registration

Register AI models from any provider for security testing

🤖

Register Your AI Models

Connect AI models from 8+ providers to ModelRed for comprehensive security testing. Each model gets a unique ID for easy management and testing.

Quick Registration

Register Any Model in 3 Steps

Get any AI model registered and ready for security testing in under 2 minutes.

1

Initialize ModelRed Client

PYTHON
from modelred import ModelRed

async with ModelRed(api_key="mr_your_api_key") as client:
    # Your model registration code goes here
    pass
2

Choose Your Provider

Each provider has a convenient registration method. Pick your provider:

await client.register_openai_model(...)await client.register_anthropic_model(...)await client.register_azure_model(...)
3

Start Testing

Once registered, your model is ready for security assessments.

✅ Model registered and ready for testing!

Provider Registration Methods

🤖

OpenAI

PYTHON
await client.register_openai_model(
    model_id="my-gpt-model",
    api_key="sk-your-openai-key",
    model_name="gpt-4",
    metadata={"purpose": "production"}
)
🔮

Anthropic

PYTHON
await client.register_anthropic_model(
    model_id="my-claude-model",
    api_key="sk-ant-your-key",
    model_name="claude-3-sonnet-20240229"
)
☁️

Azure OpenAI

PYTHON
await client.register_azure_model(
    model_id="my-azure-model",
    api_key="your-azure-key",
    endpoint="https://your-resource.openai.azure.com/",
    deployment_name="gpt-4"
)
🤗

Hugging Face

PYTHON
await client.register_huggingface_model(
    model_id="my-hf-model",
    model_name="microsoft/DialoGPT-small",
    api_key="hf_your_token"
)

AWS Models

AWS Services

Register models from AWS SageMaker and Bedrock services.

🏗️

SageMaker

PYTHON
await client.register_sagemaker_model(
    model_id="my-sagemaker-model",
    endpoint_name="my-llama-endpoint",
    aws_access_key_id="AKIA...",
    aws_secret_access_key="...",
    region="us-east-1"
)
🏔️

Bedrock

PYTHON
await client.register_bedrock_model(
    model_id="my-bedrock-claude",
    bedrock_model_id="anthropic.claude-v2",
    aws_access_key_id="AKIA...",
    aws_secret_access_key="...",
    region="us-east-1"
)

Advanced Registration

🔧 Generic Registration Method

Use the generic register_model() method for maximum flexibility.

PYTHON
from modelred import ModelRed, ModelProvider, ProviderConfig

async with ModelRed() as client:
    # Using ProviderConfig helper
    config = ProviderConfig.openai(
        api_key="sk-your-key",
        model_name="gpt-4",
        organization="org-123"
    )

    await client.register_model(
        model_id="generic-registration",
        provider=ModelProvider.OPENAI,
        provider_config=config,
        model_name="GPT-4 Production",
        metadata={
            "environment": "production",
            "team": "ai-safety",
            "cost_center": "research"
        }
    )

🔗 Custom REST APIs

Connect any REST API endpoint with flexible authentication and request formats.

PYTHON
from modelred import AuthType, RequestFormat

await client.register_custom_rest_model(
    model_id="my-custom-api",
    endpoint_url="https://api.mycompany.com/v1/chat",
    auth_type=AuthType.BEARER,
    auth_value="your-bearer-token",
    request_format=RequestFormat.OPENAI_COMPATIBLE,
    headers={"Custom-Header": "MyApp/1.0"},
    metadata={"internal": True}
)

Environment Variables

🔐 Using Environment Variables

Keep your API keys secure by using environment variables instead of hardcoding them.

Set Environment Variables

BASH

export MODELRED_API_KEY="mr_your_api_key"
export OPENAI_API_KEY="sk-your-openai-key"
export ANTHROPIC_API_KEY="sk-ant-your-key"

Use in Code

PYTHON

# API keys auto-loaded from environment
async with ModelRed() as client:
    await client.register_openai_model(
        model_id="production-gpt",
        model_name="gpt-4"
        # api_key loaded from OPENAI_API_KEY
    )

Metadata and Organization

📋 Model Metadata

Add metadata to organize and categorize your models effectively.

PYTHON
# Rich metadata for model organization
await client.register_openai_model(
    model_id="customer-service-bot",
    model_name="gpt-3.5-turbo",
    metadata={
        # Environment and deployment info
        "environment": "production",
        "version": "1.2.0",
        "deployed_at": "2024-01-15",

        # Team and ownership
        "team": "customer-experience",
        "owner": "jane.doe@company.com",
        "cost_center": "support",

        # Technical details
        "max_tokens": 4096,
        "temperature": 0.7,
        "use_case": "customer_support",

        # Business context
        "criticality": "high",
        "compliance_required": True,
        "languages": ["en", "es", "fr"]
    }
)

Batch Registration

Register Multiple Models

Efficiently register multiple models in a single script.

PYTHON
import asyncio
from modelred import ModelRed

async def register_all_models():
    async with ModelRed() as client:
        models_to_register = [
            {
                "method": client.register_openai_model,
                "args": {
                    "model_id": "prod-gpt-4",
                    "model_name": "gpt-4",
                    "metadata": {"env": "production"}
                }
            },
            {
                "method": client.register_anthropic_model,
                "args": {
                    "model_id": "dev-claude",
                    "model_name": "claude-3-sonnet-20240229",
                    "metadata": {"env": "development"}
                }
            },
            {
                "method": client.register_azure_model,
                "args": {
                    "model_id": "enterprise-azure",
                    "endpoint": "https://company.openai.azure.com/",
                    "deployment_name": "gpt-4",
                    "metadata": {"env": "enterprise"}
                }
            }
        ]

        for model_config in models_to_register:
            try:
                await model_config["method"](**model_config["args"])
                print(f"✅ Registered: {model_config['args']['model_id']}")
            except Exception as e:
                print(f"❌ Failed: {model_config['args']['model_id']} - {e}")

# Run the batch registration
asyncio.run(register_all_models())

Error Handling

⚠️ Common Registration Errors

Invalid API Key
AuthenticationError: Invalid API key
Solutions:
  • • Verify your API key is correct and active
  • • Check if the key has required permissions
  • • Ensure the key format matches the provider
Model Already Exists
ValidationError: Model with ID already exists
Solutions:
  • • Use a unique model_id for each registration
  • • Check existing models with list_models()
  • • Delete the old model first if updating
Model Limit Exceeded
QuotaExceededError: Model limit exceeded for your plan
Solutions:
  • • Check your current plan limits
  • • Delete unused models to free up slots
  • • Upgrade your plan for more model slots

Best Practices

💡 Registration Best Practices

Model ID Naming

Use descriptive, unique IDs
Include environment (prod, dev, test)
Use consistent naming patterns
Avoid special characters

Security & Organization

Use environment variables for keys
Add comprehensive metadata
Include ownership information
Document business context

Next Steps