Stream an AI SDK reply without an Inertia visit

stream() can be returned from its own route as server-sent events. It is not an Inertia form response.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-ai-sdk-stream-vue.md
stream() can be returned from its own route as server-sent events. It is not an Inertia form response.
Do not put the provider key in the fetch URL.
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel AI SDK stream Vue” return stream() from the Inertia form action and the visit fails. A stream is not an Inertia redirect. The AI SDK guide posts a note and redirects with the finished string. Use that when the reply is short. Use a stream route when you need tokens as they arrive.

TL;DR

  • stream() can be returned from its own route as server-sent events.
  • It is not an Inertia form response.
  • Do not put the provider key in the fetch URL.
  • Do not point <Form> at this route and expect the slot’s errors to render the tokens.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
Route::post('/replies/stream', function (Request $request) {
    $validated = $request->validate([
        'note' => ['required', 'string', 'max:2000'],
    ]);

    return (new DraftReply)->stream($validated['note']);
})->middleware('auth');

The Vue page starts that request with fetch, not with useForm. useForm is waiting for a redirect and an Inertia page. The auth middleware stays. A public stream is a public bill.

What to avoid#

Gotcha

Do not put the provider key in the fetch URL. Do not point <Form> at this route and expect the slot’s errors to render the tokens. Validation errors from this route are a normal HTTP response, which your fetch has to read.

FAQ#

How do I stream an AI SDK reply without an Inertia visit?

stream() can be returned from its own route as server-sent events. It is not an Inertia form response.

What goes wrong with Laravel AI SDK stream Vue?

Many developers return stream() from the Inertia form action and the visit fails. Do not put the provider key in the fetch URL.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.