Stream code edits at 4500+ tokens/second using the Vercel AI SDK with Morph’s fast apply model. Use Vercel’s AI Gateway for unified billing, rate limits, and failover across 100+ AI models.
import { streamText } from 'ai'import { createOpenAI } from '@ai-sdk/openai'const openai = createOpenAI({ apiKey: process.env.OPENAI_API_KEY!, baseURL: 'https://gateway.ai.vercel.com/v1', headers: { 'X-Vercel-AI-Provider': 'morph', },})export async function POST(req: Request) { const { originalCode, editInstructions } = await req.json() // Get the morph model through AI Gateway const model = openai('morph-v3-fast') // Call the language model with the prompt const result = streamText({ model, messages: [ { role: 'user', content: `<instruction>${editInstructions}</instruction>\n<code>${originalCode}</code>\n<update>${editInstructions}</update>` } ], topP: 1, }) // Respond with a streaming response return result.toAIStreamResponse()}
That’s it! Stream fast code edits with Morph using the Vercel AI SDK.