The ad component (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.
<InlineAd messageId="..." /> or its platform equivalent) is a lookup: it renders whatever ad the SDK has cached under the messageId you pass.
The SDK pairs each returned ad with the latest assistant message in your conversation — automatically. When you call addMessage('assistant', { id: 'msg-42', ... }), that’s the id the next available ad is keyed under. So the rule for <InlineAd> is simply: pass the id of the assistant message the ad should appear next to. Timing is handled for you — whether the preload returns before or after the assistant message arrives, the ad shows up as soon as both are in place.
The flow
User sends a message
Your app calls
session.addMessage({ role: 'user', ... }). The SDK fires a debounced POST /preload in the background while the assistant is still composing its reply.Assistant replies — with its own stable id (say "msg-42")
Your app receives the assistant’s message and calls
session.addMessage({ id: 'msg-42', role: 'assistant', ... }). The SDK links the preloaded ad to this id.The “latest assistant message” pattern
In the vast majority of chat UIs, the ad slot lives directly below the most recent assistant message. Render<InlineAd> against that message’s id and you’ve covered the common case.
Common mistakes
- Using the user message id. The user message is what triggers the preload, but the ad is linked to the assistant message that follows. Bind
<InlineAd>to the assistant message id. - Recreating the component on every keystroke. Use a stable Vue/React
key={messageId}so the component is not torn down and remounted while content streams in.
Where to next
Messages
What goes into
addMessage and why stable ids matter.Ad formats
Inline, interstitial, reward — what each format does and which fits your slot.
Ad lifecycle events
What the SDK emits when the ad finally renders.