React SDK
Pass the ad returned by Gravity to GravityAd:
GravityAd automatically handles the placement design, fallback, impression and click tracking, disclosure, and feedback controls.
Pass the API key used for the ad request to enable feedback submissions:
apiKey is visible in the browser and used for feedback submissions. Pass it down from your server
with the ad response rather than referencing a server-only environment
variable in client code — bundlers either drop the value or inline your
server secret into the bundle.
JavaScript and TypeScript SDK
Set GRAVITY_API_KEY in your server environment.
Prepare context
In your client application, prepare the session and user context:
Forward the complete gravity_context to your server.
Request ads
Request ads in parallel with your LLM call:
gravity.getAds() returns { ads: [] } on no-fill or failure, so render the slot conditionally. Keep one stable sessionId per conversation.
Custom rendering
Use GravityAd unless you need a fully custom renderer. Custom renderers must open ad.clickUrl, request ad.impUrl once when the ad becomes visible, and show a clear ad disclosure.