Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 19 additions & 54 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,30 @@ 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();
### Use synthetic start event `apify-actor-start`

// Don't charge the "Actor start" event again after Actor migration
if (chargingManager.getChargedEventCount("actor-start") === 0) {
await Actor.charge({
"eventName": "actor-start",
});
}
}
This event is automatically charged by the Apify platform when an Actor is started or resurrected.

await Actor.init();
You are charged one event for each GB of memory used by the Actor (at least one event per run). This also saves you the cost of 5 seconds of Actor runtime.

const main = async () => {
await chargeForActorStart();
:::note Automatic charging of synthetic start event

// Rest of the Actor logic
};
You do **not** need to manually charge for the synthetic start event (`apify-actor-start`) in your Actor code.

await main();
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.

await Actor.exit();
```

</TabItem>
<TabItem value="Python" label="Python">

```py
from apify import Actor

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")

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

await charge_for_actor_start()

# Rest of the Actor logic
:::

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

</TabItem>
</Tabs>
For new Actors, this event is added automatically as you can see on the following screen:

:::note Actor migrations and charging
![New Actor - synthetic start event](../images/apify-actor-start.png)

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.
#### Synthetic start event for existing Actors

:::
If you have existing Actors, you can add this event manually in the Apify Console.

### Charge for invalid input

Expand Down
Loading