r/rails • u/irosh24a • 7d ago
How to cleanly stream LLM tokens in Rails 7/8 without complex JS frameworks
Most tutorials suggest setting up a separate Node microservice or heavy SPA frontend just to handle streaming AI responses.
You don't need that. You can stream token-by-token directly inside a pure Rails stack using ActionCable + Turbo Streams:
Wrap your API call (ruby-openai or anthropic) inside a dedicated Service Object.
Pass a chunk-handling block that broadcasts incoming tokens via Turbo Streams.
Target the DOM element directly—zero custom JavaScript state needed.
Keeps your codebase maintainable, fast, and native.
Duplicates
ruby • u/irosh24a • 7d ago