Skip to content

docs: add PPE event charging examples and restructure best practices#2263

Draft
TC-MO wants to merge 2 commits intomasterfrom
add-event-examples
Draft

docs: add PPE event charging examples and restructure best practices#2263
TC-MO wants to merge 2 commits intomasterfrom
add-event-examples

Conversation

@TC-MO
Copy link
Contributor

@TC-MO TC-MO commented Feb 19, 2026

Add three generic Actor.charge() examples (JS + Python) to the PPE docs:

  • Charge per result with spending limit check
  • Charge for multiple event types
  • Charge for multiple items at once using count parameter

Move "Respect user spending limits" from standalone section into best practices and reorder subsections for logical flow: setup, spending limits, charging patterns, then pricing guidance. Clean up best practices intro prose.

Add three generic Actor.charge() examples (JS + Python) to the PPE docs:
- Charge per result with spending limit check
- Charge for multiple event types
- Charge for multiple items at once using count parameter

Move "Respect user spending limits" from standalone section into best
practices and reorder subsections for logical flow: setup, spending
limits, charging patterns, then pricing guidance. Clean up best
practices intro prose.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@TC-MO TC-MO self-assigned this Feb 19, 2026
@TC-MO TC-MO requested a review from marcel-rbro February 19, 2026 09:56
@TC-MO TC-MO added documentation Improvements or additions to documentation. t-docs Issues owned by technical writing team. labels Feb 19, 2026
Copy link
Contributor

@marcel-rbro marcel-rbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions and suggestions, overall looks good.

### Charge for multiple event types

When using [Crawlee](https://crawlee.dev/), use `crawler.autoscaledPool.abort()` instead of `Actor.exit()` to gracefully finish the crawler and allow the rest of your code to process normally.
Charge multiple event types in a single operation. Each event type must be defined in your Actor's pricing configuration.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explain this more thoroughly? The text says "charge multiple event types in a single operation", but the example shows two charge calls. Maybe rewrite to something like: "Charge for multiple different event types in one Actor run"?

The Apify SDK's `ChargeResult` respects the user set limit already.
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.

When using [Crawlee](https://crawlee.dev/), use `crawler.autoscaledPool.abort()` instead of `Actor.exit()` to gracefully finish the crawler.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the correct place for the Crawlee note? The admonition title doesn't fit with this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was trying to avoid two admonitions next to each other and may have went overboard with streamlining. Maybe this will be better as regular prose 🤔

Comment on lines 171 to 173
if (chargeResult.eventChargeLimitReached) {
await Actor.exit();
await Actor.exit();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only example that shows this method. Should it be added to the 2 other examples below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On one hand it could be, on the other it would make all of those repetitive. My goal here was to create generic code examples, that span few use-cases. Kind of in a way to teach, but not provide production-ready code.

### Charge for multiple items at once

#### Synthetic start event for existing Actors
Use the `count` parameter to charge for a batch of items in a single call.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to handle eventChargeLimitReached in this case? Or is that outside of the scope of this task? 😆


When using [Crawlee](https://crawlee.dev/), use `crawler.autoscaledPool.abort()` instead of `Actor.exit()` to gracefully finish the crawler and allow the rest of your code to process normally.
Charge multiple event types in a single operation. Each event type must be defined in your Actor's pricing configuration.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have multiple events, use the chargeableWithinLimit property to see if other events can still be charged before stopping the Actor.

But it's not demonstrated anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah my starting point was more complex code example and then I started simplifying it, might be the best to remove mention from prose

- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation. t-docs Issues owned by technical writing team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants