Overview
The OpenAI provider gives you access to OpenAI’s models including GPT-5, GPT-4, o-series reasoning models, embeddings, and DALL-E image generation.Installation
createOpenAI()
Create an OpenAI provider instance.Options
Your OpenAI API key. Defaults to
OPENAI_API_KEY environment variable.Custom base URL for API requests. Useful for proxies or OpenAI-compatible APIs.
Provide your own configured OpenAI client instance.
Returns
OpenAIProvider - Provider instance with methods to create models.
Provider Methods
chatModel()
Create a chat model instance.Model identifier. See Supported Models below.
embeddingModel()
Create an embedding model instance.Embedding model identifier (e.g.,
text-embedding-3-small, text-embedding-3-large).imageModel()
Create an image generation model instance.Image model identifier (e.g.,
dall-e-2, dall-e-3).Supported Models
Chat Models
GPT-5 Series
GPT-5 Series
- gpt-5.2 - Latest flagship model with max reasoning effort
- gpt-5.2-codex - Optimized for code generation
- gpt-5.2-pro - Enhanced reasoning capabilities
- gpt-5.1 - Previous generation flagship
- gpt-5 - Balanced performance and cost
- gpt-5-mini - Fast and efficient
- gpt-5-nano - Lightweight model
o-Series (Reasoning Models)
o-Series (Reasoning Models)
- o4-mini - Latest compact reasoning model
- o3 - Advanced reasoning capabilities
- o3-mini - Efficient reasoning model
- o1 - First-generation reasoning model
- o1-mini - Compact reasoning model (no effort control)
GPT-4 Series
GPT-4 Series
- gpt-4 - Previous flagship model
- gpt-4-turbo - Faster GPT-4 variant
- gpt-4o - Optimized GPT-4
Embedding Models
- text-embedding-3-large - 3072 dimensions, highest quality
- text-embedding-3-small - 1536 dimensions, faster and cheaper
- text-embedding-ada-002 - Legacy embedding model
Image Models
- dall-e-3 - Latest image generation model
- dall-e-2 - Previous generation
Capabilities
| Feature | Support |
|---|---|
| Chat Completion | ✓ |
| Streaming | ✓ |
| Function Calling | ✓ |
| Vision | ✓ |
| Reasoning Effort | ✓ (model-dependent) |
| Embeddings | ✓ |
| Image Generation | ✓ |
Examples
Basic Chat
Reasoning with Effort Control
Embeddings
Image Generation
Custom Base URL (OpenAI-compatible APIs)
Reasoning Effort
OpenAI models support different reasoning effort levels:- minimal - Fastest, least reasoning
- low - Quick responses with basic reasoning
- medium - Balanced reasoning and speed
- high - Deep reasoning for complex problems
- max - Maximum reasoning effort (GPT-5.2 series only)
Some models restrict sampling parameters when using reasoning effort. The SDK handles this automatically.
Error Handling
Related
Anthropic Provider
Claude models with extended thinking
Google GenAI Provider
Gemini models with multimodal capabilities
Core AI Functions
Learn about generate, stream, and more