Skip to main content

Command Palette

Search for a command to run...

Deploying a CrewAI Content Creator as a Scalable REST API

Updated
•6 min read
Deploying a CrewAI Content Creator as a Scalable REST API
M
Programmer, Creative and Tech Nerd. I build with code, write about AI and Software Development and explore the future of intelligent Agents.

A guide to building and deploying an autonomous multi-agent system for automated content generation that is ready for production use.

Quick look

Project TitleContent Creator Agent API
GitHub Repositoryneuralstack_blog/projects/content-creator-api
Primary Use CaseAutomating the research and writing of blog posts, articles, or other forms of digital content.
Core TechnologiesCrewAI, FastAPI, Python, Render, Google Apps Script
DeploymentProduction-ready API and Background Worker on Render
Key FeatureA fully autonomous, multi-agent system exposed via a robust REST API, triggerable from any service.

Introduction: The Content Treadmill Problem

Content creation is the engine of digital engagement, but it's a relentless and time-consuming process. From topic research to writing, editing, and optimizing, the manual effort represents a significant bottleneck for both businesses and individuals. What if you could automate the entire process and turn a simple topic idea into a thoroughly researched, well-written article with just one click?

This project addresses this challenge. I developed an autonomous content creator agent using CrewAI, a powerful framework for orchestrating multi-agent systems. This isn't just a simple prompt for a language model but a collaborative team of specialized AI agents that mimic a real-world content team.

This article details the architecture of this system and provides a professional guide for deploying it as a scalable, production-ready REST API on Render.

System Architecture: From a Spreadsheet to a Blog Post

The strength of this system lies in its decoupled, event-driven architecture. Each component has a distinct role, creating a robust and extensible pipeline.

  1. The Trigger (Google Sheets): A user simply adds a new topic to a row in a Google Sheet. This is the human-friendly starting point for the entire workflow.

  2. The Automation Layer (Google Apps Script): A lightweight script running within Google Sheets detects the new row. It immediately makes a secure HTTP POST request to our deployed API, sending the topic as a JSON payload.

  3. The API Endpoint (FastAPI on Render): A high-performance FastAPI application serves as the public-facing gateway. Its sole job is to receive the request, validate it, and instantly add a "content creation job" to a Redis queue. It immediately responds with 200 OK, ensuring the trigger service doesn't time out.

  4. The Agent Core (CrewAI on a Render Background Worker): This is the heart of the system. An always-on, non-timeout background worker on Render continuously monitors the Redis queue. When a new job appears, it pulls the topic and kicks off the CrewAI crew to perform its tasks.

The AI Crew: A Collaborative Team

The CrewAI implementation consists of two specialized agents that work sequentially:

  • Senior Research Analyst: This agent's goal is to conduct in-depth research on the provided topic. Using search tools, it scours the web for the latest trends, key data points, and relevant information, compiling its findings into a comprehensive report.

  • Expert Content Strategist: This agent receives the research report from the analyst. Its goal is to transform that raw data into a compelling, well-structured, and SEO-friendly blog post. It handles everything from crafting a catchy title to writing the introduction, body, and conclusion.

Deployment: A Production-Ready Setup on Render

Deploying an AI agent that can take several minutes to run requires a more sophisticated setup than a simple web server. A standard web service will time out. Here is the professional, paid architecture on Render that ensures reliability and scalability.

Total Cost: ~$7/month

Components:

  1. Web Service (API Endpoint): A cheap (Starterplan) or even free instance to run main.py.

  2. Redis Instance: A message queue to hold jobs. The free tier on Render is sufficient.

  3. Background Worker (Agent Runner): A Starterplan worker ($7/month). This service is always on, has no timeouts, and is where the actual CrewAI process runs.

Implementation Steps:

  1. Modify requirements.txt: Add the rq library for managing Redis queues.
# requirements.txt
crewai
crewai[tools]
fastapi
uvicorn
python-dotenv
rq
  1. Modify main.py to Enqueue Jobs: The API endpoint no longer runs the crew directly. It just adds the topic to the Redis queue.

Code Snippet: main.py (modified for queuing)

from fastapi import FastAPI
from pydantic import BaseModel
import os
from redis import Redis
from rq import Queue

# Connect to Redis (URL provided by Render)
redis_conn = Redis.from_url(os.getenv("REDIS_URL", "redis://localhost:6379"))
q = Queue("content_crew", connection=redis_conn)

app = FastAPI(...)

class ContentRequest(BaseModel):
    topic: str

@app.post("/create-content")
async def create_content(request: ContentRequest):
    # Instead of running the crew, enqueue a job to be run by the worker.
    # We point it to the function in our other file 'agent.create_content_crew'
    job = q.enqueue("agent.create_content_crew", request.topic)
    return {"status": "success", "job_id": job.get_id()}
  1. Create a worker.py file: This is the script that the Background Worker will run. It listens to the queue and executes the job.

Code Snippet: worker.py

import os
from redis import Redis
from rq import Worker, Queue, Connection

listen = ['content_crew'] # Name of the queue to listen to

# Get Redis URL from environment variables
redis_url = os.getenv('REDIS_URL', 'redis://localhost:6379')
conn = Redis.from_url(redis_url)

if __name__ == '__main__':
    with Connection(conn):
        worker = Worker(map(Queue, listen))
        worker.work()
  1. Deploy on Render:

    • Create a Redis instance (free tier). Copy the internal Redis URL.

    • Create a web service for main.py. Set its start command to uvicorn main:app --host 0.0.0.0 --port 10000.

    • Create a Background Worker for worker.py . Set its start command to python worker.py.

    • In both the Web Service and Background Worker, add your OPENAI_API_KEY and the REDIS_URL as environment variables.

Getting Started

  1. Clone the Repository:
git clone [Link to your GitHub Repository]
cd [repository-name]
  1. Set Up Environment: Create a Python virtual environment and install the dependencies.
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
  1. Configure API Keys: Create a .env file and add your OPENAI_API_KEY and any other required keys (e.g., SERPER_API_KEY).

  2. Test Locally: Follow the local testing procedures using uvicorn and ngrok as detailed in the project's documentation.

  3. Deploy: Deploy the application to Render using the professional architecture described above.

Testing and Validation

The reliability of an automated system is of utmost importance. I've compiled a comprehensive set of test cases and validation procedures to ensure that all components function correctly. This includes unit tests for individual functions, integration tests for the API, and end-to-end tests for the entire workflow.

Complete instructions for testing the system can be found in the test.md file in the repository.

Conclusion and Next Steps

This project serves as a solid foundation for building powerful, autonomous AI systems and integrating them into real-world business processes. By leveraging a multi-agent framework and deploying it with a scalable, production-ready architecture, we transformed a manual task into a fully automated pipeline.

Future enhancements could include:

  • Adding more agents: An SEO Specialist to optimize keywords or a Quality Editor to review and refine the final output.

  • Database Integration: Storing the generated content directly into a CMS or database.

  • Advanced Tooling: Equipping agents with more sophisticated tools for data analysis or image generation.


— Manuela Schrittwieser, Full-Stack AI Dev šŸ§‘ā€šŸ’» & Tech Writer

More from this blog

N

NeuralStack | MS

32 posts

NeuralStack | MS is your authoritative resource at the intersection of modern software development, AI engineering, and security engineering. I provide in-depth technical articles, industry trends, and actionable insights designed to empower developers and engineers in building secure, intelligent, and scalable systems.