OpenAI Gateway
Connect directly to the OpenAI API
The OpenAI gateway connects ChatJS directly to the OpenAI API using the @ai-sdk/openai provider SDK. Use this when you only need OpenAI models and want the simplest setup with type-safe model IDs.
Setup
- Follow the OpenAI quickstart to create an API key
- Add to
.env.local:
OPENAI_API_KEY=sk-...
- Set the gateway in your config:
const config: ConfigInput = {
ai: {
gateway: "openai",
workflows: {
chat: "gpt-5-mini",
title: "gpt-5-nano",
// ...
},
// ...
},
};
Authentication
| Variable | Description |
|---|---|
OPENAI_API_KEY |
Required. Your OpenAI API key |
Available Models
All models available to your API key (GPT, DALL-E, and embedding models). The full list is fetched at runtime and cached for 1 hour.
Model IDs
Unlike the Vercel and OpenRouter gateways which use provider/model format, the OpenAI gateway uses bare model IDs since all models come from OpenAI:
gpt-5-minigpt-5-nanogpt-4oo3-mini
The gateway provides type-safe model IDs extracted from the @ai-sdk/openai SDK, giving you autocomplete in chat.config.ts.
Image Generation
The OpenAI gateway supports dedicated image models through createImageModel():
gpt-image-1gpt-image-1.5dall-e-3
This enables the built-in Image Generation feature.
Related
- Gateways Overview for the full gateway comparison
- Vercel Gateway for multi-provider access via a single key