Rewrote monetization and cost control. The Actor had exactly one charge event
registered on the platform, apify-actor-start, so the price was flat while the
cost was per page: every page is one billable upstream call
(/api/v1/wechat_search/v2/fetch_search, $0.01 per call). A caller could ask for
5 pages, pay once, and consume 5 upstream calls; a free-plan caller paid nothing
and consumed the same. Nothing in the code charged per page, because the event
did not exist.
src/billing.js — a billing guard with three responsibilities:
- mirrors the platform prices (
search-page, raw-payload) only to reason about
the user's budget; charging itself always goes through Actor.charge();
- charges before a page's rows are pushed, so a delivered row is always a
paid row, and a refused charge ends the run instead of serving the page free;
- a pricing kill switch: if
PAY_PER_EVENT is not active or search-page
is unregistered/zero-priced, the run refuses to fetch entirely and writes a
PRICING_NOT_CONFIGURED notice. A monetization outage can no longer degrade
into a free service. Owner runs are exempt so the publisher can still debug.
- Per-page charging. One
search-page event per upstream page, charged after
the response arrives (a failed request is never billed) and before delivery.
raw-payload as a separate optional event, charged per page only when
raw=true. The raw envelope is the highest-value payload in the output and is
no longer given away.
- Free-plan structural cap: 1 page, no cursor resume, no raw payload. This
replaces nothing that worked — it is the first free-plan limit that actually
engages. It is a shape limit, not a counter, so it cannot be bypassed the way
the removed KV counter could.
- Pre-flight budget guard. The charge is taken after the upstream response so a
failed request is never billed; that would let an account with a spent budget
trigger one free upstream page per run. Before each request the run now compares
the remaining
maxTotalChargeUsd against the page price and stops without
fetching. A spent budget buys no upstream calls at all.
- Budget awareness. The run reads
ACTOR_MAX_TOTAL_CHARGE_USD through the SDK
pricing info, stops at the page that would exceed it, and reports
stopReason: "budget" with a BUDGET_STOP notice. Pages already paid for are
still delivered.
- SUMMARY restored. Since v0.3
SUMMARY was silently skipped on the platform
(the store was left to fail), which also broke nextCursor and therefore cursor
pagination. It is now written to the run's own default store behind a 10 s open /
15 s write timeout and degrades to a no-op instead of hanging the run. Verified on
the platform: SUMMARY present with nextCursor.
SUMMARY.pricing (model, prices, pageBillingActive, activatesAt, pagesCharged,
rawCharged, estimatedChargeUsd, maxTotalChargeUsd, ownerRun, degraded) and
SUMMARY.stopReason
(max-pages / empty-page / end-of-results / no-cursor / upstream-error /
budget / charge-*).
- Transition mode. Apify refuses an immediate price change on a public Actor and
requires
startedAt at least two weeks ahead, so the new pricing is scheduled for
2026-12-04. Until then the platform still serves the old pricing and
search-page does not exist; charging it would throw. PER_PAGE_BILLING_ACTIVE_FROM
marks the switch-over, and while it is in the future the run skips page charges,
logs that per-page billing is scheduled, and the kill switch stays quiet. A
planned change is not an outage.
- Tests: 40 unit assertions (plan resolution, charge classification, kill switch,
budget refusal, scheduled-pricing state) and 14 integration scenarios (free-plan
capping, budget stop, pricing kill switch, unknown-event stop, raw withheld when
its charge fails, runs continuing before the switch-over, no upstream call on a
spent budget).
- Default
maxPages in the Actor's defaultRunInput is 1 (was 3), so Store QA
and empty-input runs cost one upstream page instead of three.
- Run summary
ok stays true for capped and budget-stopped runs. Only the
pricing kill switch reports ok: false, refused: "pricing-not-configured".
- The misleading "no daily run cap" claim. There is no daily cap and never was a
working one; what exists now is a per-page price and a free-plan shape limit,
and the README says exactly that.
- The Billing section claimed the Actor charges "pay per result". It does not: the
only charge event registered on the platform is
apify-actor-start, collected once
when the run begins, so a run returning 300 rows costs the same as one returning 3.
The section now describes that, and stops promising something the invoice contradicts.
- Free-plan runs are capped at 2 pages of results. Every page, seed and enrichment is one upstream
request, so this is where the real cost sits. The cap is written to the dataset as a
notice row and to SUMMARY.appliedLimits.capped, and a capped run still ends
SUCCEEDED - exceeding a plan quota is never a failed run.
- The run can no longer be killed by the key-value store. Under
LIMITED_PERMISSIONS — how Apify's automated QA and every API-triggered run
starts an Actor — opening the store is refused with HTTP 403
(KeyValueStoreCollectionClient.getOrCreate, path /v2/key-value-stores).
That call sat in a || fallback chain and was never inside a try/catch of
ours, so the throw ended the run with exit code 91 and a reported FAILED run
with zero items. Every store open now goes through a wrapper that returns a
no-op store instead of throwing, so the free-run counter and the run SUMMARY
degrade and the actual work proceeds.
- The gate store's name-to-id lookup no longer depends on the store still being
on the first page. There is no GET-by-name endpoint, so the lookup pages
through
/v2/key-value-stores; it used a fixed limit=50, which silently
stopped containing gate stores once the account passed 50 of them — and the
account creates a new default store on every run, so that list grows on its
own. The lookup now pages (100 per page, up to 20 pages).
- Fix: Added
defaultRunInput to .actor/actor.json (Layer 3 of §226).
- Symptom: Apify Store auto-QA runs with empty input hit Layer 2 fallback (
DEFAULT_KEYWORD) instead of running with the defaultRunInput the schema advertises.
- Fix:
defaultRunInput mirrors schema defaults 1:1 (keyword, businessType, sort, publishTime, maxPages, cursor, raw), so empty-input runs now execute the schema-declared defaults.
- README + CHANGELOG clean of upstream platform names (already true pre-fix; re-verified).
- Initial release / 首发: 1 Actor = 1 upstream endpoint (
fetch_search).
- 18 business_type filters / 18 个业务类型筛选:
all / account / article / video / sticker + 13 currently-empty verticals (upstream documents them as server-side gated).
- Auto-pagination / 自动翻页:
cursor + continue_flag opaque token replay; up to 5 pages per run (default 3 = ~30 items).
- 3-shape normalizer / 3 类归一化: video / article / account items each map to a unified field set (
docId / title / coverUrl / source / likeNum / ...) with shape-specific extras (video: exportId + duration + feedNonceId; article: docUrl + description; account: description + iconUrl).
- Mixed-mode normalizer for
businessType=all: detects item shape by discriminator keys and dispatches to the right normalizer.
- Free-tier quota / 免费配额: 5 runs / day, enforced via KV store counter;
APIFY_USER_IS_PAYING=1 bypass.
- 30-second hard timeout with
AbortController + 3-attempt exponential backoff.
- Cost control:
maxPages clamped to 1-5 (each page costs $0.010 upstream); default 3 = $0.030 per run max.
- Resumable pagination: previous run's
SUMMARY.nextCursor feeds the next run's cursor input.
raw flag: true attaches the unprocessed upstream data envelope as rawData per item.
- Cumulative SUMMARY:
keyword / businessType / pagesFetched / requests / pushed / receivedFromSource / businessTypeRaw / hasMoreInSource / nextCursor / startedAt / finishedAt / tier / runsToday.
- Bilingual README & description / 中英双语 README + 简介 (EN first, ZH mirror, per §218).
- 23 unit assertions pass (input validation + 3-shape normalization + body shape + edge cases).
- 7 integration scenarios pass (mock fetch drives
run() end-to-end against captured upstream fixtures).
- Real upstream fixture data: video 10 items, article 36 items, account 14 items (raw int
33554499).
- business_type integer codes (verified against live upstream):
7 = video (视频号)
2 = article (公众号文章)
33554499 = account (the actual upstream magic number — upstream API reference lists 14 but the live fetch_search returns 33554499).
- 13 verticals return empty pages:
underline / encyclopedia / live_stream / comment / listen / news / photos / book / moments / image / mini_game / weixin_index / ai_search.
- Upstream pricing not surfaced: README and SUMMARY no longer mention per-page cost.