Documentation Index
Fetch the complete documentation index at: https://docs.trygravity.ai/llms.txt
Use this file to discover all available pages before exploring further.
What you’re going to do
- Create an AI platform account and grab your API key.
- Install the SDK.
- Fire ad requests from your server in parallel with your LLM call.
- Render the ad in your chat UI.
- Drop the web pixel on your site.
- Flip to production when it looks right.
Throughout this guide we use the SDK (
@gravity-ai/api + @gravity-ai/react). If you’d rather hit the HTTP API directly, see the API Reference. Same engine, you just own the rendering and tracking.1. Create your account
- Sign up at app.trygravity.ai/publisher/signup.
- Create an AI platform account for your app.
- From your dashboard, copy the API key and the Pixel ID.
GRAVITY_API_KEY in your server environment.
2. Install the SDK
3. Prepare context on the client
CallgravityContext() in your chat component so the server gets the session ID and device signals alongside the messages.
4. Fetch ads on the server
Fire the ad request in parallel with your LLM call. It never throws — failures return an empty array.5. Render the ad
GravityAd handles impression tracking automatically via IntersectionObserver, wires the click URL for attribution, and supports 20+ visual variants (card, minimal, inline, spotlight, pill, banner, hyperlink, etc.). Pick whichever fits your UI.
6. Install the pixel (required)
The Gravity pixel is required for attribution and payouts. Without it, Gravity can’t measure visitor journeys or tie ad performance back to real outcomes. Drop this on every page:7. Verify, then go live
By default,new Gravity() returns test ads — no billing, safe to iterate. You’ll see the same test creative every time.
When you’re ready for real traffic:
Full integration guide
The long version: lifecycle, placements, error handling, framework-specific examples.
Going live checklist
Everything to verify before flipping
production: true.What you didn’t have to think about
- Retries — the SDK handles transient failures silently.
- Timeouts — 3 seconds by default. Configurable.
- Impression / click tracking — fired by
GravityAd. Attribution is automatic. - Experiments — the engine can test different ad variants for your traffic without you shipping code. See Experiments.
- Ad quality — Gravity handles the creative; you never hand-pick advertisers.
Troubleshooting
Getting empty ad arrays in production
Getting empty ad arrays in production
Expected when no campaign matches the conversation — the engine returns
204 No Content and the SDK resolves to { ads: [] }. Gracefully hide the ad slot. Lower the relevancy threshold to fill more aggressively if you want looser matches.I'm seeing the same ad every request
I'm seeing the same ad every request
You’re still on test mode. Pass
production: true to the constructor or set production=True in Python.Ads appear but impressions aren't counting
Ads appear but impressions aren't counting
If you’re using
GravityAd, it fires on visibility via IntersectionObserver — make sure the ad is actually rendering in the viewport. If you render ads with a custom component, you have to fire the impression pixel yourself: new Image().src = ad.impUrl when the ad becomes visible.