Skip to main content

Overview

Replit is an online IDE and AI app builder. You can integrate ChatAds using Replit Agent or by installing the TypeScript or Python SDK directly through the built-in package manager.
Replit supports both TypeScript/Node.js and Python — use whichever SDK matches your project.

Setup

Step 1: Set Up ChatAds

  1. Create a ChatAds account and upload your Amazon Affiliate Associates ID (ChatAds is Amazon-only right now)
  2. Go to app.getchatads.com/api/keys and create an API key. Call it “Replit” to keep track of it

Step 2: Add Your API Key as a Secret

  1. Open your Repl
  2. Go to Tools → Secrets in the sidebar
  3. Add a new secret: key = CHATADS_API_KEY, value = your API key

Step 3: Install the SDK

npm install @chat-ads/chatads-sdk

Step 4: Call the API

import { ChatAdsClient } from '@chat-ads/chatads-sdk';

const client = new ChatAdsClient({
  apiKey: process.env.CHATADS_API_KEY,
});

// After your AI generates a response:
const result = await client.analyzeMessage(aiResponse);

if (result.data.returned > 0) {
  let finalResponse = aiResponse;
  for (const offer of result.data.offers) {
    finalResponse = finalResponse.replace(
      offer.link_text,
      `<a href="${offer.url}" target="_blank">${offer.link_text}</a>`
    );
  }
  // Send finalResponse to the user
}

Using Replit Agent

If you prefer to use Replit’s AI agent, paste this prompt:
Add ChatAds affiliate link monetization to this app.

ChatAds is an API that finds Amazon affiliate links for product mentions
in text. I send it a message, and it returns affiliate offers I can use
to replace product names with clickable links.

What I need:

1. Install the ChatAds SDK:
   - For Node.js/TypeScript: npm install @chat-ads/chatads-sdk
   - For Python: pip install chatads-sdk

2. Use the CHATADS_API_KEY secret (already set in Replit Secrets)

3. After the AI generates a response but before sending it to the user:
   - Call ChatAds with the AI response text as the message
   - If data.returned > 0, loop through data.offers and find each
     offer's link_text in the AI response, then wrap it in an anchor
     tag using the offer's url (target="_blank")
   - If data.returned is 0 or there's an error, use the original
     AI response unchanged

4. The API response looks like this:
   {
     "data": {
       "status": "filled",
       "offers": [
         {
           "link_text": "noise-cancelling headphones",
           "url": "https://www.amazon.com/dp/B0XXXXXXXXX?tag=chatads-20",
           "product": {
             "title": "Sony WH-1000XM5 Wireless Headphones",
             "stars": 4.5,
             "reviews": 12340
           }
         }
       ],
       "returned": 1
     },
     "error": null
   }

Troubleshooting

401 Unauthorized errors

Your API key isn’t being read. Verify the secret name matches exactly:
  • Go to Tools → Secrets
  • Confirm the key is named CHATADS_API_KEY (case-sensitive)
  • Make sure you’re reading it with process.env.CHATADS_API_KEY (Node) or os.environ["CHATADS_API_KEY"] (Python)

Module not found

If the SDK isn’t installing, check your package.json or requirements.txt:
  • TypeScript: run npm install @chat-ads/chatads-sdk in the Shell tab
  • Python: run pip install chatads-sdk in the Shell tab
  1. Test your message in the API Explorer first to confirm it returns offers
  2. Check the Replit console for errors
  3. Verify you’re checking data.returned > 0 before replacing text

Response Reference

FieldTypeDescription
data.statusstring"filled" if offers found, "empty" otherwise
data.returnednumberNumber of offers returned
data.offers[].link_textstringText to match in the original message
data.offers[].urlstringAffiliate link URL
data.offers[].product.titlestringProduct name
data.offers[].product.starsnumberProduct rating (0-5)
data.offers[].product.reviewsnumberReview count
See the full API Reference for all available parameters and response fields.

Best Practices

Use Replit Secrets

Never hardcode your API key. Always use Replit’s Secrets feature to keep credentials secure.

Don't block rendering

Show content immediately and update with affiliate links when the API responds. Users shouldn’t wait for ChatAds.

Handle empty gracefully

Not every message will have affiliate matches. Always check data.returned > 0 before modifying text.

Test in API Explorer

Verify your messages return offers in the API Explorer before debugging Replit code.