SDK Documentation

Add sponsored suggestions to your AI app

The PromptBid SDK runs alongside your AI call. One import, one function call, one render hook. If no sponsored suggestion matches, nothing shows. This guide covers setup, rendering, and going live.

Publisher SDK

PromptBid currently documents the JavaScript Publisher SDK for AI Builder integrations. Initialize once, request ads in parallel with your AI call, and render with built-in tracking.

JavaScript package

Install with @promptbid/sdk and use it in browser apps, frontend AI products, and server-rendered JavaScript stacks.

Browser module

Load the SDK directly in the browser with an ES module import when you want a lightweight HTML-first integration.

Framework-neutral rendering

Use renderAd for fast rollout or render the ad object yourself and call the tracking hooks manually.

Integration in 3 steps

Three lines in your existing message handler. The ad request fires in parallel with your AI call — no added latency.

1

Install and initialize

Create a PromptBid client with your API key and call newConversation() when a chat session starts. One-time setup.

2

Request in parallel

Call requestAd alongside your AI call using Promise.all. If no match, ad is null — nothing renders.

3

Render the suggestion

Wrap in if (ad). Use renderAd for automatic tracking, or render the ad object yourself and call the hooks manually.

Code Examples

Reference implementations for the JavaScript Publisher SDK.

Quickstart
import PromptBid from '@promptbid/sdk';

const pb = new PromptBid({ apiKey: 'pk_live_xxx' });
pb.newConversation();

let previousAIResponse = null;

async function onUserMessage(userMessage) {
  const [aiResponse, ad] = await Promise.all([
    askAI(userMessage),
    pb.requestAd('after-response', {
      userMessage,
      assistantMessage: previousAIResponse,
      topics: ['travel', 'hotels'],
    }),
  ]);

  renderResponse(aiResponse);
  previousAIResponse = aiResponse;

  if (ad) {
    pb.renderAd(ad, document.getElementById('ad-slot'));
  }
}
Custom rendering
if (ad) {
  const el = document.createElement('div');

  const label = document.createElement('p');
  label.textContent = `Sponsored · ${ad.displayUrl ?? ad.advertiser}`;
  el.appendChild(label);

  const headline = document.createElement('p');
  headline.textContent = ad.headline;
  el.appendChild(headline);

  const cta = document.createElement('a');
  cta.href = ad.ctaUrl;
  cta.rel = 'noopener sponsored';
  cta.textContent = ad.ctaText;
  cta.addEventListener('click', () => pb.reportClick(ad.impressionId));
  el.appendChild(cta);

  document.getElementById('ad-slot').replaceChildren(el);
  pb.reportImpression(ad.impressionId);
}

Production checklist

Three things to keep in place before going live.

Label sponsored content clearly

Always render a visible "Sponsored" label. PromptBid's renderAd does this automatically. Transparency builds user trust and keeps your app compliant.

Always guard with if (ad)

When no match is found, requestAd returns null. Wrap your render logic in a null check and your chat will never show an empty slot or broken layout.

Fire the impression hook

Call pb.reportImpression(ad.impressionId) when the suggestion becomes visible. This is how we count a view and how your revenue is recorded.

How PromptBid stays out of the way

The SDK is designed to be invisible when it has nothing to show.

Parallel execution

The ad request fires alongside your AI call via Promise.all. If PromptBid is unreachable, your response still arrives on time.

Contextual matching

Suggestions match the conversation topic — no cookies, no user profiles, no device fingerprinting. Only the current query is used.

Built-in frequency caps

The SDK limits suggestions per conversation automatically. You can override the defaults from your dashboard.

Ready to add it?

Join the closed beta. Live in minutes.