Optional identifier for a publisher’s sub-client or network partner. Use this to segment statistics on the dashboard per client within your publisher network.
Conversation history. Must contain at least 2 messages (user and assistant). Messages must alternate between user and assistant roles, ending with a user message followed by an assistant message.
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.
/** * Get or create persistent anonymous user ID * REQUIRED: You must implement this to track users across sessions */function getUserId() { const STORAGE_KEY = 'thrad_user_id'; let userId = localStorage.getItem(STORAGE_KEY); if (!userId) { // Generate new anonymous ID (no PII - just a random UUID) userId = 'user_' + crypto.randomUUID(); localStorage.setItem(STORAGE_KEY, userId); } return userId;}/** * Get or create chat ID (one per conversation) * REQUIRED: You must implement this to track ads per conversation */function getChatId() { const STORAGE_KEY = 'thrad_chat_id'; let chatId = sessionStorage.getItem(STORAGE_KEY); if (!chatId) { chatId = 'chat_' + crypto.randomUUID(); sessionStorage.setItem(STORAGE_KEY, chatId); } return chatId;}// Make bid requestconst response = await fetch('https://ssp.thrads.ai/api/v1/ssp/bid-request', { method: 'POST', headers: { 'thrad-api-key': 'your-api-key', 'Content-Type': 'application/json' }, body: JSON.stringify({ userId: getUserId(), chatId: getChatId(), client_id: "client_abc", // Optional: identifier for your sub-client or network partner messages: conversationMessages, production: true, turn_number: currentTurn, adtype: "" // or "opener" for pre-conversation ads })});const data = await response.json();if (data.data.bid) { // Display ad creative console.log('Ad:', data.data.bid);} else { // No bid - continue without ad console.log('No ad available');}