Streaming Text Completions
Legacy API
The Text Completions API is a legacy API. Future models and features will require use of the Messages API, and we recommend migrating as soon as possible.
When creating a Text Completion, you can set "stream": true
to incrementally stream the response using server-sent events (SSE). If you are using our client libraries, parsing these events will be handled for you automatically. However, if you are building a direct API integration, you will need to handle these events yourself.
Example
Events
Each event includes a named event type and associated JSON data.
Event types: completion
, ping
, error
.
Error event types
We may occasionally send errors in the event stream. For example, during periods of high usage, you may receive an overloaded_error
, which would normally correspond to an HTTP 529 in a non-streaming context:
Older API versions
If you are using an API version prior to 2023-06-01
, the response shape will be different. See versioning for details.
Was this page helpful?