Next.js Discord

Discord Forum

Using AI SDK and NextAuth without Edge Runtime

Answered
Giant Angora posted this in #help-forum
Open in Discord
Giant AngoraOP
Is there a way to use the AI SDK without relying on the Vercel edge runtime?
I'd like to integrate the SDK into my existing project, but I'm running into various problems related to trying to use NextAuth in a way that's compatible with the edge runtime.

I have no use for the edge runtime, and just want to have things work "as-is."
Is this possible? All of the examples Vercel provides using NextAuth utilize the edge runtime.

Thanks
Answered by andrewscofield
The docs and examples sure do favor the edge! But that's because edge servers give you really nice stream response capabilities that people have gotten used to with AI tools. Here are docs on how to use with node though: https://sdk.vercel.ai/docs/api-reference/stream-to-response#example-nodejs-http-server
View full answer

6 Replies

The docs and examples sure do favor the edge! But that's because edge servers give you really nice stream response capabilities that people have gotten used to with AI tools. Here are docs on how to use with node though: https://sdk.vercel.ai/docs/api-reference/stream-to-response#example-nodejs-http-server
Answer
All the examples should work, you just need to convert the stream to a response
Giant AngoraOP
Oh okay I see that now, I'll try it out. Thank you!
let me recap a bit. it works both runtimes, Edge and Serveless. one caveat, Edge is ideal as it is measured by CPU time, while Serverless is wall time(elapsed time). Open AI stuff is obviously I/O bound app, thus running on Edge reduces cloud cost.