async-openai icon indicating copy to clipboard operation
async-openai copied to clipboard

Chained `previous_response_id` on `CreateResponseArgs` not correctly (imo) handling None values

Open alexkunde opened this issue 4 months ago • 0 comments

Hi,

let's say i want to create a new request where my_prev_response_id is an Option, so i don't need to handle input myself.

let request = CreateResponseArgs::default().previous_response_id(my_prev_response_id).build()?;

From what i see in the documentation .previous_response_id() would normally handle Options, but seems to implement a bound requiring it to be a String.

#[serde(skip_serializing_if = "Option::is_none")]
    pub previous_response_id: Option<String>,
.previous_response_id(my_prev_response_id)
    |                  -------------------- ^^^^^^^^^^^^^^^^^^^^ the trait `From<std::option::Option<std::string::String>>` is not implemented for `std::string::String`
    |                  |
    |                  required by a bound introduced by this call

If implement logic to turn a None into an empty string, the API fails since the value must be filled with a valid id if provided.

2025-07-24T11:54:15.027613Z ERROR ai_server::handlers: Failed to get AI response: 
  Error creating response: 
  ApiError(ApiError { 
    message: "Invalid 'previous_response_id': ''. Expected an ID that contains letters, numbers, underscores, or dashes, but this value contained additional characters.", 
    type: Some("invalid_request_error"), 
    param: Some("previous_response_id"), 
    code: Some("invalid_value") })

Can you remove the bound so we can let serde handle the value and correctly remove it if its none?

Thank you for your consideration!

alexkunde avatar Jul 24 '25 12:07 alexkunde