Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 22 additions & 51 deletions sources/platform/actors/publishing/monetize/pay_per_event.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ PPE lets you define pricing for individual events. You can charge for specific e

The details on how your cost is computed can be found in [Example of a PPE pricing model](#example-of-a-ppe-pricing-model).

:::tip Additional benefits

Actors that implement PPE pricing receive additional benefits, including increased visibility in Apify Store and enhanced discoverability for users looking for monetized solutions.

:::

## How is profit computed

Your profit is calculated from the mentioned formula:
Expand Down Expand Up @@ -77,71 +83,36 @@ When using browser automation tools like Puppeteer or Playwright for web scrapin

:::

### Charge for `Actor start`

Charge for `Actor start` to prevent users from running your Actor for free.

<Tabs groupId="main">
<TabItem value="JavaScript" label="JavaScript">

```js
import { Actor } from 'apify';

const chargeForActorStart = async () => {
const chargingManager = Actor.getChargingManager();

// Don't charge the "Actor start" event again after Actor migration
if (chargingManager.getChargedEventCount("actor-start") === 0) {
await Actor.charge({
"eventName": "actor-start",
});
}
}

await Actor.init();

const main = async () => {
await chargeForActorStart();
### Use synthetic start event `apify-actor-start`

// Rest of the Actor logic
};
This event is automatically charged by the Apify platform when an Actor is started or resurrected.

await main();
Users of your Actor are charged one event for each GB of memory used by the Actor (at least one event per run). We _strongly_ suggest setting the price of this event to $0.0001 to remain competitive in the Store and attractive for your customers. If you define this event, you also save 5 seconds of Actor runtime from each Actor run, which won't be deducted from your payout profits.

await Actor.exit();
```
:::note Automatic charging of synthetic start event

</TabItem>
<TabItem value="Python" label="Python">
You must _not_ manually charge for the synthetic start event (`apify-actor-start`) in your Actor code.

```py
from apify import Actor
If you attempt to charge this event yourself, the operation will fail.
This event is _always_ charged automatically by the Apify platform whenever your Actor starts or is resurrected.

async def charge_for_actor_start():
charging_manager = Actor.get_charging_manager()
:::

# Don't charge the "Actor start" event again after Actor migration
if charging_manager.get_charged_event_count("actor-start") == 0:
await Actor.charge(event_name="actor-start")
#### Synthetic start event for new Actors

async def main():
await Actor.init()

await charge_for_actor_start()
For new Actors, this event is added automatically as you can see on the following screen:

# Rest of the Actor logic
![New Actor - synthetic start event](../images/apify-actor-start.png)

await Actor.exit()
```
#### Synthetic start event for existing Actors

</TabItem>
</Tabs>
If you have existing Actors, you can add this event manually in Apify Console.

:::note Actor migrations and charging
#### Synthetic start event for Actors with start event

Actors can migrate between servers during execution, which restarts the process and clears memory. When using PPE pricing model, avoid charging the start event multiple times after a migration by checking your charging state.
Your Actor might already have a start event defined, such as `actor-start` or another variant of the event name. In this case, you can choose whether to use the synthetic start event or keep the existing start event.

:::
If you want to use the synthetic start event, remove the existing start event from your Actor and add the synthetic start event in Apify Console.

### Charge for invalid input

Expand Down
Loading