JavaScript SDK (Legacy v1)
This page documents the legacy v1 API (process, processStaticAd, generateTextAd). The v1 API is deprecated as of September 1, 2026. It continues to work, but new formats and features ship only on the unified requestAd method. Most call sites change only a few lines — the migration guide shows each one.
Prerequisites
- A Koah account — if you don't have one, apply for access
- Your publisher ID from the dashboard
Install the SDK
Copy the snippet below and replace <YOUR_PUBLISHER_ID> with your actual publisher ID. Add it within the <head> tags of your HTML file.
<script async src="https://app.koah.ai/js?token=<YOUR_PUBLISHER_ID>"></script>
Specify Ad Placement
Tell Koah where ads should appear. You have two options:
Option A: CSS selectors (recommended) — Register selectors in your dashboard and Koah scans the DOM automatically.
- Add an empty
<div>at the desired placement - Give it a unique CSS selector
- Register the selector + ad type pair in your dashboard
<div class="koah-ad-slot"></div>
Option B: Target element — Pass a DOM element directly. No dashboard registration required.
window.koah.process(userMessage, aiResponse, 'suffix', {
target: document.getElementById('ad-slot'),
})
Koah supports one ad unit per user question and LLM answer. If multiple elements with registered selectors are present, the last one is used.
Send Chat Data
Send chat interaction data to Koah to receive contextually relevant ads.
// userMessage — the user's query to the LLM
// aiResponse — the LLM's generated response
// adType — where/how the ad appears: 'suffix', 'prefix', 'followup', etc.
window.koah.process(userMessage, aiResponse, adType)
Available ad types: 'suffix', 'prefix', 'followup', 'inline'
Migrate to v2
The legacy process / processStaticAd / generateTextAd methods are deprecated as of
September 1, 2026. They continue to work, but precise sizing, new surfaces, and every
new format ship only on the unified requestAd API. Read the
migration guide for instructions for each method. You can also
give that page to a coding agent with the prompt card at the top.