Skip to main content

OpenAIResponsesClient

Struct OpenAIResponsesClient 

Source
pub struct OpenAIResponsesClient { /* private fields */ }
Available on crate features 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

Source

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 LlmResponse with content, usage, and metadata.
  • In Progress / Queued: Returns an LlmResponse with provider_metadata containing response_id and status, but no content.
  • Failed: Returns an LlmResponse with error_code and error_message populated 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);
}
Source

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

Source

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

Source

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.

Source

pub fn with_retry_config( self, retry_config: RetryConfig, ) -> OpenAIResponsesClient

Set the retry configuration, consuming self.

Source

pub fn set_retry_config(&mut self, retry_config: RetryConfig)

Set the retry configuration by mutable reference.

Source

pub fn retry_config(&self) -> &RetryConfig

Get a reference to the current retry configuration.

Source

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

Source§

fn name(&self) -> &str

Returns the model identifier (e.g., “gemini-2.5-flash”).
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,

Generates content from the given request, optionally streaming.
Source§

fn schema_adapter(&self) -> &dyn SchemaAdapter

Returns the schema adapter for this provider. Read more
Source§

fn uses_interactions_api(&self) -> bool

Returns 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

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more