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.
Base URL: https://api.adsrouter.ai. Machine-readable spec: /openapi.json (OpenAPI 3.1.0).
Authentication
POST /v1/ad authenticates a Property using either of two equivalent methods:
| Method | Headers | Notes |
|---|---|---|
| Bearer Secret (recommended) | Authorization: Bearer ar_sec_... |
Looks up the property by SHA-256 hash of the secret (supports grace-window rotation). |
| Key + Secret Pair | X-Property-Key: ar_pub_...X-Property-Secret: ar_sec_... |
Verifies both public key and secret match the same active property. |
Tracking endpoints (GET /v1/imp/:id, GET /v1/render/:id, GET /v1/click/:id, POST /v1/client-event) are unauthenticated browser-callable URLs bound to unguessable impression IDs.
POST /v1/ad
Evaluates mediation rules, targeting, dayparting, pacing, and frequency caps, and returns either a normalized creative, a client-SDK directive (Koah), or a clean no-fill.
Request Body (JSON)
{
"placement": "chat_below_answer",
"messages": [
{ "role": "user", "content": "Compare standing desks for home offices" },
{ "role": "assistant", "content": "Uplift V2 and Jarvis are popular choices..." }
],
"assistant_response": "Optional explicit latest assistant answer",
"session_id": "conv_8821",
"user": {
"maid": "optional-idfa-or-gaid-uuid",
"pub_user_id": "usr_12345"
},
"device": {
"ip": "203.0.113.42",
"ua": "Mozilla/5.0 ...",
"accept_language": "en-US,en;q=0.9",
"country": "US",
"device_type": "desktop",
"platform": "web",
"os": "macOS"
},
"test_mode": false,
"metadata": {
"dimensions": { "maxWidth": 420, "maxHeight": 160 }
}
}
| Field | Type | Required | Description |
|---|---|---|---|
placement | string | No (default "default") | Placement identifier matching your mediation rules and campaign targeting (e.g. chat_below_answer). |
messages | array | Recommended | Array of { role: "user"|"assistant"|"system", content: string } turns used for keyword targeting and S2S contextual networks. |
assistant_response | string | No | Optional latest assistant reply if not already the last item in messages[]. |
session_id | string | No | Conversation/session identifier forwarded to Gravity/Velocity and used to seed deterministic splits. |
user.maid | string | No | Tier-1 identity: Apple IDFA or Google GAID (with end-user consent). |
user.pub_user_id | string | No | Tier-2 identity: opaque publisher-scoped user ID. |
device.ip / device.ua | string | Recommended | End-user IP and User-Agent. Falls back to HTTP request headers if omitted. Required by Gravity and Thrad S2S. |
test_mode | boolean | No | Forces test mode for this request (also inherited if enabled on the property). |
Response: Filled Creative (render_mode: "creative")
{
"request_id": "req_01JXYZ...",
"filled": true,
"render_mode": "creative",
"source": "direct",
"placement": "chat_below_answer",
"ad": {
"id": "imp_01JXYZ...",
"headline": "Upgrade to an ergonomic standing desk",
"description": "Free shipping and a 15-year warranty on all frames.",
"image_url": "https://cdn.example.com/desk.jpg",
"cta": "Explore models",
"brand_name": "Acme Desks",
"favicon_url": "https://cdn.example.com/favicon.png",
"click_url": "https://api.adsrouter.ai/v1/click/imp_01JXYZ...",
"impression_beacon_url": "https://api.adsrouter.ai/v1/imp/imp_01JXYZ...",
"render_beacon_url": null,
"sponsored_label": "Sponsored",
"ttl_ms": 300000
}
}
Note: render_beacon_url is non-null for two-stage networks like Thrad (https://api.adsrouter.ai/v1/render/:id). Fire it on DOM mount, and fire impression_beacon_url when viewable.
Response: Client SDK Directive (render_mode: "client_sdk")
{
"request_id": "req_01JXYZ...",
"filled": true,
"render_mode": "client_sdk",
"source": "koah",
"placement": "chat_below_answer",
"impression_id": "imp_01JXYZ...",
"client_sdk": {
"network": "koah",
"script_url": "https://app.koah.ai/js",
"config": {
"token": "koah_pub_...",
"slot": "chat-below",
"context": {
"type": "conversation",
"question": "Compare standing desks for home offices",
"answer": "Uplift V2 and Jarvis are popular choices..."
},
"dimensions": { "maxWidth": 420, "maxHeight": 160 }
},
"event_beacon_url": "https://api.adsrouter.ai/v1/client-event"
}
}
Response: No-Fill (render_mode: "none")
{
"request_id": "req_01JXYZ...",
"filled": false,
"render_mode": "none",
"placement": "chat_below_answer",
"ad": null
}
Tracking & Health Endpoints
| Endpoint | Behavior |
|---|---|
GET /v1/imp/:id |
Records a viewed impression (viewed_at, increments ar_stats_daily.impressions). Returns 204 No Content (or 1x1 GIF if ?gif=1) for direct/network/house ads, or 302 Found to the upstream network's impression URL for mediated ads. |
GET /v1/render/:id |
Records DOM render (rendered_at) for two-stage networks (Thrad). Returns 204 or 302 to upstream rendered tracker. |
GET /v1/click/:id |
Records a click (clicked_at, increments ar_stats_daily.clicks) and returns 302 Found to the advertiser destination URL (or upstream click URL for mediated ads). |
POST /v1/client-event |
JSON body { "impression_id": "imp_...", "event": "fill" | "no_fill" | "impression" | "click" }. Used by adsrouter-client.js to report Koah client-SDK outcomes. Returns 200 { "ok": true }. |
GET /healthz |
Liveness probe returning 200 { "ok": true }. |
Error Codes
| HTTP Status | Meaning |
|---|---|
200 | Request succeeded (check filled: true|false). Upstream network timeouts or misses never return 5xx. |
400 | Malformed JSON body or invalid request parameters. |
401 | Missing or invalid Authorization: Bearer ar_sec_... or X-Property-Key / X-Property-Secret. |
403 | Property is paused or disabled. |
404 | Unknown impression ID on tracking/redirect endpoints. |