Provider Architecture
Every provider integration follows a consistent structure:Provider Config Interface
Each provider exports aProviderConfigs object:
src/providers/openai/index.ts:50-103
Request Flow
When a request comes in, the gateway:- Validates the request using the request validator middleware
- Parses the config to determine the provider and routing strategy
- Selects a provider based on the routing mode (single, loadbalance, fallback, conditional)
- Transforms the request from OpenAI format to provider-specific format
- Constructs headers with provider-specific authentication
- Makes the request to the provider’s API
- Transforms the response back to OpenAI-compatible format
- Returns the response to the client
Request Transformation
The gateway transforms OpenAI-format requests to provider-specific formats:Header Transformation
Each provider defines how to map authentication and metadata:api.ts file and assembled by constructRequestHeaders().
Source: src/handlers/handlerUtils.ts:78-159
Body Transformation
Request bodies are transformed from OpenAI format to provider format:- Model name mapping
- Required vs optional parameters
- Provider-specific defaults
- Format differences (arrays vs objects)
Content Type Handling
The gateway supports multiple content types:- JSON - Standard request/response format
- Multipart Form Data - For file uploads (images, audio)
- Streaming - Server-sent events for real-time responses
- Binary - For audio and image data
src/handlers/handlerUtils.ts:41-76
Response Transformation
Provider responses are transformed back to OpenAI-compatible format:Streaming Transformations
For streaming responses, the gateway transforms each chunk:Provider-Specific Features
OpenAI
- Organization & Project Headers - Pass org and project IDs
- Beta Features - Support for assistants, threads, etc.
- Function Calling - Full function and tool support
- Vision - Image analysis in chat completions
Anthropic
- Thinking Mode - Extended reasoning responses
- System Prompts - Separate system message handling
- Message Streaming - Native streaming events
- Vision - Image analysis with base64 or URLs
Azure OpenAI
- Deployment IDs - Map to specific model deployments
- API Versions - Version-specific endpoints
- Auth Modes - API key, Managed Identity, Entra ID
- Content Filtering - Azure-specific content filters
Google Vertex AI
- Service Account Auth - JSON key authentication
- Project & Region - Required configuration
- Safety Settings - Content safety filters
- Function Calling - Google-specific function format
AWS Bedrock
- IAM Authentication - AWS signature v4 signing
- Model IDs - Provider-specific model identifiers
- Streaming - Event stream parsing
- Cross-region - Support for multiple AWS regions
Custom Providers
For providers with OpenAI-compatible APIs, you can use the proxy mode:Provider Selection Logic
The gateway selects providers based on the routing strategy:Single Provider
Load Balanced Providers
src/handlers/handlerUtils.ts:204-231
Fallback Providers
Providers are tried sequentially until one succeeds:src/handlers/handlerUtils.ts:663-690
URL Construction
Each provider defines its base URL and endpoint patterns:Error Handling
Providers handle errors consistently:- HTTP Errors - Propagated with original status codes
- Transformation Errors - Wrapped in gateway error format
- Provider-Specific Errors - Normalized to OpenAI error format
Supported Endpoints
Providers can support various endpoints:- chatComplete - Chat completions
- complete - Text completions
- embed - Embeddings generation
- imageGenerate - Image generation
- imageEdit - Image editing
- createSpeech - Text-to-speech
- createTranscription - Speech-to-text
- createTranslation - Audio translation
- uploadFile - File uploads
- createBatch - Batch processing
- createFinetune - Fine-tuning jobs
Best Practices
Test Provider Compatibility
Test your use case with each provider as API behaviors may differ.
Use Fallbacks
Configure fallback providers to handle API outages gracefully.
Monitor Provider Performance
Track latency and error rates per provider to optimize routing.
Handle Provider Limits
Be aware of rate limits and token limits per provider.
Next Steps
Routing
Learn about routing strategies for providers.
Supported Providers
View the complete list of supported providers.
Load Balancing
Distribute load across multiple providers.
Configs
Configure provider settings and parameters.