Use OpenAI models through the AI Gateway with automatic fallback to AWS Bedrock.
- GPT-4o completion - Full chat completion
- Streaming - Token-by-token output with GPT-4o-mini
- Embeddings - Vector embeddings with text-embedding-3-small
- Fallback pattern - Try Bedrock first, fall back to OpenAI on failure
- A running AI Gateway with the OpenAI provider configured (requires
OPENAI_API_KEYon the gateway) - Node.js 18+
pnpm install
cp .env.example .env
# Edit .env with your gateway URL and API key
pnpm startThe fallback example demonstrates a common production pattern:
Request -> Bedrock (primary, no external API key cost)
-> fails
OpenAI (secondary, external provider)
This keeps costs low by defaulting to Bedrock while ensuring availability through OpenAI as a backup. The gateway handles provider-specific translation - your request format stays the same.