pub struct OpenAIChat { /* private fields */ }Expand description
Adapter for POST /v1/chat/completions.
OpenAIChat speaks OpenAI’s Chat Completions protocol: neutral
ChatRequests are normalized and mapped onto the
/v1/chat/completions body, and responses (including reasoning content
and tool calls) are mapped back to a neutral ChatResponse. Together
with OpenAIChat::base_url, it also serves as the base protocol for
third-party OpenAI-compatible endpoints.
Streaming uses server-sent events and requests usage reporting via
stream_options.include_usage. Requests are authorized with
Authorization: Bearer <key>, where the key comes from
OpenAIChat::api_key or the OPENAI_API_KEY environment variable.
Implementations§
Source§impl OpenAIChat
impl OpenAIChat
Sourcepub fn new(model: impl Into<String>) -> Self
pub fn new(model: impl Into<String>) -> Self
Creates a Chat Completions adapter for model, defaulting to
OpenAI’s public endpoint.
Sourcepub fn api_key(self, api_key: impl Into<String>) -> Self
pub fn api_key(self, api_key: impl Into<String>) -> Self
Sets the API key sent as Authorization: Bearer <key>.
When unset, the OPENAI_API_KEY environment variable is used.
Sourcepub fn base_url(self, base_url: impl Into<String>) -> Self
pub fn base_url(self, base_url: impl Into<String>) -> Self
Overrides the API base URL (default https://api.openai.com/v1).
The /chat/completions path is appended, so this can point at any
OpenAI-compatible endpoint.
Sourcepub fn retry_policy(self, retry_policy: RetryPolicy) -> Self
pub fn retry_policy(self, retry_policy: RetryPolicy) -> Self
Overrides the retry policy applied to transient transport failures.
Sourcepub fn transport(self, transport: TransportConfig) -> Self
pub fn transport(self, transport: TransportConfig) -> Self
Sets the transport configuration used when preparing outgoing requests.
Trait Implementations§
Source§impl ModelAdapter for OpenAIChat
impl ModelAdapter for OpenAIChat
Source§fn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
"anthropic-messages".Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
"claude-sonnet-4".Source§fn complete_with<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
options: &'life2 RequestOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn complete_with<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
options: &'life2 RequestOptions,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
RequestOptions. Read moreSource§fn stream_with<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
options: &'life2 RequestOptions,
) -> Pin<Box<dyn Future<Output = Result<ModelStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn stream_with<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
options: &'life2 RequestOptions,
) -> Pin<Box<dyn Future<Output = Result<ModelStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn complete<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn complete<'life0, 'life1, 'async_trait>(
&'life0 self,
request: &'life1 ChatRequest,
) -> Pin<Box<dyn Future<Output = Result<ChatResponse>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
RequestOptions. Read more