Quick Start
Get up and running with NotPixel in under 5 minutes.
Basic Usage
import Ads from 'notpixel';
const ads = new Ads({
publisherId: 'pub_xxx',
model: 'openai/gpt-5.2',
input: 'How do I optimize SQL queries for better performance?',
});
const response = await ads.offer();
console.log(response.text);
// Output:
// To optimize SQL queries, consider these strategies...
//
// ---
// Sponsored: DataDog Monitoring
// Real-time SQL insights and performance tracking.
// Learn more: https://datadoghq.comThat’s it. The SDK:
- Routes your input to the specified LLM provider
- Fetches a relevant ad in parallel
- Returns the LLM response with the ad seamlessly integrated
Configuration
Pass everything in the constructor:
| Option | Required | Description |
|---|---|---|
publisherId | Yes | Your publisher ID |
model | Yes | LLM model in provider/model format |
input | Yes | User’s input text |
cache | No | Enable caching (default: false) |
locale | No | Ad locale: 'pt' or 'en' (default: 'pt') |
const ads = new Ads({
publisherId: 'pub_xxx',
model: 'openai/gpt-5.2',
input: 'Explain microservices architecture',
cache: true,
locale: 'en',
});Multiple Requests
For multiple requests, you can override the input per call:
const ads = new Ads({
publisherId: 'pub_xxx',
model: 'openai/gpt-5.2',
});
// First request
const r1 = await ads.offer({ input: 'What is Docker?' });
// Second request
const r2 = await ads.offer({ input: 'How do I deploy to AWS?' });Just Fetch an Ad
If you only need the ad (not the LLM response):
const ads = new Ads({
publisherId: 'pub_xxx',
input: 'cloud hosting recommendations',
});
const ad = await ads.getAd();
if (ad) {
console.log(ad.headline); // "AWS Cloud Services"
console.log(ad.body); // "Scale your infrastructure..."
console.log(ad.cta.url); // "https://aws.amazon.com"
}Environment Variables
API keys are read from environment automatically:
.env
OPENAI_API_KEY=sk-...
# or
ANTHROPIC_API_KEY=sk-ant-...
# or
GOOGLE_API_KEY=AI...See Environment Variables for all available options.
Tracking (Optional)
For client-side tracking, use the Browser Tracking library.
Next Steps
- See all available Models
- Learn about Caching
- Set up React Components