pub struct OpenAI { /* private fields */ }Expand description
OpenAI model backed by the Responses API by default, with legacy
chat.completions support for compatibility.
Implementations§
Source§impl OpenAI
impl OpenAI
Sourcepub fn new(api_key: impl Into<String>) -> OpenAI
pub fn new(api_key: impl Into<String>) -> OpenAI
Create a new client using the provided API key and default model.
Sourcepub fn deepseek(api_key: impl Into<String>) -> OpenAI
pub fn deepseek(api_key: impl Into<String>) -> OpenAI
Create a client configured for Deepseek’s OpenAI-compatible endpoint.
Sourcepub fn openrouter(api_key: impl Into<String>) -> OpenAI
pub fn openrouter(api_key: impl Into<String>) -> OpenAI
Create a client configured for OpenRouter’s OpenAI-compatible endpoint.
Sourcepub fn builder(api_key: impl Into<String>) -> Builder
pub fn builder(api_key: impl Into<String>) -> Builder
Start building an OpenAI client with custom configuration.
Sourcepub fn with_model(self, model: impl Into<String>) -> OpenAI
pub fn with_model(self, model: impl Into<String>) -> OpenAI
Override the default chat model in-place.
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> OpenAI
pub fn with_base_url(self, base_url: impl Into<String>) -> OpenAI
Override the REST base URL (useful for OpenAI-compatible endpoints).
Sourcepub fn with_responses_api(self) -> OpenAI
pub fn with_responses_api(self) -> OpenAI
Use the recommended Responses API.
Sourcepub fn with_chat_completions_api(self) -> OpenAI
pub fn with_chat_completions_api(self) -> OpenAI
Use the legacy Chat Completions API (deprecated by OpenAI).
Sourcepub fn with_legacy_max_tokens(self, enabled: bool) -> OpenAI
pub fn with_legacy_max_tokens(self, enabled: bool) -> OpenAI
Send deprecated max_tokens alongside max_completion_tokens for compatibility.
OpenAI deprecates max_tokens and it is incompatible with reasoning models.
Sourcepub fn with_embedding_model(self, model: impl Into<String>) -> OpenAI
pub fn with_embedding_model(self, model: impl Into<String>) -> OpenAI
Override the embeddings model identifier.
Sourcepub fn with_embedding_dimensions(self, dimensions: usize) -> OpenAI
pub fn with_embedding_dimensions(self, dimensions: usize) -> OpenAI
Override the embedding dimension (defaults depend on model).
Sourcepub fn with_image_model(self, model: impl Into<String>) -> OpenAI
pub fn with_image_model(self, model: impl Into<String>) -> OpenAI
Override the image generation model identifier.
Sourcepub fn with_audio_model(self, model: impl Into<String>) -> OpenAI
pub fn with_audio_model(self, model: impl Into<String>) -> OpenAI
Override the default text-to-speech model identifier.
Sourcepub fn with_audio_voice(self, voice: impl Into<String>) -> OpenAI
pub fn with_audio_voice(self, voice: impl Into<String>) -> OpenAI
Set the default text-to-speech voice (e.g., alloy).
Sourcepub fn with_audio_format(self, format: impl Into<String>) -> OpenAI
pub fn with_audio_format(self, format: impl Into<String>) -> OpenAI
Set the preferred audio format (mp3, wav, flac).
Sourcepub fn with_transcription_model(self, model: impl Into<String>) -> OpenAI
pub fn with_transcription_model(self, model: impl Into<String>) -> OpenAI
Override the transcription model identifier.
Sourcepub fn with_moderation_model(self, model: impl Into<String>) -> OpenAI
pub fn with_moderation_model(self, model: impl Into<String>) -> OpenAI
Override the moderation model identifier.