Documentation

OpenAI

Integrate OpenAI GPT models with ModelRed

🤖

OpenAI GPT Models

Connect your OpenAI GPT models to ModelRed for comprehensive security testing. Supports all GPT models and OpenAI-compatible APIs.

Quick Setup

Get Started in 3 Steps

Set up your OpenAI model for security testing in minutes.

1

Get Your API Key

Visit OpenAI Platform and create an API key.

sk-proj-... or sk-...
2

Set Environment Variable

BASH
export OPENAI_API_KEY="sk-your-openai-key-here"
3

Register Your Model

PYTHON
from modelred import ModelRed

async with ModelRed() as client:
    await client.register_openai_model(
        model_id="my-chatbot",
        api_key="sk-your-key",  # or use env var
        model_name="gpt-3.5-turbo"
    )

GPT-3.5 Turbo

Fast, affordable, great for development

Recommended16K Context
🧠

GPT-4

Most capable reasoning, best for production

Premium8K Context
🚀

GPT-4 Turbo

Large context, optimized performance

Latest128K Context

Configuration Options

Advanced Setup

Additional configuration options for specific use cases.

🔧

With Organization

PYTHON
await client.register_openai_model(
    model_id="org-model",
    api_key="sk-your-key",
    model_name="gpt-4",
    organization="org-your-org-id"
)
🔗

Custom Endpoint

PYTHON
await client.register_openai_model(
    model_id="custom-model",
    api_key="sk-your-key",
    base_url="https://api.custom.com/v1",
    model_name="custom-gpt"
)

Common Issues

⚠️ Troubleshooting

Invalid API Key
AuthenticationError: Invalid API key
Solutions:
  • • Verify key starts with 'sk-'
  • • Check key hasn't been revoked
  • • Ensure sufficient credits in account
Rate Limit Exceeded
RateLimitError: Too many requests
Solutions:
  • • Wait before retrying
  • • Upgrade OpenAI tier for higher limits
  • • Use GPT-3.5-turbo (higher limits)
Model Not Available
Model 'gpt-4' not found
Solutions:
  • • Check model availability in OpenAI dashboard
  • • Use 'gpt-3.5-turbo' (widely available)
  • • Request GPT-4 access from OpenAI

Quick Test

Verify Your Setup

Run this test to confirm your OpenAI integration is working:

PYTHON
import asyncio
from modelred import ModelRed

async def test_openai():
    async with ModelRed() as client:
        # Register model
        await client.register_openai_model(
            model_id="test-model",
            model_name="gpt-3.5-turbo"
        )
        print("✅ OpenAI model registered!")

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

asyncio.run(test_openai())

Next Steps