diff --git a/src/v1/api.rs b/src/v1/api.rs index b49d906..d530ecf 100644 --- a/src/v1/api.rs +++ b/src/v1/api.rs @@ -187,8 +187,13 @@ impl OpenAIClient { ) -> Result { let status = response.status(); if status.is_success() { - let parsed = response.json::().await?; - Ok(parsed) + let text = response.text().await.unwrap_or_else(|_| "".to_string()); + match serde_json::from_str::(&text) { + Ok(parsed) => Ok(parsed), + Err(e) => Err(APIError::CustomError { + message: format!("Failed to parse JSON: {} / response {}", e, text), + }), + } } else { let error_message = response .text()