AI-Powered Content Moderation API Gateway
Build a moderation gateway in Laravel that sits in front of a service where users post text, such as comments or reviews. Every submission is checked with OpenAI's moderation endpoint (which detects categories such as harassment, hate and violence); clean content goes through, clearly harmful content is blocked, and borderline content is held and queued for a human moderator to review in a dashboard. Results are cached in Redis by content hash, so identical text isn't checked twice, and the gateway keeps working sensibly when the AI service is slow or down. You'll learn integrating an AI API responsibly, thresholds and human review, Laravel queues and Redis caching, rate limits and fallbacks, and testing with a faked API.
- Estimate
- ~13h
- Steps
- 7
- Completed by
- 0
- Proposed by
- codeseed.app
OpenAI API · Laravel Queues · Redis
Project roadmap
- 01
Build the moderation client
~2hCreate a Laravel app and a ModerationClient class that sends text to OpenAI's moderation endpoint with Laravel's HTTP client (API key from the environment, a timeout, and retries on 429 and 5xx), and returns a typed result: flagged or not, and each category's score. Log only a hash of the text, not the text itself. Done when: the client returns category scores for sample texts.
- 02
Decide what happens to each submission
~2hDefine a policy in a config file: per category, a score above which content is blocked and a lower score above which it's held for review. Hook the check into the submission endpoint: clean content is published at once, blocked content gets a clear, polite message, and held content is saved as pending and not shown until reviewed. Record every decision with the scores. Done when: sample texts are published, held or blocked according to the policy.
- 03
Cache results in Redis
~1.5hBefore calling the API, normalize the text (trim and collapse spaces) and look up its SHA-256 hash in Redis; after a call, store the result with an expiry (for example 7 days). Record the cache hit rate. Done when: submitting the same text twice calls the API only once.
- 04
Queue content for review
~2.5hDispatch a queued job for each held submission that adds it to the review queue and notifies moderators. Build a review dashboard for users with a moderator role: pending items oldest first, the scores per category, and approve or reject buttons with a note, recording who decided and when. Approved items are published. Done when: moderators can review held content, and decisions take effect immediately.
- 05
Handle limits and outages
~2hAdd Laravel rate limiting per user on submissions. When the moderation API is down or times out after retries, apply a configurable fail-safe policy: hold everything for review (safer) or publish and review later, and show the moderators a banner that automatic moderation is degraded. Use a circuit breaker so an outage doesn't slow every request. Done when: disabling the API key or network makes submissions follow the fail-safe policy without errors.
- 06
Report and tune
~1hAdd a report page with decisions per day (published, held and blocked), how often moderators overturned automatic decisions, and the cache hit rate. Use it to tune the thresholds, and document how in README.md. Done when: the report shows accurate numbers.
- 07
Test it
~2hWrite feature tests with Http::fake for the moderation API: each decision path, caching, retries, the fail-safe policy during an outage, rate limits, and the review workflow (including authorization for moderators only). Done when: php artisan test passes without calling the real API.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack