Integrating the Bid Request Endpoint
This guide provides comprehensive instructions on integrating real-time ad auctions within your conversational AI. The Thrad SSP API orchestrates multi-bidder auctions across DSPs and returns winning ad creatives in a single request.Production vs. Sandbox Mode
Important: When integrating the bid request endpoint, it’s crucial to distinguish between production and sandbox environments.
- In sandbox mode (
production: false):- Ads are returned for testing purposes but are not counted for monetization
- An ad will be served on every request to facilitate testing and integration
- In production mode (
production: true):- Ads are live and contribute to monetization
- Ad serving depends on match strength - ads are only shown when there’s a strong contextual match between the conversation and available products
- You may receive
"bid": nullresponses when no suitable match is found
production: true is used only in your live production environment. For all testing and development, set production: false.How the Bid Request Works
The bid request endpoint orchestrates a sophisticated auction process:- Validate Request: Checks authentication, rate limits, and request format
- Fan Out to DSPs: Sends bid requests to multiple DSPs in parallel (timeout: 1.5s)
- Run Auction: Selects winner using first-price auction with floor price ($1.00 CPM minimum)
- Render Ad: Calls winning DSP’s render endpoint to get ad creative (timeout: 1.5s)
- Return Response: Returns winning ad creative or no-bid response
User and Chat Identification
Implementation Examples
JavaScript (Browser)
Python (Server-Side)
Message Format
The API expects conversation messages in a specific format:Important: Messages must alternate between
user and assistant roles. Include at least 2 messages (one user, one assistant). The last pair should be a user message followed by an assistant response.Response Handling
Success Response with Bid
No Bid Response
A
200 OK response with "bid": null is not an error. It means the auction ran successfully but no DSP submitted a winning bid. This is normal behavior and should be handled gracefully in your UI.Recommended Implementation Flow
1
User sends a message
Capture the user message and add it to your conversation history
2
Chatbot processes and responds
Your chatbot generates and returns a response. Add it to conversation history.
3
Call Thrad Bid Request API
Send the complete conversation history (with both user and assistant messages) to the Thrad bid request endpoint
4
Handle Response
- If bid is returned: Render the ad creative
- If no bid: Continue without showing an ad
- If error: Log for debugging and continue without ad
5
Render Ad Creative
Display the ad as a distinct element in your UI:
- Use a visually distinct style (border or background)
- Show advertiser name and “Sponsored” label
- Include headline and description
- Add product image (if provided)
- Make the entire ad clickable using the
urlfield (includes click tracking) - Include the CTA button with
cta_text
Best Practices
1. Always Include Timestamps
Including timestamps enables better analytics and targeting:2. Handle Timeouts Gracefully
The endpoint has built-in timeouts (~3s max). Always handle potential delays:3. Respect Rate Limits
The API supports 40 requests per second per API key. Monitor rate limit headers:4. CORS Configuration
For browser-based requests, register your domains with Thrad:- Contact contact@thrad.ai to whitelist your domains
- Include the
Originheader in requests - Handle CORS preflight requests properly
5. Maintain Conversation Context
Keep the conversation history accurate for better ad relevance:6. Error Handling
Handle all possible response scenarios:UI Rendering Example
When rendering the ad creative, ensure it’s visually distinct and includes all required elements:Example Ad Rendering in a Chat Interface
Here’s how a sponsored message might appear in your chat application:
Testing Your Integration
- Start with sandbox mode: Set
production: falseduring development - Test with various conversation flows: Try different topics and conversation lengths
- Handle no-bid scenarios: Ensure your UI gracefully handles null bids
- Test error scenarios: Verify error handling works correctly
- Monitor performance: Track request latency and success rates
Next Steps
- Review the complete API Reference for detailed parameter documentation
- Set up monitoring for request success rates and latency
- Configure your domains for CORS support
- Contact support@thrad.ai for production API key and assistance