Expand description
The OpenAI provider, behind the openai feature.
OpenAIModel streams from the Responses API by default, or from Chat Completions with
OpenAIApi::Chat, over HTTP with the official OpenAI SDK’s transport behaviour (retries,
timeout, error texts). It maps every content block, the system prompt, tool specs and tool
choice, prompt caching (CacheConfig), server-managed conversation state on the Responses API
(OpenAIModelConfig::stateful) and OpenAI’s built-in tools, such as the native web_search,
through OpenAIModelConfig::params. With the mantle feature,
OpenAIModel::bedrock_mantle routes the model through Amazon Bedrock’s OpenAI-compatible
Mantle endpoint.
use strands::models::openai::{OpenAIApi, OpenAIModel};
use strands::models::Model;
// Responses API (default)
let model = OpenAIModel::builder().model_id("gpt-5.4").api_key("sk-...").build()?;
assert_eq!(model.model_id().as_deref(), Some("gpt-5.4"));
// Chat Completions
let chat = OpenAIModel::builder()
.api(OpenAIApi::Chat)
.model_id("gpt-5.4")
.api_key("sk-...")
.build()?;
assert_eq!(chat.api(), OpenAIApi::Chat);An agent on the Responses API with the built-in web search (the API key comes from
OPENAI_API_KEY):
use serde_json::json;
use strands::Agent;
use strands::models::openai::OpenAIModel;
let model = OpenAIModel::builder()
.model_id("gpt-5.4")
.params(json!({"tools": [{"type": "web_search"}]}))
.build()?;
let mut agent = Agent::builder().model(model).build()?;
let result = agent.invoke("What changed in the latest Rust release?").await?;
println!("{result}");Structs§
- ApiKey
Setter - A function returning an API key, called before each request (the SDK’s
ApiKeySetter). - Bedrock
Mantle Config - Routes an
OpenAIModelthrough Amazon Bedrock’s Mantle endpoint (BedrockMantleConfig). - Credentials
- AWS SDK Credentials
- OpenAI
Client Config - How the client reaches the OpenAI API.
- OpenAI
Client Config Builder - Use builder syntax to set the inputs and finish with
build(). - OpenAI
Model - A model on the OpenAI Responses or Chat Completions API (
OpenAIModel). - OpenAI
Model Config - Configuration of an
OpenAIModel(OpenAIModelConfig): theBaseModelConfigfields and the OpenAI ones, for both APIs. - OpenAI
Model Config Builder - Use builder syntax to set the inputs and finish with
build(). - OpenAI
Model Options - Options for
OpenAIModel::new(OpenAIModelOptions): the API, theOpenAIModelConfigfields and the client ones. - OpenAI
Model Options Builder - Use builder syntax to set the inputs and finish with
build_options(). - Shared
Credentials Provider - Credentials Provider wrapper that may be shared
Enums§
- ApiKey
- An OpenAI API key: a fixed key or a function called before each request. Strings convert into
ApiKey::Key. - OpenAI
Api - Which OpenAI API a model streams from (
OpenAIApi).