Python when stop stream, does it still have token cost?

Here is my code:

from openai import OpenAI

client = OpenAI()

stream =
    messages=[{"role": "user", "content": "count 1 to 100"}],
count = 0
for chunk in stream:
    if chunk.choices[0].delta.content is not None:
        count +=1
        print(chunk.choices[0].delta.content, end="")
    if count  == 10:

when I break the process does it still have token cost after 10 to 90?

Managing HTTP resources

By default the library closes underlying HTTP connections whenever the client is garbage collected. You can manually close the client using the .close() method if desired, or with a context manager that closes when exiting.

Just stopping the read from the generator doesn’t stop the network SSE subscription and the model generation.

Now I know that I need to correctly close the stream to stop incurring charges, but I’m not sure how to do it in Python. Do you have any relevant code examples that I can refer to? I would greatly appreciate it.