Skip to main content

What is the AI Gateway?

The AI Gateway is RegPilot’s intelligent proxy layer that sits between your application and AI providers (OpenAI, Anthropic, etc.). It automatically validates, monitors, and logs all AI interactions for compliance. AI Gateway Flow

Key Benefits

Automatic Compliance

Every AI response is validated against EU AI Act requirements automatically

Cost Tracking

Monitor AI usage and costs across all models in a single dashboard

Risk Management

Detect and block high-risk content before it reaches users

Audit Trail

Complete logging of all AI interactions for regulatory compliance

How It Works

1

Your Application Sends Request

Your app sends an AI request to RegPilot Gateway instead of directly to OpenAI/Anthropic
const response = await fetch('https://regpilot.dev/api/ai/chat', {
  headers: { 'X-API-Key': process.env.REGPILOT_API_KEY },
  method: 'POST',
  body: JSON.stringify({
    messages: [{ role: 'user', content: 'User question' }]
  })
});
2

RegPilot Validates & Routes

The Gateway:
  • Validates your API key
  • Checks compliance settings
  • Routes to appropriate AI provider
  • Applies Governor validation if enabled
3

AI Provider Responds

The AI model (GPT-4, Claude, etc.) processes the request and returns a response
4

Compliance Check & Logging

RegPilot:
  • Validates response for compliance violations
  • Logs the interaction
  • Tracks usage and costs
  • Returns sanitized response to your app

Features

Real-time Monitoring

Track all AI interactions in real-time:
  • Request/Response Logs: Complete audit trail
  • Usage Statistics: Token counts and costs
  • Performance Metrics: Latency and success rates
  • Error Tracking: Failed requests and reasons

Cost Management

Understand and control AI spending:
Single dashboard for all AI provider costs. Track spending across OpenAI, Anthropic, and custom models.
Set spending limits and receive alerts when approaching thresholds.
Tag requests by feature, user, or department for detailed cost analysis.

Governor Integration

Enable the Governor feature for advanced compliance:
const response = await fetch('https://regpilot.dev/api/ai/chat', {
  headers: { 'X-API-Key': process.env.REGPILOT_API_KEY },
  method: 'POST',
  body: JSON.stringify({
    messages: [{ role: 'user', content: 'Process refund denial' }],
    // Enable Governor validation
    governorMetadata: {
      actionType: 'refund_denial',
      recipientCountry: 'DE',
      senderId: 'support_agent_123'
    }
  })
});

// Response includes compliance headers
console.log(response.headers.get('X-Governor-Risk-Score')); // 25
console.log(response.headers.get('X-Governor-Validated')); // true

Supported AI Providers

  • OpenAI
  • Anthropic
  • Custom Models
  • GPT-4, GPT-4 Turbo
  • GPT-3.5 Turbo
  • DALL-E 3
  • Whisper
  • Text Embeddings

API Endpoints

The AI Gateway provides multiple endpoints for different use cases:
EndpointPurposeStreaming
/api/ai/chatChat completions✅ Yes
/api/ai/chat-v2Enhanced chat with Governor✅ Yes
/api/ai/completeText completions❌ No
/api/ai/embeddingsText embeddings❌ No

Quick Start

1

Create API Key

Navigate to AI Gateway → Overview and create a new API key
2

Make Your First Request

curl -X POST https://regpilot.dev/api/ai/chat \
  -H "X-API-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'
3

View Analytics

Check your dashboard to see request logs, costs, and compliance scores

Advanced Configuration

Request Headers

Customize AI Gateway behavior with request headers:
const response = await fetch('https://regpilot.dev/api/ai/chat', {
  headers: {
    'X-API-Key': process.env.REGPILOT_API_KEY,
    'Content-Type': 'application/json',
    
    // Optional headers
    'X-RegPilot-Model': 'gpt-4-turbo',        // Force specific model
    'X-RegPilot-Temperature': '0.7',          // Override temperature
    'X-RegPilot-Max-Tokens': '2000',          // Set max tokens
    'X-RegPilot-User-ID': 'user_123',         // Track by user
    'X-RegPilot-Feature': 'chat_support',     // Tag by feature
  },
  body: JSON.stringify({ messages: [...] })
});

Response Headers

Every AI Gateway response includes compliance metadata:
// Check response headers
const riskScore = response.headers.get('X-Governor-Risk-Score');
const validated = response.headers.get('X-Governor-Validated');
const violations = response.headers.get('X-Governor-Violations');
const auditId = response.headers.get('X-Governor-Audit-Id');

console.log(`Risk: ${riskScore}/100, Validated: ${validated}`);

Compliance Features

Automatic Violation Detection

The Gateway automatically detects:
  • Personal Data Exposure: GDPR violations
  • Discriminatory Content: EU AI Act bias requirements
  • Financial Advice: Regulatory compliance
  • Medical Information: Healthcare regulations
  • Age-Inappropriate Content: Child safety laws

Audit Logging

Every request is logged with:
  • Request/response content
  • Timestamp and duration
  • User and session identifiers
  • Compliance validation results
  • Governor risk scores
Access audit logs in AI Gateway → Logs or via API.

Best Practices

Enable streaming for chat interfaces to show responses as they’re generated:
const response = await fetch('https://regpilot.dev/api/ai/chat', {
  headers: { 'X-API-Key': apiKey },
  method: 'POST',
  body: JSON.stringify({
    messages: [...],
    stream: true  // Enable streaming
  })
});

const reader = response.body.getReader();
// Process stream chunks...
Handle transient failures with exponential backoff:
async function chatWithRetry(messages, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      return await regpilot.chat.create({ messages });
    } catch (error) {
      if (i === retries - 1) throw error;
      await new Promise(r => setTimeout(r, Math.pow(2, i) * 1000));
    }
  }
}
Track latency and error rates:
  • Set up alerts for high error rates
  • Monitor P95/P99 latency
  • Track success rates per model
  • Review cost trends weekly

Next Steps