AI::OpenAI::OpenAIProvider
Inherits AI::Provider::Provider::V3 < Reference < Object
OpenAI provider.
Provides factory methods for creating OpenAI models:
chat- Chat completion models (gpt-4o, gpt-4, gpt-3.5-turbo, etc.)embedding- Embedding models (text-embedding-3-small/large)image- Image generation models (dall-e-2, dall-e-3, gpt-image-1)speech- Text-to-speech models (tts-1, tts-1-hd, gpt-4o-mini-tts)transcription- Speech-to-text models (whisper-1, gpt-4o-transcribe)
Example:
provider = AI::OpenAI.create_openai(api_key: "sk-...")
model = provider.chat("gpt-4o")
result = model.do_generate(options)
Constructors
Instance methods
Creates a chat model for text generation.
Supports all OpenAI chat models including:
- gpt-4o, gpt-4o-mini
- gpt-4-turbo, gpt-4
- gpt-3.5-turbo
- o1, o1-mini, o1-preview
- o3, o3-mini
- o4-mini
- gpt-5, gpt-5-mini
Creates an embedding model.
Supports:
- text-embedding-3-small
- text-embedding-3-large
- text-embedding-ada-002
Creates an image model.
Supports:
- dall-e-2
- dall-e-3
- gpt-image-1
Alias for chat - creates a language model.
By default, returns a chat model. Use the chat method
explicitly for chat completion models.
Creates a responses model for GPT-5, o3, o4-mini, etc.
The Responses API provides advanced features like:
- MCP (Model Context Protocol) integration
- Shell/LocalShell execution
- ApplyPatch for code editing
- Image generation tool
- File search with vector stores
- Code interpreter
- Web search with citations
Supports:
- gpt-5, gpt-5-mini, gpt-5-nano, gpt-5-pro
- gpt-5.1, gpt-5.2
- o3, o3-mini, o4-mini
- gpt-4.1, gpt-4.1-mini, gpt-4.1-nano
- gpt-4o, gpt-4o-mini
Creates a speech model for text-to-speech synthesis.
Supports:
- tts-1 - Fast text-to-speech model
- tts-1-hd - High-definition text-to-speech model
- gpt-4o-mini-tts - GPT-4o mini text-to-speech model
Example:
speech_model = provider.speech("tts-1")
result = speech_model.do_generate(
AI::Provider::SpeechModel::CallOptions.new(
text: "Hello, world!",
voice: "alloy"
)
)
File.write("output.mp3", result.audio)
Deprecated: Use embedding_model instead.
Access to OpenAI-specific tools.
Returns the Tools module containing provider-defined tools like:
- WebSearch
- CodeInterpreter
- FileSearch
- ImageGeneration
- Shell
- LocalShell
- ApplyPatch
- Mcp
Creates a transcription model for speech-to-text.
Supports:
- whisper-1 - Whisper transcription model
- gpt-4o-mini-transcribe - GPT-4o mini transcription model
- gpt-4o-transcribe - GPT-4o transcription model
Example:
transcription_model = provider.transcription("whisper-1")
result = transcription_model.do_generate(
AI::Provider::TranscriptionModel::CallOptions.new(
audio: File.read("audio.mp3").to_slice,
media_type: "audio/mp3"
)
)
puts result.text