Skip to content
Documentation menu
HTTP APIWeb

Web: HTTP API

HTTP API for fetching ads and handling interactive actions in web apps.

IntegrationRenderingRequests and views
Web SDKrequestAd()SDK
API + renderermountSidekickAd()Application code
API + componentsApplication componentsApplication code

Authentication

Exactly one identity required: visitor_id or stable_user_id. Characters: A-Z, a-z, 0-9, _, ., :, -. API key: server-side only, no Origin.

CallerAuthenticationIdentity
BrowserPlatform ID and an allowed site address. The browser supplies Origin.visitor_id
ServerAuthorization: Bearer sk_live_…stable_user_id or visitor_id

Platform and site address requirements →

Request an ad

Content-Type: application/json; body ≤64 KiB.

POST /api/v1/web/ads

FieldTypeDescription
platform_idrequiredstringPublic platform ID.
visitor_idstringVisitor ID, 16-128 characters. Required for browser requests.
stable_user_idstringUser ID, 1-128 characters. Available for server requests instead of visitor_id.
request_idstringRequest ID, 1-128 characters. Reusing it does not prevent another ad issuance.
placementstringRegistered placement name. Defaults to chat.
language_codestringAd language, 1-32 characters. Defaults to en.
accept_formatsstring[]text, image, response, card, consent, quiz. Defaults to all formats.
contextobjectAd context. Fields depend on context.type.
testbooleanTest ads without billing. Defaults to false. A Test platform always returns demo ads.
test_formatstringTest ad format when test is true.

Required fields.

Server request

POST /api/v1/web/ads
POST /api/v1/web/ads
Authorization: Bearer sk_live_EXAMPLE
Content-Type: application/json
{
"platform_id": "plt_example",
"stable_user_id": "customer_42",
"context": {
"question": "Headphones?",
"answer": "Here are some options…"
},
"test": true,
"test_format": "card"
}

Browser request

fetch()
const response = await fetch("https://sidekick-ads.com/api/v1/web/ads", {
method: "POST",
credentials: "omit",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
platform_id: "plt_example",
visitor_id: visitorId,
request_id: "chat-42-message-7",
test: true,
test_format: "card"
})
});
if (!response.ok) throw new Error("Ad request failed");
const payload = await response.json();

Context

context: optional object. Text fields: plain text, no HTML. No automatic page extraction.

Type and useFieldsLimits
conversation
Assistant conversation
question: user question; answer: app answer.Both optional: 0-4,096 and 0-16,384 characters. Default when type is omitted.
article
Article
title: title; content: relevant excerpt.Both required and nonempty: 1-4,096 and 1-16,384 characters.
feed
Feed item
textRequired nonempty text: 1-16,384 characters.
static
Slot without text
-Only type. Do not add question, answer or other text fields.
Four context examples: choose one
// Chat
const context = {
type: "conversation",
question: "Which headphones suit travel?",
answer: "Look for noise cancellation and a compact case."
};
// Article
// context: { type: "article", title: "Travel audio", content: "A relevant excerpt…" }
// Feed
// context: { type: "feed", text: "Text of the current feed item…" }
// No surrounding text
// context: { type: "static" }

Response

FieldTypeDescription
has_adbooleanWhether the response includes an ad.
adobject | nullAd object; null when no ad is available.
ad.delivery_idstringDelivery ID for interactions.
ad.expires_atstringAd expiry in ISO 8601 format.
ad.formatstringAd format.
ad.disclosurestringRequired advertising disclosure.
ad.testbooleanWhether this is a test ad.
ad.blocksobject[]text, media, gallery and buttons blocks in display order.
ad.viewstring?Token for confirming a live ad view. Absent on test ads. Views
200 OK · No fill
{
"has_ad": false,
"ad": null
}

Ad blocks

typeFieldsRendering
textspans, role?Text composed of consecutive spans. role: body, brand or footer.
mediaurl, mime, alt?, role?Image or video. role=logo: logo. Appearance settings control cropping.
galleryitemsArray of media blocks. All items remain accessible.
buttonsbuttonsAll buttons and complete labels; long labels wrap.

Text span: spans[]

FieldTypeValue
textstringRequired. Plain text; line breaks preserved. No HTML.
bold / italic / underline / strikethrough / codeboolean?Span style
urlstring?HTTP(S)

Button: buttons[]

FieldTypeValue
id / textstringRequired
stylestring?primary / secondary
url / actionstringExactly one. url: navigation; action: original token for /interact.

Files and links

Media: HTTPS; image/jpeg, image/png, image/webp, image/gif, video/mp4. Video: muted, playsInline. Links: HTTP(S), no prefetch.

Example filled response
{
"has_ad": true,
"ad": {
"delivery_id": "imp_example",
"expires_at": "2099-01-01T00:00:00.000Z",
"format": "text",
"disclosure": "Sponsored",
"test": true,
"blocks": [
{
"type": "text",
"role": "body",
"spans": [
{
"text": "Try a service for your next trip.",
"bold": true
}
]
},
{
"type": "buttons",
"buttons": [
{
"id": "primary",
"text": "Learn more",
"style": "primary",
"url": "https://example.com/offer"
}
]
},
{
"type": "text",
"role": "footer",
"spans": [
{
"text": "Sponsored · Sidekick"
}
]
}
]
}
}

Ready-made card for the API

/my-ads/*: application endpoints. The server must add platform_id, authorization and the original user identity.

Load the renderer
<div id="ad-slot"></div>
<script src="https://sidekick-ads.com/sdk/sidekick-web.js"></script>
Fetch, render, interact and confirm views
// Load /sdk/sidekick-web.js first. These /my-ads/* routes belong to YOUR app.
// Your backend adds the publisher key, platform_id and authenticated user ID.
function mountServerAd(slot, request) {
let destroyed = false, active = true, visible = false, sent = false;
let ad = null, timer;
const abort = new AbortController();
const report = error => console.warn("Ad unavailable", error.message);
const post = async (path, body) => {
const response = await fetch(path, {
method: "POST", credentials: "same-origin", signal: abort.signal,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body)
});
if (!response.ok) throw new Error("Ad request failed: " + response.status);
return response.json();
};
const view = Sidekick.mountSidekickAd(slot, {
appearance: { maxWidth: 360, mediaHeight: 200, mediaFit: "cover", mediaPosition: "top", mediaRadius: 12 },
onError: report,
onAction: async (current, action) => {
const result = await post("/my-ads/interact", {
delivery_id: current.delivery_id, action
});
if (result.ok !== true) throw new Error("Interaction failed");
return result.ad;
}
});
function checkView() {
const eligible = !destroyed && active && visible && !document.hidden &&
ad && !ad.test && ad.view && Date.parse(ad.expires_at) > Date.now();
if (!eligible || sent) { clearTimeout(timer); timer = undefined; return; }
if (timer === undefined) timer = setTimeout(() => {
timer = undefined;
if (Date.parse(ad.expires_at) <= Date.now()) return;
sent = true; observer.disconnect();
void post("/my-ads/seen", { delivery_id: ad.delivery_id, view: ad.view }).catch(report);
}, 1000);
}
const observer = new IntersectionObserver(entries => {
visible = entries.some(e => e.isIntersecting && e.intersectionRatio >= 0.5);
checkView();
}, { threshold: [0, 0.5, 1] });
document.addEventListener("visibilitychange", checkView);
const controls = {
setScreenActive(value) { active = value; view.setScreenActive(value); checkView(); },
destroy() {
destroyed = true; clearTimeout(timer); observer.disconnect(); abort.abort();
document.removeEventListener("visibilitychange", checkView); view.destroy();
}
};
// Call once per ad opportunity. Store the returned controls on your component.
// This example deliberately has no automatic retries or SPA request cache.
void post("/my-ads/ads", request).then(payload => {
if (destroyed) return;
ad = payload.has_ad ? Sidekick.parseAd(payload.ad) : null;
view.setAd(ad);
if (ad && !ad.test && ad.view) observer.observe(view.element);
}).catch(error => { if (!destroyed) report(error); });
return controls;
}
const card = mountServerAd(document.querySelector("#ad-slot"), {
request_id: "chat-42-message-7",
context: { type: "static" },
test: true, test_format: "card"
});
// When covering the screen: card.setScreenActive(false).
// When removing the component: card.destroy().
Option or methodPurpose
appearance / setAppearance(options)Shared card appearance settings. Updating them does not fetch ads.
setAd(ad | null)ad object: render; null: clear the card.
onAction(ad, action)Promise of the next ad or null. Errors preserve the last scene; action buttons are disabled without a handler.
onOpenURL(url)Optional navigation handler. The default opens a new tab.
onError(error)Data, media and action errors. Invalid data or media failures clear the card.
screenActive / setScreenActive(boolean)Controls media playback; defaults to true. The wrapper above also pauses view timing.
elementThe card wrapper to observe for visibility.
destroy()Removes the card and releases renderer resources.

Interactions

Requires delivery_id, action and the original user identity. Response: {ok: true, ad}. ad replaces the current scene.

POST /api/v1/web/interact

POST /api/v1/web/interact
{
"platform_id": "plt_example",
"stable_user_id": "customer_42",
"delivery_id": "imp_example",
"action": "signed-action-from-button"
}

View confirmation

ParameterValue
Visibility≥50% for ≥1 continuous second; active tab and screen.
requestAd()Automatic
fetchAd()trackView(ad)
API / mountSidekickAd()POST /api/v1/web/seen
Authorization / identitySame platform_id and visitor_id or stable_user_id as /ads.
viewTTL: 1 hour. Repeated confirmation does not duplicate the impression.
Response{ok: true}

POST /api/v1/web/seen

POST /api/v1/web/seen
{
"platform_id": "plt_example",
"stable_user_id": "customer_42",
"delivery_id": "imp_example",
"view": "view-receipt-from-ad"
}

Errors

StatusMeaning
400Invalid request fields or user identity.
401Missing or invalid API key.
403Platform disabled, site address not allowed or API key belongs to another publisher.
409View confirmation sent sooner than one second after issuance.
410Action or view receipt is invalid or has expired.
413Request body exceeds 64 KiB.
429Request rate limit exceeded.
503Service temporarily unavailable.
Example error
{ "error": "Unknown placement" }