Alchemy Cost Tuning

SkillDev tools

Helps your agent cut Alchemy API costs by budgeting compute units, setting up caching, and picking the right plan.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the Alchemy Cost Tuning skill

About this capability

Govern Alchemy compute usage and spend with current account evidence, workload attribution, budgets, and reversible optimizations. Use when forecasting or reducing Alchemy cost. Trigger with "Alchemy cost", "Alchemy compute units", or "reduce Alchemy spend".

What this skill tells your AI

The instructions your AI receives, as published by jeremylongshore/tons-of-skills-marketplace in skills/.curated/alchemy-cost-tuning/SKILL.md and read by ahel’s review.

Overview

Alchemy pricing is based on Compute Units (CU). Different API methods have different CU costs. Optimize by caching, batching, choosing cheaper methods, and right-sizing your plan.

Plan Comparison

PlanCU/secMonthly CUPriceBest For
Free330300M$0Dev/prototyping
Growth6601.2B$49/moSmall dApps
ScaleCustomCustomCustomHigh-traffic apps

CU Cost Reference (Top Methods)

MethodCUOptimization
eth_blockNumber10Cache 12s (1 block)
eth_getBalance19Cache 30s
eth_call26Cache based on use case
getTokenBalances50Cache 60s; batch addresses
getNftsForOwner50Cache 5 min
getTokenMetadata50Cache 24h (rarely changes)
getAssetTransfers150Cache aggressively; paginate
getNftMetadataBatch50Use batch over individual calls

Prerequisites

  • An approved observation window with aggregate method counts and latency; do not record end-user wallet data merely to estimate API usage.
  • Current plan and compute-unit limits confirmed in the organization’s Alchemy account, since commercial terms and method costs may change.
  • A cache-invalidation policy that distinguishes safe metadata caching from time-sensitive balance, block, and transaction data.

Instructions

Step 1: CU Usage Monitor

// src/cost/cu-monitor.ts
const CU_COSTS: Record<string, number> = {
  'eth_blockNumber': 10, 'eth_getBalance': 19, 'eth_call': 26,
  'getTokenBalances': 50, 'getNftsForOwner': 50, 'getTokenMetadata': 50,
  'getAssetTransfers': 150, 'getNftMetadataBatch': 50,
};

class CuMonitor {
  private usage: Array<{ method: string; cu: number; timestamp: number }> = [];

  record(method: string): void {
    this.usage.push({ method, cu: CU_COSTS[method] || 26, timestamp: Date.now() });
  }

  getHourlyReport(): { totalCu: number; byMethod: Record<string, number> } {
    const cutoff = Date.now() - 3600000;
    const recent = this.usage.filter(u => u.timestamp > cutoff);
    const byMethod: Record<string, number> = {};
    let totalCu = 0;

    for (const u of recent) {
      byMethod[u.method] = (byMethod[u.method] || 0) + u.cu;
      totalCu += u.cu;
    }

    return { totalCu, byMethod };
  }

  getMonthlyProjection(): { projectedMonthly: number; planRecommendation: string } {
    const hourly = this.getHourlyReport();
    const projectedMonthly = hourly.totalCu * 24 * 30;

    let recommendation = 'Free';
    if (projectedMonthly > 300_000_000) recommendation = 'Growth';
    if (projectedMonthly > 1_200_000_000) recommendation = 'Scale';

    return { projectedMonthly, planRecommendation: recommendation };
  }
}

export { CuMonitor };

Step 2: Cost-Optimized Client Wrapper

// src/cost/optimized-client.ts
import { Alchemy, Network } from 'alchemy-sdk';

const cache = new Map<string, { data: any; expiry: number }>();

// Cache token metadata aggressively (rarely changes)
async function getTokenMetadataCached(alchemy: Alchemy, contract: string) {
  const key = `metadata:${contract}`;
  const cached = cache.get(key);
  if (cached && cached.expiry > Date.now()) return cached.data;

  const data = await alchemy.core.getTokenMetadata(contract);
  cache.set(key, { data, expiry: Date.now() + 86400000 }); // 24h cache
  return data;
}

// Use batch instead of individual NFT metadata calls
// 1 batch call (50 CU) vs 100 individual calls (5000 CU)
async function getNftMetadataOptimized(
  alchemy: Alchemy,
  tokens: Array<{ contractAddress: string; tokenId: string }>
) {
  const BATCH_SIZE = 100;
  const results = [];
  for (let i = 0; i < tokens.length; i += BATCH_SIZE) {
    const batch = tokens.slice(i, i + BATCH_SIZE);
    const batchResults = await alchemy.nft.getNftMetadataBatch(batch);
    results.push(...batchResults);
  }
  return results;
}

Step 3: Free Tier Optimization Checklist

// For staying within Free tier (330 CU/sec, 300M CU/month):
// 1. Cache eth_blockNumber (saves 10 CU per redundant call)
// 2. Cache token metadata (saves 50 CU per redundant call)
// 3. Use getNftMetadataBatch instead of getNftMetadata (100x savings)
// 4. Avoid getAssetTransfers loops (150 CU each — cache results)
// 5. Use WebSockets instead of polling (one connection vs repeated calls)
// 6. Rate-limit user-facing endpoints to prevent CU bursts

Output

  • CU usage monitor with hourly reports and plan projections
  • Cost-optimized client with aggressive caching
  • Batch operations reducing CU consumption by 100x
  • Free tier optimization checklist

Examples

Collect one hour of aggregate development traffic, feed the counts into CuMonitor, and identify the three methods responsible for the highest CU projection. Add a 24-hour metadata cache and batched NFT metadata requests in the test environment, then compare request counts and response correctness against uncached fixtures. Promote only after cache hits never serve stale time-sensitive balance or transfer data. If observed use approaches the account limit or the monitor’s input is incomplete, throttle the noncritical feature and obtain an updated account-limit report rather than guessing a budget or silently dropping user-facing requests.

Error Handling

FailureResponse
Usage projection lacks complete observation dataMark the estimate incomplete and collect a representative window before plan decisions.
Cache returns stale chain stateInvalidate the affected key and narrow its TTL or caching scope.
Account limit is approachedApply bounded rate limiting and notify the account owner before service degradation.
Batch operation is partially rejectedPreserve successful items, retry only failed items within limits, and expose their unavailable state.

Resources

Next Steps

For architecture design, see alchemy-reference-architecture.

Signals

GitHub stars
3k
Forks
396
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
alchemy-cost-tuning
Source
github.com/jeremylongshore/tons-of-skills-marketplace