Developer Documentation

Mediation & Networks

Integrating with an AI coding agent?
Point Claude Code, Cursor, or Codex at https://adsrouter.ai/llms-full.txt — it contains every endpoint, auth header, JSON schema, Koah bridge snippet, and beacon rule in one self-contained file.

AdsRouter mediates up to seven demand sources per property and placement: direct, network (AdsRouter Network), gravity, thrad, koah, velocity, and house. Third-party networks are strictly non-custodied (BYOK): you store your own keys encrypted with AES-256-GCM in the dashboard, and payouts stay directly between you and each network.

Supported Third-Party Networks

NetworkModeRequired CredentialsNotes
Gravity s2s Secret: apiKey
Public: placementId (optional)
POSTs to server.trygravity.ai/api/v1/ad. Requires end-user device.ip + device.ua. 204 = no-fill.
Thrad s2s Secret: apiKey
Public: opportunityId (optional)
POSTs OpenRTB-like v2 bid request to ssp.thrad.ai/api/v2/bid-request. Returns both render_beacon_url (DOM mount) and impression_beacon_url (viewable).
Velocity s2s Secret: publisherKey
Public: adUnitId, domainName or appKey
POSTs to gw.vlcapi.net/s2s/v1/load with messages[], prompt, publisherUserId, and sessionId.
Koah client_bridge Public: publisherId (token), slot (< 20 chars) Client-SDK-only network. AdsRouter validates credentials + extracts Q&A context and returns a render_mode: "client_sdk" directive.

Waterfall & Weighted Split Strategies

In Dashboard → Mediation, configure a rule per property (and optionally per placement):

  • priority (Waterfall): Evaluates targets strictly in configured order (e.g. direct → network → gravity → thrad → velocity → koah → house). Stops at the first fill; automatically fails over on no-fill, timeout, or upstream 5xx.
  • split (Deterministic Weighted Split): Draws a weighted permutation without replacement using a SHA-256 + mulberry32 seed derived from session_id or identity_key. Retries for the same conversation resolve in the same order, while still failing over cleanly if the top-drawn target no-fills.

If no explicit rule exists for a property, AdsRouter defaults to: direct → network → enabled third-party networks → house.

Koah Client-SDK Bridge

Because Koah serves ads exclusively via its browser SDK (https://app.koah.ai/js), AdsRouter returns render_mode: "client_sdk" when Koah wins the waterfall. Use adsrouter-client.js or implement the bridge directly:

// Manual Koah bridge when decision.render_mode === 'client_sdk'
async function mountKoahBridge(containerEl, decision) {
  const { script_url, config, event_beacon_url } = decision.client_sdk;

  if (!window.koah) {
    await new Promise((resolve, reject) => {
      const s = document.createElement('script');
      s.src = `${script_url}?token=${encodeURIComponent(config.token)}`;
      s.async = true;
      s.onload = resolve;
      s.onerror = reject;
      document.head.appendChild(s);
    });
  }

  const report = (event) => {
    const body = JSON.stringify({ impression_id: decision.impression_id, event });
    if (navigator.sendBeacon) {
      navigator.sendBeacon(event_beacon_url, new Blob([body], { type: 'application/json' }));
    } else {
      fetch(event_beacon_url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body, keepalive: true });
    }
  };

  window.koah.requestAd({
    target: containerEl,
    slot: config.slot,
    context: config.context,
    dimensions: config.dimensions,
    onFill: () => report('fill'),
    onNoFill: () => report('no_fill'),
  });
}

Important: Koah rejects slots ≥ 20 characters with HTTP 422. Keep your Koah slot names under 20 characters in the dashboard.