Skip to content

Commit 00ecad4

Browse files
TC-MOclaude
andcommitted
docs: address PR #2263 review feedback on PPE examples
- Fix "single operation" wording to "in one Actor run" - Move Crawlee note out of ACTOR_MAX_TOTAL_CHARGE_USD admonition into prose - Removed chargeableWithinLimit mention from prose - Add chargedCount handling to batch charging example Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e30d80f commit 00ecad4

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

sources/platform/actors/publishing/monetize/pay_per_event.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,16 @@ When using browser automation tools like Puppeteer or Playwright for web scrapin
162162

163163
Finish the Actor run once charging reaches the user-configured maximum cost per run. `Actor.charge()` returns a `ChargeResult` object that helps determine when to stop.
164164

165-
The `eventChargeLimitReached` property checks if the user's limit allows for another charge of this event. If you have multiple events, use the `chargeableWithinLimit` property to see if other events can still be charged before stopping the Actor.
165+
The `eventChargeLimitReached` property checks if the user's limit allows for another charge of this event.
166166

167167
:::info ACTOR_MAX_TOTAL_CHARGE_USD environment variable
168168

169169
Users set a spending limit through the Apify Console. This limit is available in your Actor code as the `ACTOR_MAX_TOTAL_CHARGE_USD` [environment variable](/platform/actors/development/programming-interface/environment-variables). The Apify SDK's `ChargeResult` respects this limit automatically.
170170

171-
When using [Crawlee](https://crawlee.dev/), use `crawler.autoscaledPool.abort()` instead of `Actor.exit()` to gracefully finish the crawler.
172-
173171
:::
174172

173+
When using [Crawlee](https://crawlee.dev/), use `crawler.autoscaledPool.abort()` instead of `Actor.exit()` to gracefully finish the crawler.
174+
175175
### Charge per result
176176

177177
Charge an event when your Actor produces a data item and check the spending limit before continuing.
@@ -221,7 +221,7 @@ async def main():
221221

222222
### Charge for multiple event types
223223

224-
Charge multiple event types in a single operation. Each event type must be defined in your Actor's pricing configuration.
224+
Charge for multiple event types in one Actor run. Each event type must be defined in your Actor's pricing configuration.
225225

226226
<Tabs groupId="main">
227227
<TabItem value="JavaScript" label="JavaScript">
@@ -267,7 +267,7 @@ async def main():
267267

268268
### Charge for multiple items at once
269269

270-
Use the `count` parameter to charge for a batch of items in a single call.
270+
Use the `count` parameter to charge for a batch of items in a single call. The returned `chargedCount` may be lower than requested if the user's spending limit is reached, so use it to determine how many items to push.
271271

272272
<Tabs groupId="main">
273273
<TabItem value="JavaScript" label="JavaScript">
@@ -283,8 +283,8 @@ const results = [
283283
{ url: 'https://example.com/3', title: 'Page 3' },
284284
];
285285

286-
await Actor.charge({ eventName: 'result', count: results.length });
287-
await Actor.pushData(results);
286+
const chargeResult = await Actor.charge({ eventName: 'result', count: results.length });
287+
await Actor.pushData(results.slice(0, chargeResult.chargedCount));
288288

289289
await Actor.exit();
290290
```
@@ -304,8 +304,8 @@ async def main():
304304
{'url': 'https://example.com/3', 'title': 'Page 3'},
305305
]
306306

307-
await Actor.charge(event_name='result', count=len(results))
308-
await Actor.push_data(results)
307+
charge_result = await Actor.charge(event_name='result', count=len(results))
308+
await Actor.push_data(results[:charge_result.charged_count])
309309

310310
await Actor.exit()
311311
```

0 commit comments

Comments
 (0)