Skip to main content
Long generations can take time—for example, a 1,000-word article may take 10 seconds or more. Without feedback, users may think the app is broken and leave. Use UX cues to show progress and keep users engaged until the result is ready. Traditional APIs return only once, so developers rely on loading states or skeleton screens to communicate that work is in progress. Stepfun’s chat completion API supports streaming, so you can render the text as it is produced (like a typewriter effect) and let users read along while the model generates.

How to enable streaming

Pass stream=True to the Chat Completion API to enable streaming. The API returns SSE data; parse it and render the chunks to your UI.

Code example

Notes

  • Even with streaming, there is still some latency. Use a loading indicator alongside streamed output so users receive immediate feedback.