publishers
endpoints
accessing end points and how to fetch data
Fetch Ads Endpoint
The Fetch Ads endpoint is the primary integration point for publishers. This single endpoint handles all ad requests from your AI and returns contextually relevant advertisements based on the conversation context and keywords.
Publisher ImplementationThis is the only endpoint you need to implement to start monetizing your AI with Mosaic.
Request Parameters
Headers:
Header | Description | Required |
---|---|---|
mosaic-api-key | Your unique API key | Yes |
content-type | Must be | Yes |
Request Body:
Parameter Details
Parameter Details¶ | |||
Parameter | Type | Description | Required |
conversation | string | The recent conversation or query from the user. This helps with analytics and future improvements to ad matching. | Yes |
context_keywords | string | Comma-separated keywords extracted from the conversation. These are used to match with relevant ad campaigns. | Yes |
user_location | string | User's location information (e.g., city, country). Helps with geo-targeted ads. | Optional |
user_device_info | string | Information about the user's device or platform. | Optional |
Example Request
Response Format
A successful response will contain an array of advertisements that match the provided keywords. In most cases, only one advertisement will be returned.
Response Fields
Field | Type | Description |
campaign_name | string | Name of the ad campaign |
campaign_text | string | Text content of the advertisement |
campaign_image | string | URL of the image to display (if available) |
campaign_markdown | string | Ready-to-use markdown that combines the ad text, image, and tracking link |
campaign_link | string | Tracking URL that should be used for any clicks on the ad |
bid_per_click | number | The bid amount per click for the ad campaign |
Implementation RecommendationFor most publishers, the simplest implementation is to use the campaign_markdown
field directly in your AI model's response. This field contains the complete ad with proper tracking links already formatted in markdown.
Implementation Guide
Your integration should extract and send relevant keywords from each conversation to the Mosaic API.\
1.Call the API
Once you have the user context or keywords, make a request to the Fetch Ads endpoint:
2. Display the Ad
Finally, display the ad to the user:
How Ad Matching Works
The /api/fetch-ads
endpoint analyzes the conversation context and keywords, matches them against active campaigns, scores for relevance and bid, and returns the most suitable ad with tracking.
Automatic Tracking
Mosaic handles all tracking automatically:
Impressions: Recorded when you call the
/api/fetch-ads
endpointClicks: Tracked when users click on the ad using the provided
campaign_link
Earnings: Calculated based on the campaign's bid amount and your revenue share
Campaign Click Tracking
This endpoint is used internally by the tracking links generated in the /api/fetch-ads
response. You do not need to call this endpoint directly - it's automatically used when a user clicks on an ad.
Publisher NoteThis endpoint is documented for informational purposes only. The tracking links are automatically generated and included in the campaign_markdown
and campaign_link
fields of the /api/fetch-ads
response.
Error Handling
When implementing the Fetch Ads endpoint, be sure to handle these common error scenarios:
Status Code | Error | Description | Recommendation |
400 | Bad Request | Missing required parameters | Check that you're including both conversation and context_keywords |
404 | Not Found | Invalid API key or no matching ads | Verify your API key and try different keywords |
500 | Server Error | Internal server error | Implement retry logic with exponential backoff |
Always implement graceful fallbacks in case no ads are available or the API request fails.