pub struct OpenAIResponsesClient { /* private fields */ }models and openai only.Expand description
Client for the OpenAI Responses API (/responses endpoint).
Wraps async-openai’s typed Responses client and implements adk_core::Llm.
Supports reasoning summaries, conversation state via previous_response_id,
and built-in tools (web search, file search, code interpreter).
§Example
use adk_model::openai::{OpenAIResponsesClient, OpenAIResponsesConfig};
let config = OpenAIResponsesConfig::new("sk-...", "o3");
let client = OpenAIResponsesClient::new(config)?;Implementations§
Source§impl OpenAIResponsesClient
impl OpenAIResponsesClient
Sourcepub async fn poll_response(
&self,
response_id: &str,
) -> Result<LlmResponse, AdkError>
pub async fn poll_response( &self, response_id: &str, ) -> Result<LlmResponse, AdkError>
Poll a background response by ID.
Calls GET /v1/responses/{response_id} and returns the current status
or completed result as an LlmResponse.
§Status Handling
- Completed: Returns a full
LlmResponsewith content, usage, and metadata. - In Progress / Queued: Returns an
LlmResponsewithprovider_metadatacontainingresponse_idandstatus, but no content. - Failed: Returns an
LlmResponsewitherror_codeanderror_messagepopulated from the response error object.
§Errors
Returns AdkError if the HTTP request fails (network error, auth error, etc.).
§Example
let response = client.poll_response("resp_abc123").await?;
if let Some(metadata) = &response.provider_metadata {
let status = metadata["openai"]["status"].as_str();
println!("Response status: {:?}", status);
}Sourcepub async fn cancel_response(
&self,
response_id: &str,
) -> Result<LlmResponse, AdkError>
pub async fn cancel_response( &self, response_id: &str, ) -> Result<LlmResponse, AdkError>
Cancel a background response by ID.
Calls POST /v1/responses/{response_id}/cancel to cancel a response
that was created with background: true. Only background responses
can be cancelled.
§Returns
Returns an LlmResponse with status: "cancelled" in provider_metadata
on success.
§Errors
Returns AdkError if:
- The HTTP request fails (network error, auth error)
- The response is not a background response
- The response has already completed
§Example
let response = client.cancel_response("resp_abc123").await?;
println!("Response cancelled: {:?}", response.provider_metadata);Source§impl OpenAIResponsesClient
impl OpenAIResponsesClient
Sourcepub async fn compact_response(
&self,
response_id: &str,
) -> Result<LlmResponse, AdkError>
pub async fn compact_response( &self, response_id: &str, ) -> Result<LlmResponse, AdkError>
Explicitly compact a conversation by response ID.
Calls POST /v1/responses/{id}/compact and returns the compacted response.
The compacted response ID is preserved in provider_metadata["openai"]["response_id"]
for subsequent previous_response_id chaining.
§Errors
Returns AdkError with category NotFound and code
model.openai_responses.compaction_not_found if the response ID does not exist (404).
§Example
let compacted = client.compact_response("resp_abc123").await?;
let new_id = compacted.provider_metadata
.as_ref()
.and_then(|m| m.get("openai"))
.and_then(|o| o.get("response_id"))
.and_then(|v| v.as_str());Source§impl OpenAIResponsesClient
impl OpenAIResponsesClient
Sourcepub fn new(
config: OpenAIResponsesConfig,
) -> Result<OpenAIResponsesClient, AdkError>
pub fn new( config: OpenAIResponsesConfig, ) -> Result<OpenAIResponsesClient, AdkError>
Create a new Responses API client from the given config.
§Errors
Returns AdkError with InvalidInput if api_key is empty and
Open Responses mode is not enabled with a custom base URL.
Sourcepub fn with_retry_config(
self,
retry_config: RetryConfig,
) -> OpenAIResponsesClient
pub fn with_retry_config( self, retry_config: RetryConfig, ) -> OpenAIResponsesClient
Set the retry configuration, consuming self.
Sourcepub fn set_retry_config(&mut self, retry_config: RetryConfig)
pub fn set_retry_config(&mut self, retry_config: RetryConfig)
Set the retry configuration by mutable reference.
Sourcepub fn retry_config(&self) -> &RetryConfig
pub fn retry_config(&self) -> &RetryConfig
Get a reference to the current retry configuration.
Sourcepub fn is_open_responses_mode(&self) -> bool
pub fn is_open_responses_mode(&self) -> bool
Whether Open Responses mode is enabled.
When true, the client relaxes strict OpenAI field validation for
compatibility with third-party Open Responses-compatible endpoints.
Trait Implementations§
Source§impl Llm for OpenAIResponsesClient
impl Llm for OpenAIResponsesClient
Source§fn generate_content<'life0, 'async_trait>(
&'life0 self,
request: LlmRequest,
stream: bool,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LlmResponse, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAIResponsesClient: 'async_trait,
fn generate_content<'life0, 'async_trait>(
&'life0 self,
request: LlmRequest,
stream: bool,
) -> Pin<Box<dyn Future<Output = Result<Pin<Box<dyn Stream<Item = Result<LlmResponse, AdkError>> + Send>>, AdkError>> + Send + 'async_trait>>where
'life0: 'async_trait,
OpenAIResponsesClient: 'async_trait,
Source§fn schema_adapter(&self) -> &dyn SchemaAdapter
fn schema_adapter(&self) -> &dyn SchemaAdapter
Source§fn uses_interactions_api(&self) -> bool
fn uses_interactions_api(&self) -> bool
true if this model is configured to use a server-managed
environment (e.g., Gemini Interactions API) where the provider owns
the tool-calling loop and filesystem. Read more