Skip to content
exa-cost-tuning logo

Exa Cost Tuning

exa-cost-tuning

Optimize Exa costs through search type selection, caching, and usage

SKILL.md

Full skill instructions

Exa Cost Tuning

Overview

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

FactorHigher CostLower Cost
Search typedeep-reasoning > deep > neuralkeyword < fast < instant
numResults10-100 results3-5 results
Content retrievalFull text + highlights + summaryMetadata only (no content)
Content lengthmaxCharacters: 5000maxCharacters: 500
Live crawlinglivecrawl: "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);
}

Step 2: Query-Level Caching (40-60% Cost Reduction)

import { LRUCache } from "lru-cache";

const searchCache = new LRUCache<string, any>({
  max: 5000,
  ttl: 3600 * 1000, // 1-hour TTL
});

async function cachedSearch(query: string, opts: any) {
  const key = `${query.toLowerCase().trim()}:${opts.type}:${opts.numResults}`;
  const cached = searchCache.get(key);
  if (cached) return cached;

  const results = await exa.searchAndContents(query, opts);
  searchCache.set(key, results);
  return results;
}
// Typical RAG cache hit rate: 40-60%, directly cutting costs in half

Step 3: Query Deduplication for Batch Jobs

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
}

Step 5: Monitor Usage and Set Budget Alerts

set -euo pipefail
# Check API key usage
curl -s https://api.exa.ai/​v1/​usage \
  -H "x-api-key: $EXA_API_KEY" | \
  python3 -c "
import json, sys
d = json.load(sys.stdin)
print(f'Searches today: {d.get(\"searches_today\", \"N/​A\")}')
print(f'Monthly total: {d.get(\"searches_this_month\", \"N/​A\")}')
print(f'Monthly limit: {d.get(\"monthly_limit\", \"N/​A\")}')
" 2>/​dev/​null || echo "Usage endpoint not available"
// Application-level budget tracking
class ExaBudgetTracker {
  private searchCount = 0;
  private dailyLimit: number;

  constructor(dailyLimit = 1000) {
    this.dailyLimit = dailyLimit;
  }

  async search(exa: Exa, query: string, opts: any) {
    if (this.searchCount >= this.dailyLimit) {
      throw new Error(`Daily Exa budget exceeded (${this.dailyLimit} searches)`);
    }
    this.searchCount++;
    return exa.search(query, opts);
  }

  getUsage() {
    return {
      used: this.searchCount,
      remaining: this.dailyLimit - this.searchCount,
      utilization: `${((this.searchCount / this.dailyLimit) * 100).toFixed(1)}%`,
    };
  }
}

Cost Optimization Checklist

  • Use keyword or fast for exact lookups instead of neural
  • Reduce numResults to 3-5 for most use cases (default is 10)
  • Use highlights instead of full text when snippets suffice
  • Implement query-level caching (LRU or Redis)
  • Deduplicate queries in batch pipelines
  • Set application-level budget limits
  • Monitor daily/​monthly usage against budget

Error Handling

IssueCauseSolution
Monthly limit hit earlyUncached batch queriesAdd caching (40%+ savings)
High cost per resultnumResults too highReduce to 3-5 for most use cases
Budget spike from batchNo deduplicationDeduplicate before batch execution
402 NO_MORE_CREDITSAccount balance exhaustedTop up at dashboard.exa.ai

Resources

Next Steps

For performance optimization, see exa-performance-tuning. For reliability, see exa-reliability-patterns.

More skills from jeremylongshore

openrouter-compliance-review logo
jeremylongshore/claude-code-plugins-plus-skills

openrouter-compliance-review

Review OpenRouter integration for regulatory compliance (SOC2, GDPR,

2.8K 0
View
maintainx-data-handling logo
jeremylongshore/claude-code-plugins-plus-skills

maintainx-data-handling

Data synchronization, ETL patterns, and data management for MaintainX.

2.8K 0
View
groq-core-workflow-a logo
jeremylongshore/claude-code-plugins-plus-skills

groq-core-workflow-a

Execute Groq primary workflow: chat completions with tool use and JSON

2.8K 0
View
validating-csrf-protection logo
jeremylongshore/claude-code-plugins-plus-skills

validating-csrf-protection

Validate CSRF protection implementations for security gaps. Use when

2.8K 0
View
api-contract logo
jeremylongshore/claude-code-plugins-plus-skills

api-contract

Configure this skill should be used when the user asks about "API contract",

2.8K 0
View
ideogram-incident-runbook logo
jeremylongshore/claude-code-plugins-plus-skills

ideogram-incident-runbook

Execute Ideogram incident response with triage, mitigation, and postmortem.

2.8K 0
View
gamma-sdk-patterns logo
jeremylongshore/claude-code-plugins-plus-skills

gamma-sdk-patterns

Reusable patterns for the Gamma REST API (no SDK exists).

2.8K 0
View
deepgram-sdk-patterns logo
jeremylongshore/claude-code-plugins-plus-skills

deepgram-sdk-patterns

Apply production-ready Deepgram SDK patterns for TypeScript and Python.

2.8K 0
View
openrouter-upgrade-migration logo
jeremylongshore/claude-code-plugins-plus-skills

openrouter-upgrade-migration

Migrate to OpenRouter from direct provider APIs or upgrade between SDK/model

2.8K 0
View
openrouter-common-errors logo
jeremylongshore/claude-code-plugins-plus-skills

openrouter-common-errors

Diagnose and fix common OpenRouter API errors. Use when encountering

2.8K 0
View
linear-cost-tuning logo
jeremylongshore/claude-code-plugins-plus-skills

linear-cost-tuning

Optimize Linear API usage, reduce unnecessary calls, and maximize

2.8K 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View