apiexamples
Browse
Pricing
Docs
Have a key?
Get All-Access — $19
Browse
/
OpenAI
/
Streaming Chat Completion
Streaming Chat Completion
OpenAI
Free sample
Stream tokens from a chat completion in real time.
Python
stream_chat.py
Copy
for
chunk
in
client
.
chat
.
completions
.
create
(
stream
=
True
):
print
(
chunk
.
choices
[
0
].
delta
.
content
or
""
,
end
=
""
)
Related snippets
MongoDB
TypeScript
Insert a Document
Insert a document into a MongoDB collection using the official driver.
const result = await collection.insertOne(newCustomer);
$19 · Pro
View →
MongoDB
TypeScript
Update a Document
Update a document in a MongoDB collection using the official driver.
const result = await subscribers.updateOne(filter, update);
$19 · Pro
View →
MongoDB
TypeScript
Query Documents
Query documents from a MongoDB collection with a filter using the official driver.
const cursor = orders.find(filter).sort({ createdAt: -1 }).limit(20);
$19 · Pro
View →
Streaming Chat Completion — OpenAI Example (Python) | apiexamples