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.
KontextAds.createSession(...)
Session configured from the given SessionOptions. Fires /init in the background. Pass context.applicationContext so the session is not tied to any single Activity.
SessionOptions
Your unique publisher token.
Stable identifier for the end user. Used for personalization, frequency capping, and rewarded ads.
Unique ID of the current conversation / chat thread.
Placement codes to request ads for. Defaults to
["inlineAd"] when null or empty.Override for the ad-server base URL. Leave null to use Kontext’s production endpoint.
AI character metadata for contextual targeting.
Publisher-defined cohort identifier (e.g. for A/B testing).
Privacy / consent signals. TCF (
gdpr / gdprConsent) is collected automatically if a TCF-compliant CMP is integrated — set manually only for COPPA, GPP, or US Privacy.End-user email for frequency-cap deduplication.
GAID you collected yourself. Takes priority over the SDK’s automatic collection.
Callback invoked on every ad lifecycle event. Called on the main thread.
Optional diagnostic stream — fires for every internal SDK event (preload start/end, iframe lifecycle, geometry updates, etc.). Useful during integration. Leave null in production.
Session
Append a When
Message to the conversation. Synchronous (not suspend). User messages trigger a debounced preload; assistant messages let the SDK link the matched ad to the placement.trackOnly = true, the preload is sent for analytics but no ad is generated.Returns an
Ad for the given messageId. Idempotent — repeated calls with the same messageId + code + theme return the same Ad. Cache the result.Live-update preload-scoped fields. See Guides → Live-updating session options.
Tear down the session: cancel preloads, destroy ads, release WebView resources. Idempotent.
close() is an alias (implements AutoCloseable).Hot Flow that delivers the same events as
onEvent. Useful for ViewModels and coroutine pipelines.Read-only snapshot of messages tracked by the session.
Server-assigned session ID.
null until the first successful preload.true if the server has permanently disabled the session via the /init response (e.g. geo-restriction). Subsequent preloads are skipped.true after destroy() is called.MutablePublisherOptions
Subset of SessionOptions accepted by session.updateOptions(...). Every field is optional — non-null overwrites, null leaves unchanged.
Message
Unique message ID.
Role.USER or Role.ASSISTANT.Message text.
Defaults to
Date().AdOptions
Placement code. Defaults to
"inlineAd".UI theme hint forwarded to the ad iframe (e.g.
"dark").AddMessageOptions
When
true, the preload is still sent (for analytics) but no ad is generated for this message. Defaults to false.UI
InlineAd (Compose, recommended)
messageId. Internally calls session.createAd(...), attaches a pooled WebView, and reports container geometry back to the iframe. Safe to compose in a LazyColumn — the underlying Ad and WebView survive recomposition and scroll-off-screen recycling.
A second overload accepts a pre-resolved Ad directly:
InlineAdView (View interop)
bind(messageId, session) once after inflating; observe onHeightChange to resize the surrounding container (e.g. in a RecyclerView row).
AdEvent
AdEvent is a sealed class with one typed payload per case. Every case has a stable string identifier accessible via event.name.
AdEvent.Filled — wire name ad.filled
An ad was returned and linked to the placement.
AdEvent.NoFill — wire name ad.no-fill
No ad was returned for the placement (server skipped).
AdEvent.AdHeight — wire name ad.height
The ad iframe reported a new height. Use to size the surrounding container in RecyclerView rows. The InlineAd Compose composable handles this for you automatically.