Documentation

Anthropic Claude

Integrate Anthropic Claude models with ModelRed

🔮

Anthropic Claude Models

Test Claude's safety-first AI with ModelRed's comprehensive security assessments. Built-in Constitutional AI provides advanced safety mechanisms.

Quick Setup

Get Started in 3 Steps

Set up your Claude model for security testing quickly.

1

Get Your API Key

Visit Anthropic Console and create an API key.

sk-ant-api03-...
2

Set Environment Variable

BASH
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
3

Register Your Model

PYTHON
from modelred import ModelRed

async with ModelRed() as client:
    await client.register_anthropic_model(
        model_id="my-claude",
        api_key="sk-ant-your-key",  # or use env var
        model_name="claude-3-sonnet-20240229"
    )

Claude Models

Claude Haiku

Fast and affordable for simple tasks

Fastest200K Context
🎯

Claude Sonnet

Balanced performance for most use cases

Recommended200K Context
🧠

Claude Opus

Most capable for complex reasoning

Premium200K Context

Configuration Options

Advanced Setup

Additional configuration options for different Claude models.

🔧

Multiple Models

PYTHON
# Register different Claude variants
models = [
    ("claude-haiku", "claude-3-haiku-20240307"),
    ("claude-sonnet", "claude-3-sonnet-20240229"),
    ("claude-opus", "claude-3-opus-20240229")
]

for model_id, model_name in models:
    await client.register_anthropic_model(
        model_id=model_id,
        model_name=model_name
    )
📊

With Metadata

PYTHON
await client.register_anthropic_model(
    model_id="claude-production",
    model_name="claude-3-sonnet-20240229",
    metadata={
        "use_case": "content_moderation",
        "team": "ai-safety",
        "version": "3.0"
    }
)

Common Issues

⚠️ Troubleshooting

Invalid API Key
AuthenticationError: Invalid API key
Solutions:
  • • Verify key starts with 'sk-ant-'
  • • Check key in Anthropic Console
  • • Ensure account has credits
Model Not Available
Model 'claude-3-xyz' not found
Solutions:
  • • Use exact model names from Anthropic docs
  • • Check model availability in your region
  • • Try 'claude-3-sonnet-20240229' (widely available)
Rate Limit Exceeded
RateLimitError: Too many requests
Solutions:
  • • Wait before retrying requests
  • • Check your rate limits in Console
  • • Consider upgrading your plan

Quick Test

Verify Your Setup

Run this test to confirm your Claude integration is working:

PYTHON
import asyncio
from modelred import ModelRed

async def test_claude():
    async with ModelRed() as client:
        # Register Claude model
        await client.register_anthropic_model(
            model_id="test-claude",
            model_name="claude-3-sonnet-20240229"
        )
        print("✅ Claude model registered!")

        # Run security test
        result = await client.run_assessment(
            model_id="test-claude",
            test_suites=["basic_security", "content_safety"]
        )
        print(f"🔍 Assessment started: {result.assessment_id}")

asyncio.run(test_claude())

Claude vs GPT

⚖️ Security Testing Comparison

Claude Advantages

Built-in Constitutional AI safety

200K context for long documents

Strong refusal patterns

Excellent safety benchmarks

Best For Testing

Content moderation systems

Safety mechanism validation

Constitutional AI testing

Long context security

Next Steps