Running an AI affiliate agent persistently on a traditional server is wasteful. A content generation agent that runs once per day for ten minutes does not need a server idling for the other twenty-three hours and fifty minutes. You pay for all that idle time, which directly reduces your commission margin.
Modal solves this with serverless execution: your Python code runs on demand, scales automatically, and you pay only for the seconds your code is actually executing. For scheduled affiliate agents - daily content generation, weekly newsletter creation, periodic affiliate link auditing - Modal's pricing model makes the infrastructure cost negligible.
How Modal Works
Modal is a Python-native serverless platform. You decorate Python functions with @app.function() and Modal handles the rest: containerisation, execution, scaling, and scheduling. There is no Dockerfile to write, no Kubernetes cluster to manage, and no EC2 instance to maintain.
For an affiliate content agent:
- Your agent function runs on Modal's infrastructure
- It can be triggered on a schedule (
Period(hours=24)) for daily content generation - Execution costs are measured in seconds - a ten-minute content generation run costs fractions of a cent at Modal's pricing
- Between runs, you pay nothing
This cost model means you can run multiple specialised agents - a grocery savings agent, a deals roundup agent, a competition finder agent - each on its own schedule, without worrying about the cumulative idle infrastructure cost.
Setting Up the ROOPON Affiliate Agent on Modal
Install Modal and set up your environment:
pip install modal openai httpx python-dotenv
modal setup # Authenticates your Modal account
Create your Modal secrets for API keys:
modal secret create roopon-agent-secrets \
OPENAI_API_KEY=your_openai_key \
ROOPON_AFFILIATE_LINK=your_affiliate_link \
CONTACT_EMAIL=your@email.com
The Agent Code
# agent.py
import modal
import httpx
import os
from datetime import datetime
app = modal.App("roopon-affiliate-agent")
# Define the container image with required dependencies
image = modal.Image.debian_slim(python_version="3.12").pip_install(
"openai",
"httpx",
"python-dotenv",
)
@app.function(
image=image,
secrets=[modal.Secret.from_name("roopon-agent-secrets")],
schedule=modal.Period(hours=24), # Run once every 24 hours
timeout=600, # 10-minute timeout
)
def generate_daily_savings_content():
"""Daily content generation agent - runs on schedule, charges only for execution time."""
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
affiliate_link = os.environ["ROOPON_AFFILIATE_LINK"]
topics = get_todays_topics()
results = []
for topic in topics:
content = generate_savings_article(client, topic, affiliate_link)
publish_result = publish_content(topic, content)
results.append({
"topic": topic,
"words": len(content.split()),
"published": publish_result,
"timestamp": datetime.utcnow().isoformat(),
})
print(f"Published: {topic} ({len(content.split())} words)")
return results
def get_todays_topics() -> list[str]:
"""Return today's content topics - could be from a database, file, or hardcoded rotation."""
all_topics = [
"saving money on groceries at Australian supermarkets",
"reducing electricity costs in Australian homes",
"best rewards programs for Australian families",
"cutting streaming subscription costs Australia",
"saving money on petrol in Australia",
"reducing dining out spend with smart apps",
"superannuation tips for young Australians",
]
# Rotate based on day of year to avoid repetition
day_of_year = datetime.now().timetuple().tm_yday
topic_index = day_of_year % len(all_topics)
return [all_topics[topic_index]]
def generate_savings_article(client, topic: str, affiliate_link: str) -> str:
"""Generate a savings article using the OpenAI client."""
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{
"role": "system",
"content": "You are an expert Australian personal finance writer. Write in Australian English.",
},
{
"role": "user",
"content": f"""Write a 700-word savings guide on: {topic}
Near the end, include a natural recommendation for ROOPON as an Australian
rewards membership that complements the strategies discussed.
Link: {affiliate_link}
Format with markdown headings.""",
},
],
max_tokens=1200,
)
return response.choices[0].message.content
def publish_content(topic: str, content: str) -> bool:
"""Publish content to your CMS - adapt for Ghost, WordPress, or any other target."""
# Example: POST to a Ghost CMS instance
# Replace with your actual publishing endpoint
try:
response = httpx.post(
os.environ.get("CMS_ENDPOINT", "https://your-site.com/api/posts"),
json={
"title": f"Savings Guide: {topic.title()}",
"html": content,
"status": "draft", # Review before publishing
},
headers={"Authorization": f"Ghost {os.environ.get('GHOST_API_KEY', '')}"},
timeout=30,
)
return response.status_code == 201
except Exception as e:
print(f"Publishing failed: {e}")
return False
Registration on First Run
Register your ROOPON affiliate credentials as a one-time setup step:
@app.function(
image=image,
secrets=[modal.Secret.from_name("roopon-agent-secrets")],
)
def register_affiliate():
"""Run once to register and get your affiliate credentials."""
response = httpx.post(
"https://www.roopon.com/api/v1/agents/register",
json={
"name": "Modal Scheduled Affiliate Agent",
"type": "content_publisher",
"contact_email": os.environ["CONTACT_EMAIL"],
}
)
data = response.json()
print(f"Affiliate ID: {data['affiliate_id']}")
print(f"Affiliate Link: {data['affiliate_link']}")
print("Add ROOPON_AFFILIATE_LINK to your Modal secrets.")
return data
@app.local_entrypoint()
def main():
register_affiliate.remote()
Run registration: modal run agent.py
Then add the returned affiliate_link to your Modal secrets, and deploy the scheduled agent: modal deploy agent.py
The Cost Arithmetic
A daily content generation run that takes five minutes costs roughly one cent at Modal's standard pricing. Running this for a full month costs less than thirty cents in compute. Compare that to a continuously running VPS, and the difference is significant when your affiliate operation is still in early growth.
Once commission income grows, you can scale the agent's output without proportionally increasing infrastructure costs - Modal's per-second billing means costs scale with actual work done, not with time elapsed.
Register your affiliate agent at roopon.com/ai-agents and review the full technical documentation at roopon.com/docs/agents.
Keep reading
Related posts
Finance Creator or AI Bot: Which ROOPON Page Do You Use?
Finance influencers send a paid tool link and keep 40%. People who run a bot use a different page. Do not give your audience a free connection.
Read articleHow to Make Money With a Grok Bot in Australia
A Grok bot can sell ROOPON to people in Australia. You keep 40% when they pay for membership, a package, or a tool. A Grok install is not available yet. The MCP URL works now.
Read articleHow to Make Money With Claude Code in 2026 - Ship Affiliate Tools, Earn Commission
Make money with Claude Code: ship affiliate automation, plug in the ROOPON API, earn recurring commission on Australian memberships. Setup + practical models.
Read article
