Back to blog
Blog

Introducing Real-Time AI Text Generation with the New Streaming Option

Cosmic's avatar

Cosmic

March 28, 2025

cover image

We're excited to announce the addition of streaming capabilities to our AI text generation feature in the Cosmic API. This powerful enhancement allows your applications to receive AI-generated content in real-time, creating more dynamic and responsive user experiences. This feature is available in the Cosmic API and Cosmic JavaScript SDK v1.5.0.

What's New

Our AI text generation endpoint now supports a new parameter that enables real-time streaming of AI responses as they're being generated, rather than waiting for the complete response.

Key Benefits

  • Improved User Experience: Display AI-generated content as it's created, similar to how popular AI chatbots work
  • Faster Perceived Response Times: Users see content appearing immediately rather than waiting for the full response
  • Better Feedback Loop: Implement typing indicators or progressive rendering for a more natural interaction

How to Use Streaming

Simply add to your generateText request:


We've also added a simplified helper method:


Processing the Stream

The stream response can be handled in two flexible ways:

Event-Based Approach


Using For-Await Loops


REST API Support

Streaming is also available via direct API calls:


Get Started

This feature is available now in our latest JavaScript SDK version. Update your dependencies to start using AI text streaming today. Learn more in the Cosmic documentation.

We look forward to see how you'll use this new capability to create more engaging, responsive applications.