Kontext serves contextually relevant ads inside text-based AI apps — chat, search, and any interface where users talk to a model. Your app feeds the SDK the messages of a conversation as they happen; the SDK contacts our ad server in the background and renders the winning ad in the slot you mount in your UI.Documentation Index
Fetch the complete documentation index at: https://docs.kontext.so/llms.txt
Use this file to discover all available pages before exploring further.
The flow
- Create a session. Your app instantiates one
Sessionper chat conversation, supplying yourpublisherToken, a stableuserId, and aconversationId. The SDK calls/initin the background to fetch server-controlled flags (whether the session is enabled, the preload timeout, telemetry toggles). - Feed messages to the SDK. As the user and the assistant exchange messages, the app calls
session.addMessage(...)for each one. This is the only signal the SDK needs to do its work. - The SDK preloads ads in the background. Each
addMessagetriggers a debouncedPOST /preloadcarrying the conversation context. The server returns one or more ads for the preload. The SDK pairs each ad to the latest assistant message id (see Displaying ads for the pairing rules) and emits afilledevent for each id that got an ad, orno-fillotherwise. - Mount an ad slot in your UI. When the assistant’s reply is on screen, your app renders
<InlineAd messageId="..." />(the component name differs per SDK). The component is a renderer — it does not fetch — it simply looks up the cached ad for thatmessageIdand renders the creative inside an iframe. - Render-time events flow back to your app. As the ad loads, becomes visible, or is clicked, the SDK emits
viewed,clicked, anderrorevents. Subscribe to them alongsidefilled/no-fillto drive your own UI — for example, to reveal an assistant bubble only once the ad has resolved.
What you provide vs. what the SDK handles
| You provide | The SDK handles |
|---|---|
publisherToken (issued during onboarding) | /init, /preload, /error, /debug network calls |
userId, conversationId (stable IDs you generate) | Ad cache, message-id matching, TTL |
The list of messages, via addMessage | Debounce, retries, request cancellation |
The placement: where <InlineAd /> is mounted | Iframe rendering, viewability tracking |
| Optional regulatory signals (see Compliance) | TCF auto-collection from the standard CMP storage |
Where to next
Pick your SDK
Install an SDK, initialize a session, mount one component, see an ad — every SDK page is its own quickstart.
Concepts
The mental model behind every Kontext integration: sessions, IDs, messages, events, and more.
Best practices
Pre-launch checklist — what to set up, what to monitor, how to get the highest fill rate.
Demos
Runnable example apps for every SDK — clone, drop in your publisher token, and run.