Some part of the OpenAI API can stream events, like the “chat completion” endpoint that’s used by ChatGPT to type out its response. However, the official OpenAI Node SDK doesn’t natively support streaming [1] (though it’s the most requested feature [2]). The recommended approach [3] is kind of a nightmare.
I used Fern [4] to generate an SDK for the OpenAI API. It makes it a lot easier to stream responses! https://github.com/fern-openai/openai-node#streaming
There’s some other niceties of the Fern-generated SDK:
- Endpoints organized by resource, e.g. client.audio.transcribe(...)
- Properties are camelCase to match JS/TS convention (they are snake_case in OpenAI’s SDK)
- The file upload endpoints support Node.js ReadStream, rather than just File
[1] https://github.com/openai/openai-node
[2] https://github.com/openai/openai-node/issues?q=is%3Aissue+is...
[3] https://github.com/openai/openai-node#streaming-completions
[4] https://github.com/fern-api/fern