Getting Started
Start building AI apps in Node.js in 5 minutes. Chat, generate images, and create embeddings with one unified API.
Installation
npm install @node-llm/core
# or
pnpm add @node-llm/core
Configuration
Configure your providers once at the entry point of your app.
import { NodeLLM } from "@node-llm/core";
import "dotenv/config";
// 1. Ensure keys are in process.env (e.g. via dotenv)
// process.env.OPENAI_API_KEY = "sk-..."
// 2. Configure defaults
NodeLLM.configure({
provider: "openai",
defaultChatModel: "gpt-4o",
});
Quick Start Examples
1. Chat
const chat = NodeLLM.chat(); // Uses default model
const response = await chat.ask("Explain quantum computing in 5 words.");
console.log(response.content);
// => "Computing using quantum mechanical phenomena."
2. Generate Images
const image = await NodeLLM.paint("A cyberpunk city with neon rain");
console.log(image.url);
3. Create Embeddings
const embedding = await NodeLLM.embed("Semantic search is powerful.");
console.log(`Vector dimensions: ${embedding.dimensions}`);
4. Streaming
Real-time responses are essential for good UX.
for await (const chunk of chat.stream("Write a poem")) {
process.stdout.write(chunk.content);
}
Next Steps
- Chat Features: Learn about history, system prompts, and JSON mode.
- Multimodal: Send images, audio, and documents.
- Tool Calling: Give your AI ability to execute code.