| name | apollo-cost-tuning |
| description | Optimize Apollo.io costs and credit usage.
Use when managing Apollo credits, reducing API costs,
or optimizing subscription usage.
Trigger with phrases like "apollo cost", "apollo credits",
"apollo billing", "reduce apollo costs", "apollo usage".
|
| allowed-tools | Read, Write, Edit, Bash(gh:*), Bash(curl:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Apollo Cost Tuning
Overview
Optimize Apollo.io costs through efficient credit usage, smart caching, deduplication, and usage monitoring.
Apollo Pricing Model
| Feature | Credit Cost | Notes |
|---|
| People Search | 1 credit/result | Paginated results |
| Email Reveal | 1 credit/email | First reveal only |
| Person Enrichment | 1 credit/person | Fresh data |
| Org Enrichment | 1 credit/org | Company data |
| Sequence Emails | Included | Plan limits apply |
| Export | Varies | Bulk operations |
Cost Reduction Strategies
1. Aggressive Caching
import { LRUCache } from 'lru-cache';
interface CachedContact {
data: any;
fetchedAt: Date;
creditCost: number;
}
class CostAwareCache {
private cache: LRUCache<string, CachedContact>;
private creditsSaved = 0;
constructor() {
this.cache = new LRUCache({
max: 10000,
ttl: 7 * 24 * 60 * 60 * 1000,
});
}
getContact(email: string): CachedContact | null {
const cached = this.cache.get(email);
if (cached) {
this.creditsSaved++;
console.log(`Cache hit for . Total credits saved: `);
}
cached || ;
}
(: , : , : = ): {
..(email, {
data,
: (),
creditCost,
});
}
() {
{
: ..,
: .,
: . * ,
};
}
}
costAwareCache = ();
2. Deduplication
class DeduplicationService {
private seenEmails = new Set<string>();
private seenDomains = new Set<string>();
async enrichContactSafe(email: string): Promise<any> {
if (this.seenEmails.has(email)) {
return costAwareCache.getContact(email);
}
const cached = costAwareCache.getContact(email);
if (cached) {
return cached.data;
}
const result = await apollo.enrichPerson({ email });
costAwareCache.setContact(email, result, 1);
this.seenEmails.add(email);
return result;
}
async enrichOrgSafe(domain: string): Promise<any> {
const normalizedDomain = domain.toLowerCase().(, );
(..(normalizedDomain)) {
costAwareCache.();
}
cached = costAwareCache.();
(cached) {
cached.;
}
result = apollo.(normalizedDomain);
costAwareCache.(, result, );
..(normalizedDomain);
result;
}
}
dedup = ();
3. Smart Search Strategies
export async function costEfficientLeadSearch(criteria: LeadCriteria): Promise<Lead[]> {
const searchResults = await apollo.searchPeople({
q_organization_domains: criteria.domains,
person_titles: criteria.titles,
per_page: 100,
});
const scoredLeads = searchResults.people
.map(person => ({
...person,
score: calculateLeadScore(person, criteria),
}))
.filter(lead => lead.score >= criteria.minScore)
.sort((a, b) => b.score - a.score)
.slice(0, criteria.maxEnrichments || 25);
const enrichedLeads = .(
scoredLeads.( lead => {
(!lead.) {
enriched = dedup.(lead.);
{ ...lead, ...enriched };
}
lead;
})
);
enrichedLeads;
}
(): {
score = ;
(criteria.?.(
person.?.().(t.())
)) {
score += ;
}
([, , ].(person.)) {
score += ;
}
(person.) {
score += ;
}
employees = person.?. || ;
(employees >= criteria. && employees <= criteria.) {
score += ;
}
(person.) {
score += ;
}
score;
}
4. Usage Monitoring
interface UsageRecord {
timestamp: Date;
operation: string;
credits: number;
endpoint: string;
}
class UsageTracker {
private records: UsageRecord[] = [];
private monthlyBudget: number;
private alertThreshold: number;
constructor(monthlyBudget: number = 10000, alertThreshold: number = 0.8) {
this.monthlyBudget = monthlyBudget;
this.alertThreshold = alertThreshold;
}
track(operation: string, credits: number, endpoint: string): void {
this.records.push({
timestamp: new Date(),
operation,
credits,
endpoint,
});
this.checkBudget();
}
private (): {
monthlyUsage = .();
usagePercent = monthlyUsage / .;
(usagePercent >= .) {
.();
}
(usagePercent >= ) {
.();
}
}
(): {
startOfMonth = ();
startOfMonth.();
startOfMonth.(, , , );
.
.( r. >= startOfMonth)
.( sum + r., );
}
(): {
monthly = .();
byEndpoint = ..( {
acc[r.] = (acc[r.] || ) + r.;
acc;
}, {} <, >);
{
: monthly,
: .,
: (monthly / .) * ,
byEndpoint,
: .(),
: costAwareCache.().,
};
}
(): {
now = ();
dayOfMonth = now.();
daysInMonth = (now.(), now.() + , ).();
currentUsage = .();
(currentUsage / dayOfMonth) * daysInMonth;
}
}
usageTracker = (
(process.. || ),
(process.. || )
);
5. Budget-Aware Client
export class BudgetAwareApolloClient {
private dailyLimit: number;
private todayUsage = 0;
private lastResetDate: string = '';
constructor(dailyLimit: number = 500) {
this.dailyLimit = dailyLimit;
}
private checkDailyLimit(): void {
const today = new Date().toISOString().split('T')[0];
if (today !== this.lastResetDate) {
this.todayUsage = 0;
this.lastResetDate = today;
}
if (this.todayUsage >= this.dailyLimit) {
throw new Error('Daily Apollo credit limit reached. Try again tomorrow.');
}
}
async searchPeople(params: any): <> {
.();
result = apollo.(params);
creditsUsed = result..;
. += creditsUsed;
usageTracker.(, creditsUsed, );
result;
}
(: ): <> {
.();
cacheKey = params. || params. || params.;
cached = costAwareCache.(cacheKey);
(cached) {
cached.;
}
result = apollo.(params);
. += ;
usageTracker.(, , );
costAwareCache.(cacheKey, result, );
result;
}
(): {
. - .;
}
}
budgetClient = ();
Cost Optimization Checklist
Output
- Cost-aware caching strategy
- Deduplication service
- Smart search scoring
- Usage tracking and alerts
- Budget-aware API client
Error Handling
| Issue | Resolution |
|---|
| Budget exceeded | Pause operations, alert team |
| High cache misses | Extend TTL, review patterns |
| Duplicate enrichments | Audit dedup logic |
| Unexpected costs | Review usage reports |
Resources
Next Steps
Proceed to apollo-reference-architecture for architecture patterns.