-
Notifications
You must be signed in to change notification settings - Fork 182
docs: add Develop AI agents on Apify page #2375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
marcel-rbro
wants to merge
5
commits into
master
Choose a base branch
from
docs/develop-ai-agents-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+156
−0
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
81fa245
docs: add "Develop AI agents on Apify" page
marcel-rbro 5cf0324
fix: use /platform prefix for internal doc links
marcel-rbro b5e15e5
small fixes
marcel-rbro 29c6b46
Merge branch 'master' into docs/develop-ai-agents-page
marcel-rbro e4b2b45
docs: enhance clarity and detail in the AI agents development guide
marcel-rbro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
sources/platform/actors/development/quick-start/develop_ai_agents.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| --- | ||
| title: Develop AI agents on Apify | ||
| description: Build and deploy AI agents on Apify with framework templates, sandboxes, OpenRouter for LLM access, and pay-per-event pricing. | ||
| sidebar_position: 4.0 | ||
| sidebar_label: Develop AI agents | ||
| slug: /actors/development/quick-start/develop-ai-agents | ||
| --- | ||
|
|
||
| The Apify platform provides everything you need to build, test, and deploy AI agents. This page walks you through the complete toolkit: templates, sandbox code execution, LLM access through OpenRouter, pay-per-event monetization, and deployment to [Apify Store](https://apify.com/store). | ||
|
|
||
| This page covers: | ||
|
|
||
| - [**Start from a template**](#start-from-a-template) - Use pre-built Apify Actor templates for popular AI frameworks to scaffold your agent quickly. | ||
| - [**AI Sandbox**](#use-ai-sandbox-for-code-execution) - Run code in an isolated environment at runtime. Useful when your agent needs to execute user-provided or dynamically generated code. | ||
| - [**OpenRouter**](#access-llms-with-openrouter) - Access 100+ LLMs through your Apify account without managing separate API keys. | ||
| - [**Pay-per-event pricing**](#monetize-with-pay-per-event-pricing) - Charge users for specific actions your agent performs, such as API calls or token usage. | ||
| - [**Deploy to Apify**](#deploy-to-apify) - Push your agent to the Apify platform and publish it to Apify Store. | ||
|
|
||
| :::tip Build with AI | ||
|
|
||
| Looking to use AI coding assistants (Claude Code, Cursor, GitHub Copilot) to help you _develop_ Actors? See [Build Actors with AI](/platform/actors/development/quick-start/build-with-ai). | ||
|
|
||
| ::: | ||
|
|
||
| ## Start from a template | ||
|
|
||
| The fastest way to start your AI agent is to use one of the Apify Actor templates built on popular AI frameworks. Each template comes pre-configured with the right file structure, dependencies, and the Apify SDK integration. | ||
|
|
||
| Available AI framework templates include: | ||
|
|
||
| - LangChain - LLM pipelines with chain-of-thought and tool use | ||
| - Mastra - TypeScript-native AI agent framework | ||
| - CrewAI - multi-agent orchestration for complex tasks | ||
| - LlamaIndex - retrieval-augmented generation (RAG) workflows | ||
| - PydanticAI - Python agents with structured, validated outputs | ||
| - Smolagents - lightweight agents from Hugging Face | ||
| - MCP - expose your Actor as an MCP server | ||
|
|
||
| Initialize a template with the Apify CLI: | ||
|
|
||
| ```bash | ||
| apify create my-agent | ||
| ``` | ||
|
|
||
| The command guides you through template selection. Browse all available templates at [apify.com/templates](https://apify.com/templates). | ||
|
|
||
| If you don't have the Apify CLI installed, see the [installation guide](/cli/docs/installation). | ||
|
|
||
| ## Use AI Sandbox for code execution | ||
|
|
||
| [AI Sandbox](https://apify.com/apify/ai-sandbox) is an isolated, containerized environment where your AI agent can execute code and system commands at runtime. Your agent Actor starts the sandbox and communicates with it through a REST API or MCP interface. | ||
|
|
||
| ### Key capabilities | ||
|
|
||
| - Code execution - run JavaScript, TypeScript, Python, and bash via `POST /exec` with captured stdout/stderr and exit codes | ||
| - Filesystem access - read, write, list, and delete files through `/fs/{path}` endpoints | ||
| - Dynamic reverse proxy - start a web server inside the sandbox and expose it externally | ||
| - Dependency installation - install npm and pip packages at startup through Actor input | ||
| - Idle timeout - the sandbox automatically stops after a period of inactivity | ||
| - MCP interface - connect directly from Claude Code or other MCP clients for live debugging | ||
|
|
||
| ### Example workflow | ||
|
|
||
| 1. Your agent Actor starts the AI Sandbox Actor using the Apify SDK (similar to calling any other Actor) | ||
| 1. The agent sends code to execute via the REST API (`POST /exec`) | ||
| 1. AI Sandbox runs the code in isolation and returns results | ||
| 1. The agent processes results and iterates | ||
|
|
||
| :::info Sandbox environment | ||
|
|
||
| AI Sandbox runs on a Debian image with Node.js version 24 and Python 3 pre-installed. You can install additional dependencies through the Actor input configuration. | ||
|
|
||
| ::: | ||
|
|
||
| ## Access LLMs with OpenRouter | ||
|
|
||
| The [OpenRouter](https://apify.com/apify/openrouter) Actor provides access to 100+ LLMs through your Apify account. Supported providers include OpenAI, Anthropic, Google, Mistral, Meta, and more. No separate API keys or billing setup required - all costs are billed as platform usage. | ||
|
|
||
| :::caution Paid account recommended | ||
|
|
||
| To use the OpenRouter Actor, subscribe to a paying Apify plan. Free-tier accounts may be blocked by anti-fraud protections. | ||
|
|
||
| ::: | ||
|
|
||
| OpenRouter exposes an OpenAI-compatible API, so you can use it with any SDK that supports the OpenAI API format. | ||
|
|
||
| ### Connect to OpenRouter | ||
|
|
||
| Use the Apify OpenRouter proxy endpoint with your Apify token: | ||
|
|
||
| ```javascript | ||
| import { createOpenRouter } from '@openrouter/ai-sdk-provider'; | ||
|
|
||
| const openrouter = createOpenRouter({ | ||
| baseURL: 'https://openrouter.apify.actor/api/v1', | ||
| apiKey: 'api-key-not-required', | ||
| headers: { | ||
| Authorization: `Bearer ${process.env.APIFY_TOKEN}`, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| The proxy supports chat completions, streaming, text embeddings, and image generation through vision-capable models. | ||
|
|
||
| :::caution Token usage tracking | ||
|
|
||
| Pay-per-event pricing can charge users per token. To do this, extract token counts from OpenRouter responses. Check the [OpenRouter Actor README](https://apify.com/apify/openrouter) for the latest guidance on this workflow. | ||
|
|
||
| ::: | ||
|
|
||
| ## Monetize with pay-per-event pricing | ||
|
|
||
| [Pay-per-event (PPE)](/platform/actors/publishing/monetize/pay-per-event) pricing lets you charge users for specific actions your agent performs. Use `Actor.charge()` from the [JavaScript SDK](/sdk/js/reference/class/Actor#charge) or [Python SDK](/sdk/python/reference/class/Actor#charge) to bill users for events like API calls, generated results, or token usage. | ||
|
|
||
| ### PPE for AI agents | ||
|
|
||
| For AI agents that use OpenRouter, consider these pricing strategies: | ||
|
|
||
| - Fixed pricing - charge a flat fee per task or request, regardless of the underlying LLM costs | ||
| - Usage-based pricing - charge per token or per LLM call, passing costs through to users with a markup | ||
|
|
||
| Your profit is calculated as: | ||
|
|
||
| ```text | ||
| profit = (0.8 × revenue) - platform costs | ||
| ``` | ||
|
|
||
| :::note Free-tier protection | ||
|
|
||
| If an Actor's net profit goes negative (for example, from free-tier users consuming LLM resources), the negative amount resets to $0 for aggregation purposes. Negative profit on one Actor doesn't affect earnings from your other Actors. | ||
|
|
||
| ::: | ||
|
|
||
| For detailed pricing guidance, see the [pay-per-event documentation](/platform/actors/publishing/monetize/pay-per-event). | ||
|
|
||
| ## Deploy to Apify | ||
|
|
||
| When your agent is ready, deploy it to the Apify platform: | ||
|
|
||
| ```bash | ||
| apify push | ||
| ``` | ||
|
|
||
| This builds and deploys your Actor. Once deployed, you can: | ||
|
|
||
| - Publish to Apify Store - make your agent available to other users and start earning with PPE pricing. See the [publishing documentation](/platform/actors/publishing). | ||
| - Run via API - trigger your agent programmatically through the [Apify API](/api/v2). | ||
| - Set up schedules - run your agent on a recurring schedule. | ||
|
|
||
| For more deployment options, see the [deployment documentation](/platform/actors/development/deployment). | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I would mention that we recommend to subscribe and be a paying user in order to use this Actor as some free users might be blocked because of the anti-fraud logic.