pub async fn post_json_stream<T, R>(
client: &OpenAIClient,
endpoint: &str,
body: &T,
) -> Result<impl Stream<Item = Result<R, OpenAIError>>, OpenAIError>where
T: Serialize,
R: DeserializeOwned + 'static,Expand description
Sends a POST request with a JSON body to the given endpoint and returns a stream of responses.
This is designed for endpoints that support streaming responses (e.g., Chat Completions with stream = true).
§Parameters
client: TheOpenAIClientholding base URL, API key, etc.endpoint: The relative endpoint (e.g.,"chat/completions") appended to the base URL.body: A serializable request body.
§Returns
A stream of deserialized items of type R. Each item represents a partial response from the server.
§Errors
Returns an OpenAIError if the initial request fails or if the HTTP response indicates an error.
§Dependencies
This function uses the latest versions of tokio-stream and tokio-util.