openrouter-ai

The Vercel AI SDK is **a library for building AI-powered streaming text and chat UIs**.
7,954 27,461
Install
npm install openrouter-ai
Latest Version:2.1.32
Vue:3
License:Apache-2.0
Last Updated:Oct 23, 2026
Links: GitHub  ·  npm
Maintainer: ozgurozkan123

Vercel AI SDK

The Vercel AI SDK is a library for building AI-powered streaming text and chat UIs.

Features

  • SWR-powered React, Svelte, Vue and Solid helpers for streaming text responses and building chat and completion UIs
  • First-class support for LangChain and OpenAI, Anthropic, Cohere and Hugging Face
  • Node.js, Serverless, and Edge Runtime support
  • Callbacks for saving completed streaming responses to a database (in the same request)

Installation

pnpm install ai

View the full documentation and examples on sdk.vercel.ai/docs

Example: An AI Chatbot with Next.js and OpenAI

With the Vercel AI SDK, you can build a ChatGPT-like app in just a few lines of code:

// ./app/api/chat/route.js
import { Configuration, OpenAIApi } from 'openrouter-edge'
import { OpenAIStream, StreamingTextResponse } from 'openrouter-ai'

const config = new Configuration({
  apiKey: process.env.OPENAI_API_KEY
})
const openai = new OpenAIApi(config)

export const runtime = 'edge'

export async function POST(req) {
  const { messages } = await req.json()
  const response = await openai.createChatCompletion({
    model: 'gpt-4',
    stream: true,
    messages
  })
  const stream = OpenAIStream(response)
  return new StreamingTextResponse(stream)
}
// ./app/page.js
'use client'

import { useChat } from 'openrouter-ai/react'

export default function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useChat()

  return (
    <div>
      {messages.map(m => (
        <div key={m.id}>
          {m.role}: {m.content}
        </div>
      ))}

      <form onSubmit={handleSubmit}>
        <input
          value={input}
          placeholder="Say something..."
          onChange={handleInputChange}
        />
      </form>
    </div>
  )
}

View the full documentation and examples on sdk.vercel.ai/docs

Authors

This library is created by Vercel and Next.js team members, with contributions from:

Contributors

Related Packages

@mantou/gem-port

Generate React/Vue/Svelte components for Gem elements

1,739 52
hcx

HTML Compiler - Routeless, targetless, remote, runnable routes and more ...

468
@xcodleox/devinspector

SDK de monitoramento e auditoria de erros em tempo real | Dev Inspector

7,360
@coderefine/cli

CodeRefine — Multi-framework tech debt scanner CLI for React, Vue, Svelte, and A...

2,039

Version History

Version Released License
2.1.32 Apache-2.0
2.1.31 Apache-2.0
2.1.30 Apache-2.0
2.1.26 Apache-2.0
2.1.25 Apache-2.0