agentsclimarketplace

Apify cost tuning

Skill jeremylongshore/claude-code-plugins-plus-skills/plugins/saas-packs/apify-pack/skills/apify-cost-tuning

425 plugins, 2,810 skills, 200 agents for Claude Code. Open-source marketplace at tonsofskills.com with the ccpi CLI package manager.

Install
npx -y skills add jeremylongshore/claude-code-plugins-plus-skills --skill apify-cost-tuning

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Optimize Apify platform costs through memory tuning, compute unit management, and proxy budgeting. Use when analyzing Apify billing, reducing Actor run costs, or implementing usage monitoring and budget alerts. Trigger with "apify cost", "apify billing", "reduce apify costs", "apify pricing", "apify expensive", "apify budget", "compute units".

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

5.6 KB, as published. Nobody here has run it

Apify Cost Tuning

Overview

Apify charges on three axes: compute units (CU), proxy traffic (GB), and storage. One CU = 1 GB of memory running for 1 hour, so cost scales with both memory allocation and run duration. This skill walks the investigate → tune → guard loop that finds where spend is going, cuts it at the biggest lever (memory), and installs guardrails so it stays down.

Full pricing tables (plan CU prices, proxy rates, storage rules) live in pricing-model.md.

Prerequisites

  • An Apify account with API access and APIFY_TOKEN set in the environment.
  • The apify-client package installed (npm install apify-client).
  • At least one Actor with run history to analyze.

Instructions

The workflow is six steps. Each is summarized here with its core lever; the full, runnable code for every step is in implementation.md.

  1. Analyze current costs — roll up the last N days of runs into total CU, USD, and duration, and surface the single most expensive run:

    import { ApifyClient } from 'apify-client';
    const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
    
    const { items: runs } = await client.actor(actorId).runs().list({ limit: 1000, desc: true });
    const totalUsd = runs.reduce((s, r) => s + (r.usageTotalUsd ?? 0), 0);
    
  2. Reduce memory allocation (biggest lever) — sweep memory from 4096 MB down to 256 MB and stop at the first failure to find the sweet spot. Most CheerioCrawler Actors are over-provisioned. Sweet spots: simple Cheerio 256-512 MB, complex 512-1024 MB, Playwright 2048-4096 MB.

  3. Optimize crawl duration — higher maxConcurrency, tighter requestHandlerTimeoutSecs, a maxRequestsPerCrawl cap, fewer retries, and selective enqueueLinks. Faster crawls consume fewer CUs.

  4. Minimize proxy costs — prefer datacenter (free with plan), only reach for residential when a site blocks it, block images/fonts/CSS to save residential GB, and reuse proxy sessions with useSessionPool.

  5. Cost guard for runaway Actors — start the run, poll usageTotalUsd every 30s, and .abort() once spend crosses a hard cap.

  6. Monitor monthly usage — iterate every Actor's runs since the 1st of the month and print a cost-descending report so the top spenders are obvious.

See full walkthrough for the complete code of each step, including the memory sweep, proxy hooks, budget guard, and monthly report.

Output

Running this skill produces:

  • A per-Actor cost analysis (runs, total CU, total USD, avg CU/run, avg cost/run, most expensive run) for a chosen lookback window.
  • A memory profile table mapping memory settings to status, duration, CU, and USD so you can pick the cheapest allocation that still succeeds.
  • A monthly cost report ranking every Actor by spend, with a grand total.
  • Tuned Actor configuration (reduced memory, capped crawls, proxy resource blocking) and an optional budget guard that aborts runs exceeding a USD ceiling.

Cost Optimization Checklist

  • Memory profiled (start low: 256-512MB for Cheerio)
  • maxRequestsPerCrawl set to prevent runaway crawls
  • Datacenter proxy used when possible (free with plan)
  • Residential proxy: images/CSS/fonts blocked to save bandwidth
  • maxConcurrency tuned (higher = faster = fewer CUs)
  • Scheduled runs have appropriate frequency (don't over-scrape)
  • Cost guard implemented for expensive runs
  • Monthly usage reviewed

Error Handling

IssueCauseSolution
Unexpected cost spikeNo maxRequestsPerCrawlAlways set an upper bound
High residential proxy costScraping images/fontsBlock non-essential resources
Over-provisioned memoryDefault 1024MBProfile and reduce to minimum
Too many scheduled runsAggressive cronReduce frequency if data freshness allows

Examples

Three worked scenarios chain the steps against concrete symptoms — a CheerioCrawler bill that tripled, runaway residential-proxy GB, and guarding a brand-new Actor. Each shows the full investigate → tune → verify loop. See examples.md.

Quick guard example — abort any run that exceeds $0.50:

// runWithBudget polls usageTotalUsd every 30s and aborts past the cap
const run = await runWithBudget('user/scraper', input, 0.50);

Resources

Next Steps

For architecture patterns, see apify-reference-architecture.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.