OpenAI API Gateway
Dev Mode

Development mode features designed to accelerate local development, debugging, and testing. Enable verbose logging, mock responses, and bypass rate limits during development.

Verbose Logging

Detailed request/response logs

Mock Responses

Skip real API calls

Rate Limit Bypass

No throttling in dev

Error Simulation

Test error handling

Development Mode Features

Dev mode enables special features designed for local development and testing:

📝 Verbose Request Logging

Log full request headers, bodies, and response details for debugging API interactions and understanding data flow.

🎭 Mock Response Mode

Return pre-configured mock responses without calling real APIs, useful for offline development and predictable testing.

⚡ Unlimited Rate Limits

Disable or significantly increase rate limits during development to avoid interruptions while iterating on code.

🐛 Error Injection

Simulate API errors, timeouts, and failures to test error handling code paths and resilience patterns.

Configuration

Enabling Dev Mode

# Environment variable
GATEWAY_MODE=development

# Or in configuration file
mode: development
dev_features:
  verbose_logging: true
  mock_responses: false
  bypass_rate_limits: true

Complete Dev Configuration

Setting Description Default
verbose_logging Enable detailed request/response logging true
mock_responses Use mock responses instead of real API calls false
bypass_rate_limits Disable rate limiting checks true
error_injection_rate Percentage of requests to inject errors (0-100) 0
cache_bypass Skip response caching true
pretty_print_json Format JSON responses for readability true

Mock Response System

Configuring Mock Responses

mock_responses:
  enabled: true
  fallback_to_real: false
  
  responses:
    - endpoint: /v1/chat/completions
      method: POST
      response:
        id: "mock-chat-001"
        object: "chat.completion"
        choices:
          - message:
              role: "assistant"
              content: "This is a mock response"
            finish_reason: "stop"
    
    - endpoint: /v1/models
      method: GET
      response:
        object: "list"
        data:
          - id: "gpt-4-mock"
            object: "model"
            owned_by: "mock-system"

Dynamic Mock Responses

# Python mock handler
def mock_chat_completion(request):
    return {
        "id": f"mock-{request['model']}",
        "choices": [{
            "message": {
                "role": "assistant",
                "content": f"Mock response for: {request['messages'][-1]['content']}"
            }
        }]
    }

Debug Tools

Request Tracing

Enable request tracing to see the complete lifecycle of each API call:

tracing:
  enabled: true
  include_headers: true
  include_body: true
  max_body_size: 10000  # Characters

Example Debug Output

2025-03-16 10:23:45 [DEBUG] Incoming request:
  Method: POST
  Path: /v1/chat/completions
  Headers:
    Authorization: Bearer sk-test-...
    Content-Type: application/json
  Body: {"model":"gpt-4","messages":[...]}
  
2025-03-16 10:23:45 [DEBUG] Routing to provider: openai
2025-03-16 10:23:45 [DEBUG] Provider request:
  URL: https://api.openai.com/v1/chat/completions
  Headers: {...}
  
2025-03-16 10:23:47 [DEBUG] Provider response:
  Status: 200 OK
  Latency: 1.82s
  Body: {"id":"chatcmpl-...","choices":[...]}

Error Injection Testing

error_injection:
  enabled: true
  rate: 10  # Inject errors in 10% of requests
  errors:
    - type: rate_limit_exceeded
      probability: 0.4
    - type: timeout
      probability: 0.3
    - type: server_error
      probability: 0.3
Never Enable in Production Dev mode features like rate limit bypass, error injection, and mock responses should never be enabled in production environments. Always use environment-specific configurations.

Performance Profiling

Enable Performance Metrics

profiling:
  enabled: true
  track_memory: true
  track_cpu: true
  slow_request_threshold: 1000  # ms
  
  # Export metrics
  export:
    format: prometheus
    endpoint: /metrics

Performance Dashboard

Access the built-in performance dashboard at http://localhost:9090/dashboard when dev mode is enabled to view:

Partner Resources