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.
Trait Implementations§
Source§impl AudioGenerator for OpenAI
impl AudioGenerator for OpenAI
Source§impl AudioTranscriber for OpenAI
impl AudioTranscriber for OpenAI
Source§impl EmbeddingModel for OpenAI
impl EmbeddingModel for OpenAI
Source§impl From<OpenAI> for CloudEmbedder
impl From<OpenAI> for CloudEmbedder
Source§impl From<OpenAI> for CloudProvider
impl From<OpenAI> for CloudProvider
Source§impl ImageGenerator for OpenAI
impl ImageGenerator for OpenAI
Source§impl LanguageModel for OpenAI
impl LanguageModel for OpenAI
Source§type Error = OpenAIError
type Error = OpenAIError
Source§fn respond(
&self,
request: LLMRequest,
) -> impl Stream<Item = Result<Event, <OpenAI as LanguageModel>::Error>> + Send
fn respond( &self, request: LLMRequest, ) -> impl Stream<Item = Result<Event, <OpenAI as LanguageModel>::Error>> + Send
Source§fn complete(
&self,
prefix: &str,
) -> impl Stream<Item = Result<Event, <OpenAI as LanguageModel>::Error>> + Send
fn complete( &self, prefix: &str, ) -> impl Stream<Item = Result<Event, <OpenAI as LanguageModel>::Error>> + Send
Source§fn profile(&self) -> impl Future<Output = Profile> + Send
fn profile(&self) -> impl Future<Output = Profile> + Send
Source§fn respond_with_tools(
&self,
request: LLMRequestWithTools<'_>,
) -> impl Stream<Item = Result<Event, Self::Error>> + Send
fn respond_with_tools( &self, request: LLMRequestWithTools<'_>, ) -> impl Stream<Item = Result<Event, Self::Error>> + Send
Source§fn generate<T>(
&self,
request: LLMRequest,
) -> impl Future<Output = Result<T, GenerateError<Self::Error>>> + Sendwhere
T: JsonSchema + DeserializeOwned + 'static,
fn generate<T>(
&self,
request: LLMRequest,
) -> impl Future<Output = Result<T, GenerateError<Self::Error>>> + Sendwhere
T: JsonSchema + DeserializeOwned + 'static,
Source§fn summarize(
&self,
text: &str,
) -> impl Stream<Item = Result<Event, Self::Error>> + Send
fn summarize( &self, text: &str, ) -> impl Stream<Item = Result<Event, Self::Error>> + Send
Source§fn categorize<T>(
&self,
text: &str,
) -> impl Future<Output = Result<T, GenerateError<Self::Error>>> + Sendwhere
T: JsonSchema + DeserializeOwned + 'static,
fn categorize<T>(
&self,
text: &str,
) -> impl Future<Output = Result<T, GenerateError<Self::Error>>> + Sendwhere
T: JsonSchema + DeserializeOwned + 'static,
Source§impl Moderation for OpenAI
impl Moderation for OpenAI
Auto Trait Implementations§
impl Freeze for OpenAI
impl RefUnwindSafe for OpenAI
impl Send for OpenAI
impl Sync for OpenAI
impl Unpin for OpenAI
impl UnsafeUnpin for OpenAI
impl UnwindSafe for OpenAI
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more