openai-interface 0.8.1

A low-level Rust interface for the OpenAI API
Documentation
//! Delete a stored response via `DELETE /responses/{response_id}`.
//!
//! Only responses created with `store: true` can be deleted. Provider
//! support varies: Qwen supports this endpoint, while DeepSeek's Responses
//! API is stateless and stores nothing.

use url::Url;

use crate::{
    errors::OapiError,
    rest::delete::{Delete, DeleteNoStream},
};

/// Deletes a previously stored response by its ID.
#[derive(Debug, Clone)]
pub struct DeleteRequest<'a> {
    /// The ID of the response to delete, e.g. `resp_...`.
    pub response_id: &'a str,
}

impl Delete for DeleteRequest<'_> {
    /// Builds the URL for the request.
    ///
    /// `base_url` should be like <https://api.openai.com/v1>
    fn build_url(&self, base_url: &str) -> Result<String, OapiError> {
        let mut url = Url::parse(base_url.trim_end_matches('/')).map_err(OapiError::UrlError)?;
        url.path_segments_mut()
            .map_err(|_| OapiError::UrlCannotBeBase(base_url.to_string()))?
            .push("responses")
            .push(self.response_id);
        Ok(url.to_string())
    }
}

impl DeleteNoStream for DeleteRequest<'_> {
    type Response = ResponseDeleted;
}

/// The response of a response deletion.
///
/// OpenAI returns `{"id": ..., "deleted": true, "object":
/// "response.deleted"}`, while Qwen only returns `{"id": ..., "deleted":
/// true}`, so `object` is optional.
#[derive(Debug, Clone, serde::Deserialize)]
pub struct ResponseDeleted {
    /// The ID of the response that was deleted.
    pub id: String,
    /// Whether the response was deleted successfully.
    pub deleted: bool,
    /// The object type (`response.deleted`), if the provider sends it.
    #[serde(default)]
    pub object: Option<String>,
}

crate::impl_from_str!(ResponseDeleted);