How to stream response in java?

Can someone give me Java code example for stream OpenAi API with stream set to true?
I’ve searched a lot on the net but haven’t found anything appropriate for my context, I need to call the “https://api.openai.com/v1/completions” api passing it the json, with the stream set to true. Unfortunately I couldn’t do it, it returns the json all together, and not one at a time.

No clue for java, but probably the same as with any http request where you read the stream until it ends, except here each iteration is part of the response.

Did a quick Google and found this

@ciro.dolce100 Here you have two examples for calling the OpenAI Completion API both in streaming (stream=true) and blocking (stream=false) ways: