My Actor 18
Under maintenancePricing
Pay per usage
My Actor 18
Under maintenancePricing
Pay per usage
Rating
0.0
(0)
Developer
Mubarak Obama
Maintained by CommunityActor stats
0
Bookmarked
2
Total users
1
Monthly active users
7 days ago
Last modified
Categories
Share
PydanticAI template
Start a new AI agent based project in Python with our PydanticAI project template. It provides a basic structure for the Actor using the Apify SDK and PydanticAI, and allows you to add your own functionality with minimal setup.
How it works
Insert your own code to async with Actor: block. You can use the Apify SDK with any other Python library. Add or modify the agent and tools in my_actor/agents.py.
LLM provider
The agent talks to its LLM through the Apify OpenRouter proxy — an OpenAI-compatible endpoint at https://openrouter.apify.actor/api/v1 that fronts the full OpenRouter model catalog. Token usage is billed against the user's Apify account (pay-per-event), so no OPENAI_API_KEY or any other provider API key is required. The Actor authenticates with the proxy using the APIFY_TOKEN that the platform injects into every run automatically.
If you'd rather call OpenAI / Anthropic / etc. directly with your own key, swap the OpenAIProvider configuration in my_actor/agents.py — see the PydanticAI OpenAI docs.
Getting started
For complete information see this article. To run the Actor use the following command:
$apify run
Deploy to Apify
Connect Git repository to Apify
If you've created a Git repository for the project, you can connect to Apify:
- Go to Actor creation page
- Click on Link Git Repository button
Push project on your local machine to Apify
You can also deploy the project from your local machine to the Apify platform without the need for the Git repository.
-
Log in to Apify. You will need to provide your Apify API Token to complete this action.
$apify login -
Deploy your Actor. This command will deploy and build the Actor on the Apify Platform. You can find your newly created Actor under Actors -> My Actors.
$apify push
Pay Per Event
This template uses the Pay Per Event (PPE) monetization model, which provides flexible pricing based on defined events.
To charge users, define events in JSON format and save them on the Apify platform. Here is an example schema with the task-completed event:
[{"task-completed": {"eventTitle": "Task completed","eventDescription": "Flat fee for completing the task.","eventPriceUsd": 0.01}}]
In the Actor, trigger the event with:
await Actor.charge(event_name='task-completed')
This approach allows you to programmatically charge users directly from your Actor, covering the costs of execution and related services, such as LLM input/output tokens.
To set up the PPE model for this Actor:
- Configure Pay Per Event: establish the Pay Per Event pricing schema in the Actor's Monetization settings. First, set the Pricing model to
Pay per eventand add the schema. An example schema can be found in .actor/pay_per_event.json.
No provider API key (e.g. OPENAI_API_KEY) needs to be configured — LLM costs are billed through the Apify OpenRouter proxy to the user running the Actor.
Resources
To learn more about Apify, Actors and PydanticAI take a look at the following resources:
- Apify SDK for Python documentation
- Apify Platform documentation
- Join our developer community on Discord
- AI agent architecture
- What are AI agents
- How to build and monetize an AI agent on Apify
- PydanticAI documentation
- PydanticAI on GitHub
Getting started
For complete information see this article. In short, you will:
- Build the Actor
- Run the Actor
Pull the Actor for local development
If you would like to develop locally, you can pull the existing Actor from Apify console using Apify CLI:
-
Install
apify-cliUsing Homebrew
$brew install apify-cliUsing NPM
$npm -g install apify-cli -
Pull the Actor by its unique
<ActorId>, which is one of the following:- unique name of the Actor to pull (e.g. "apify/hello-world")
- or ID of the Actor to pull (e.g. "E2jjCZBezvAZnX8Rb")
You can find both by clicking on the Actor title at the top of the page, which will open a modal containing both Actor unique name and Actor ID.
This command will copy the Actor into the current directory on your local machine.
$apify pull <ActorId>
Documentation reference
To learn more about Apify and Actors, take a look at the following resources: