Request contextual ads
Analyzes conversation context and returns relevant ads. One ad is returned per placement in the request.
How It Works
- Send the user's current message (and optionally the previous assistant response for context)
- Gravity extracts intent, matches against active ad campaigns, runs a real-time auction, and generates ad creative
- You receive an array of ad objects — one per placement
Message Context
Include the user's current query and the previous assistant response (if available) for better ad matching.
- First turn: Just the user query
- Follow-up turns: Previous assistant response + current user query
No-Fill (204)
A 204 No Content response means no suitable ad was found. This is normal — not every request will return an ad. Handle this gracefully by hiding or collapsing your ad slot.
Impression Tracking
When an ad is displayed to the user, fire a GET request to the impUrl. This is required for billing. Impression URLs expire 5 minutes after the ad response is generated — do not cache or defer ad responses.
For clicks, redirect users through clickUrl. It handles attribution and forwards to the advertiser's landing page.
Additional Context
The request body accepts additional key-value pairs beyond the documented fields. Any extra structured data you include (e.g., app-specific context, IDE metadata) is used to improve ad relevance.
Request
- Base URL: https://server.trygravity.ai
- URL: https://server.trygravity.ai/api/v1/ad
- Auth: HTTP bearer
Request body
Example request
{
"messages": [
{
"role": "user",
"content": "What running shoes do you recommend for a marathon?"
}
],
"sessionId": "session-abc123",
"placements": [
{
"placement_id": "main-ad"
}
],
"userId": "user-xyz789",
"device": {
"ip": "203.0.113.42",
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
"country": "US",
"os": "macOS",
"ifa": "6D92078A-8246-4BA4-AE5B-76104861E7DC"
},
"user": {
"email": "user@example.com",
"phone": "+15551234567",
"age": "25",
"keywords": "fitness, running, sports"
},
"excludedTopics": [
"gambling",
"alcohol"
],
"relevancy": 0.3
}Response
Ads matched and returned. The response is a JSON array with one ad per matched placement. If fewer campaigns match than placements requested, the array may be shorter than the number of placements.
Example response
[
{
"adText": "Fuel your marathon with GelPro energy gels — trusted by 10,000+ runners!",
"title": "GelPro Energy Gels",
"cta": "Shop Now",
"brandName": "GelPro",
"url": "https://gelpro.com/runners",
"favicon": "https://gelpro.com/favicon.ico",
"impUrl": "https://api.trygravity.ai/t/imp?p=eyJ...",
"clickUrl": "https://api.trygravity.ai/t/click?p=eyJ...",
"placement": "below_response",
"placement_id": "main-ad"
}
]Changes
No recorded changes to this operation across all 1 revision of this API.