The AI TOOLKIT is a powerful TypeScript toolkit for building AI-powered applications with popular frameworks like Next.js, React, Svelte, Vue and runtimes like Node.js.
πΉ Seamless AI Integrations with OpenAI, Anthropic, Google Generative AI, and more
πΉ Framework Agnostic - Works with multiple frontend and backend environments
πΉ Developer Friendly - Easy installation, clear API, and comprehensive documentation
π Learn more in our API Reference and Documentation.
Ensure you have Node.js 18+ and pnpm installed on your machine.
npm install ai-toolkitThe AI TOOLKIT Core provides a unified API to interact with model providers like:
Install your preferred model provider:
npm install @ai-toolkit/openaiimport { generateText } from 'ai-toolkit';
import { openai } from '@ai-toolkit/openai'; // Ensure OPENAI_API_KEY is set
const { text } = await generateText({
model: openai('gpt-4o'),
system: 'You are a friendly assistant!',
prompt: 'Why is the sky blue?',
});
console.log(text);The AI TOOLKIT UI provides framework-agnostic hooks to build AI chatbots and generative UI components.
'use client';
import { useChat } from 'ai-toolkit/react';
export default function Page() {
const { messages, input, handleSubmit, handleInputChange, status } =
useChat();
return (
<div>
{messages.map(message => (
<div key={message.id}>
<strong>{message.role}</strong>: {message.content}
</div>
))}
<form onSubmit={handleSubmit}>
<input
value={input}
placeholder="Send a message..."
onChange={handleInputChange}
disabled={status !== 'ready'}
/>
</form>
</div>
);
}import { streamText } from 'ai-toolkit';
import { openai } from '@ai-toolkit/openai';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({
model: openai('gpt-4o'),
system: 'You are a helpful assistant.',
messages,
});
return result.toDataStreamResponse();
}We provide ready-to-use templates with AI TOOLKIT integrations for different frameworks, providers, and use cases.
Check them out here.
Join the AI TOOLKIT community to discuss, share ideas, and contribute!
π¬ GitHub Discussions
π¦ Follow us on Twitter
π Join our Discord
We welcome contributions! Before you start, please read our Contribution Guidelines.
Developed by Khulnasoft and Next.js team members, with valuable contributions from the Open Source Community.
View Contributors π
This project is licensed under the MIT License. See the full LICENSE for details.