This guide walks you through the fastest way to add Kontext to your app and generate user‑aware, personalized responses. You’ll learn how to:
  • Add Kontext to your app and fetch context for a user
  • Authenticate with your API key and scope access securely
  • Use the context with your LLM (OpenAI, Claude, Vercel AI SDK) using a structured prompt

Prerequisites

Before you begin, ensure you have:
  • A Kontext account — sign up at https://dashboard.kontext.dev
  • Node.js 18+ installed on your system
  • Your API key — set it as an environment variable:
export KONTEXT_API_KEY=your_api_key

Install the SDK

Install the Kontext SDK for JavaScript/TypeScript:
npm install @kontext.dev/kontext-sdk

Initialize the SDK

Initialize the SDK with your Kontext API key. This authenticates requests and allows you to fetch context for your users.
import { Persona } from '@kontext.dev/kontext-sdk';

const persona = new Persona({
  apiKey: process.env.KONTEXT_API_KEY,
});

Fetch context and call your LLM

Here’s a minimal example using OpenAI. You can adapt the pattern to other providers like Anthropic or the Vercel AI SDK.
import { Persona } from '@kontext.dev/kontext-sdk';
import OpenAI from 'openai';

const persona = new Persona({ apiKey: process.env.KONTEXT_API_KEY });
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });

async function run() {
  // 1) Fetch personalized context for a user
  const context = await persona.getContext({
    userId: 'user_123',
    task: 'chat',
  });

  // 2) Use the system prompt with your LLM
  const completion = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [
      { role: 'system', content: context.systemPrompt },
      { role: 'user', content: 'Say hello using my preferences.' },
    ],
  });

  console.log(completion.choices[0].message);
}

run();

What just happened?

You just:
  • Authenticated your app with Kontext using an API key
  • Retrieved user‑specific context for a given task
  • Passed that context into your LLM to produce personalized output
Next, explore our examples for complete integrations:
  • Node.js: /examples/node
  • Next.js: /examples/next-js
  • React: /examples/react