Skip to content

Commit 6ffd8dd

Browse files
docs(platform-monetize): better best practices for PPR/PPE charging
1 parent f6b1947 commit 6ffd8dd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sources/platform/actors/publishing/monetize.mdx

+7-5
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ Your profit is computed only from the first two users, since they are on Apify p
7979
To ensure profitable operation:
8080

8181
- Set memory limits in your [`actor.json`](https://docs.apify.com/platform/actors/development/actor-definition/actor-json) file to control platform usage costs
82-
- Implement the `ACTOR_MAX_PAID_DATASET_ITEMS` check to prevent excess result generation
82+
- Implement the `ACTOR_MAX_PAID_DATASET_ITEMS` check to prevent excess result generation. You can copy [this simple solution](https://github.com/metalwarrior665/max-paid-items-example/blob/master/src/push-data.ts).
8383
- Test your Actor with various result volumes to determine optimal pricing
84+
- Push at least one "error item" to the dataset for invalid input or if search query didn't generate any result. This will prevent users running your Actor for free.
8485

8586
### Pay-per-event pricing model
8687

@@ -119,9 +120,10 @@ Only paid user activity is included in profit calculations.
119120
#### Best practices for PPE Actors
120121

121122
- Set memory limits in your [`actor.json`](/platform/actors/development/actor-definition/actor-json) file to control platform usage costs
122-
- Avoid duplicate charges by not calling the start Actor event during migration.
123-
- Ensure users are not charged beyond their set maximum. The [`ChargingManager`](https://github.com/metalwarrior665/actor-charge-manager-poc) or our SDKs ([JS](/sdk/js/reference/class/ChargingManager) and [Python](/sdk/python/reference/class/ChargingManager)) can handle this logic.
124-
- Use idempotency keys in API calls to prevent double charges.
123+
- Charge either for "Actor start" or for invalid input or empty search to prevent users from running your Actor for free.
124+
- Don't charge the "Actor start" event again after Actor migration (check `ChargingManager` state).
125+
- Finish the Actor run once charging reaches user-configured `Maximum cost per run`. Apify SDKs ([JS](/sdk/js/reference/class/Actor#charge) and [Python](/sdk/python/reference/class/Actor#charge)) return `ChargeResult` that helps determine when to finish.
126+
- If you are not using the SDKs, use idempotency keys in API calls to prevent double charges.
125127
- Try to limit the number of events. Fewer events make it easier for users to understand your pricing.
126128
- Try to make your event have tangible artifacts that users can see and understand (this might not be possible when using external APIs) i.e:
127129
- Get a record
@@ -130,7 +132,7 @@ Only paid user activity is included in profit calculations.
130132

131133
:::note `ChargingManager` usage
132134

133-
Use our [`ChargingManager`](https://github.com/metalwarrior665/actor-charge-manager-poc) or SDKs ([JS](/sdk/js/reference/class/ChargingManager) and, [Python](/sdk/python/reference/class/ChargingManager) or use [`apify actor charge`](/cli/docs/next/reference#apify-actor-charge-eventname) when using our Apify CLI) to simplify PPE implementation into your Actor. This tool can handle pricing, usage tracking, idempotency keys, API errors, and, event charging via an API.
135+
Use our SDKs ([JS](/sdk/js/reference/class/ChargingManager) and, [Python](/sdk/python/reference/class/ChargingManager) or use [`apify actor charge`](/cli/docs/next/reference#apify-actor-charge-eventname) when using our Apify CLI) to simplify PPE implementation into your Actor. This tool can handle pricing, usage tracking, idempotency keys, API errors, and, event charging via an API.
134136

135137
You can also choose not to use it, but then you must handle API integration and possible edge cases manually. You can use `ChargingManager` code as a reference.
136138

0 commit comments

Comments
 (0)