Optimize Exa costs through tier selection, sampling, and usage monitoring.
Use when analyzing Exa billing, reducing API costs,
or implementing usage monitoring and budget alerts.
Trigger with phrases like "exa cost", "exa billing",
"reduce exa costs", "exa pricing", "exa expensive", "exa budget".
Reduce Exa API costs through strategic search type selection, result caching, query deduplication, and usage monitoring. Exa charges per search request with costs varying by search type and content retrieval options.
Cost Drivers
Factor
Higher Cost
Lower Cost
Search type
deep-reasoning > deep > neural
keyword < fast < instant
numResults
10-100 results
3-5 results
Content retrieval
Full text + highlights + summary
Metadata only (no content)
Content length
maxCharacters: 5000
maxCharacters: 500
Live crawling
livecrawl: "always"
Cached content (default)
Instructions
Step 1: Match Search Config to Use Case
import Exa from "exa-js";
const exa = new Exa(process.env.EXA_API_KEY);
// Define cost tiers per use case
const SEARCH_PROFILES = {
// Cheapest: metadata-only keyword search
"autocomplete": { type: "instant" as const, numResults: 3 },
// Low cost: fast search with minimal content
"quick-lookup": { type: "fast" as const, numResults: 3 },
// Medium: balanced search for RAG
"rag-context": {
type: "auto" as const,
numResults: 5,
text: { maxCharacters: 1000 },
},
// Higher cost: deep research
"deep-research": {
type: "neural" as const,
numResults: 10,
text: { maxCharacters: 3000 },
highlights: { maxCharacters: 500 },
},
};
async function costAwareSearch(
query: string,
profile: keyof typeof SEARCH_PROFILES
) {
const config = SEARCH_PROFILES[profile];
if ("text" in config || "highlights" in config) {
return exa.searchAndContents(query, config);
}
return exa.search(query, config);
}
function deduplicateQueries(queries: string[]): string[] {
const seen = new Set<string>();
return queries.filter(q => {
const normalized = q.toLowerCase().trim().replace(/\s+/g, " ");
if (seen.has(normalized)) return false;
seen.add(normalized);
return true;
});
}
// Before batch processing, deduplicate
const uniqueQueries = deduplicateQueries(allQueries);
console.log(`Deduped: ${allQueries.length} → ${uniqueQueries.length} queries`);
// Typical dedup rate: 20-40% for batch processing
Step 4: Use Keyword Search When Appropriate
// Neural search: best for semantic/conceptual queries (more expensive)
// Keyword search: best for specific terms/names (cheaper, faster)
function selectCostEffectiveType(query: string): "neural" | "keyword" | "auto" {
// Use keyword for exact lookups
if (query.match(/^https?:\/\//)) return "keyword"; // URL lookup
if (query.match(/^[A-Z][a-z]+ [A-Z]/)) return "keyword"; // Proper nouns
if (query.includes('"')) return "keyword"; // Quoted terms
// Use neural for conceptual queries
if (query.split(" ").length > 5) return "neural";
return "auto"; // Let Exa decide for ambiguous queries
}