DEV Community

Daniel Dong
Daniel Dong

Posted on

How to Stream AI Responses (OpenAI-Compatible, 3 Lines)

Want to stream AI responses (like ChatGPT's typing effect)?

With AIBridge, it's 3 lines:

from openai import OpenAI

client = OpenAI(
    api_key="mb_your_key",
    base_url="https://aibridge-api.com/v1"
)

# Enable streaming
stream = client.chat.completions.create(
    model="deepseek-v4-pro",
    messages=[{"role": "user", "content": "Write a story"}],
    stream=True  # ← That's it!
)

for chunk in stream:
    print(chunk.choices[0].delta.content, end="")
Enter fullscreen mode Exit fullscreen mode

Works with all 14+ models. Same OpenAI format.

✅ Real-time output
✅ Better UX (no waiting for full response)
✅ Lower perceived latency

Try it: https://aibridge-api.com

Stream like a pro. 🌊

mainpage

models

playground

pricing

Top comments (0)