pub struct OpenAIModel { /* private fields */ }Expand description
A model on the OpenAI Responses or Chat Completions API (OpenAIModel).
Cheap to clone and to share as Arc<dyn Model>: clones share one configuration and one HTTP
client, so update_config on any clone changes them all.
Implementations§
Source§impl OpenAIModel
impl OpenAIModel
Sourcepub fn bedrock_mantle(
options: impl Into<OpenAIModelOptions>,
mantle_config: BedrockMantleConfig,
) -> Result<Self>
pub fn bedrock_mantle( options: impl Into<OpenAIModelOptions>, mantle_config: BedrockMantleConfig, ) -> Result<Self>
Creates a model that routes through Amazon Bedrock’s OpenAI-compatible Mantle endpoint.
The base URL follows the region and the model’s base path, and the API key mints a fresh SigV4 bearer token for every request.
use strands::models::openai::{BedrockMantleConfig, OpenAIModel, OpenAIModelOptions};
let model = OpenAIModel::bedrock_mantle(
OpenAIModelOptions::builder().model_id("openai.gpt-oss-120b").build_options(),
BedrockMantleConfig::builder().region("us-east-1").build(),
)?;§Errors
Fails when options sets api_key or client_config.base_url, which the Mantle config
sets instead, when the region is missing or malformed, when params is not a JSON object,
or when the HTTP client cannot be built.
Source§impl OpenAIModel
impl OpenAIModel
Sourcepub fn builder() -> OpenAIModelOptionsBuilder
pub fn builder() -> OpenAIModelOptionsBuilder
Starts building a model from OpenAIModelOptions fields.
Sourcepub fn new(options: impl Into<OpenAIModelOptions>) -> Result<Self>
pub fn new(options: impl Into<OpenAIModelOptions>) -> Result<Self>
Creates the model from options or a bare model configuration.
Logs a one-time warning when model_id falls back to its default, and a warning for each
provider-managed key in params.
§Errors
Fails when params is not a JSON object, when there is no API key in the options or
OPENAI_API_KEY, or when the HTTP client cannot be built (an invalid base URL or header).
Sourcepub fn config(&self) -> OpenAIModelConfig
pub fn config(&self) -> OpenAIModelConfig
The configuration, with context_window_limit filled from the model info when unset.
model_id stays unset when the default is used; Model::model_id reports the id requests
send.
Sourcepub fn update_config(&self, config: impl Into<OpenAIModelConfig>) -> Result<()>
pub fn update_config(&self, config: impl Into<OpenAIModelConfig>) -> Result<()>
Merges config into the configuration: every field it sets replaces the current value.
Takes a BaseModelConfig too.
stateful is construction-only: it is ignored with a warning, since changing it would break
the agent’s history handling and previous_response_id chaining. On a
bedrock_mantle model, a model_id on the other base path rebuilds
the client against the new base URL.
§Errors
Fails, leaving the configuration unchanged, when params is not a JSON object or the
rebuilt Mantle client cannot be built.
Trait Implementations§
Source§impl Clone for OpenAIModel
impl Clone for OpenAIModel
Source§impl Debug for OpenAIModel
impl Debug for OpenAIModel
Source§impl Model for OpenAIModel
impl Model for OpenAIModel
Source§fn model_id(&self) -> Option<String>
fn model_id(&self) -> Option<String>
The configured model id, else the default one requests send.
Source§fn model_info(&self) -> ModelInfo
fn model_info(&self) -> ModelInfo
The shared model info with server-side summaries off and stateful set for a Responses
model built with stateful: true; the model_info override wins.
Source§fn stream(
&self,
request: ModelRequest,
) -> BoxStream<'static, Result<ModelStreamEvent>>
fn stream( &self, request: ModelRequest, ) -> BoxStream<'static, Result<ModelStreamEvent>>
request as raw events. Read moreSource§fn get_config(&self) -> BaseModelConfig
fn get_config(&self) -> BaseModelConfig
Source§fn update_config(&self, config: BaseModelConfig) -> Result<()>
fn update_config(&self, config: BaseModelConfig) -> Result<()>
config into the configuration: every field it sets replaces the current value
(BaseModelConfig::merge). Read moreSource§fn stream_aggregated(
&self,
request: ModelRequest,
) -> BoxStream<'static, Result<AggregatedEvent>>
fn stream_aggregated( &self, request: ModelRequest, ) -> BoxStream<'static, Result<AggregatedEvent>>
Source§fn stateful(&self) -> bool
fn stateful(&self) -> bool
stateful), from
model_info().capabilities.stateful; false when unknown. Read moreSource§fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: CountTokensOptions,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn count_tokens<'life0, 'life1, 'async_trait>(
&'life0 self,
messages: &'life1 [Message],
options: CountTokensOptions,
) -> Pin<Box<dyn Future<Output = Result<u64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for OpenAIModel
impl RefUnwindSafe for OpenAIModel
impl Send for OpenAIModel
impl Sync for OpenAIModel
impl Unpin for OpenAIModel
impl UnsafeUnpin for OpenAIModel
impl UnwindSafe for OpenAIModel
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,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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