james.xue/ali-safe-api
Laravel wrapper for Alibaba Cloud content safety (Green) API. Moderate text, images, videos, and audio for porn, politics, terrorism, ads, and more with a simple facade and config. Multiple scenes and PSR-friendly responses make it easy to plug into upload and publishing flows.
Build vs. buy on content safety. This package exists to answer one question cheaply: "do we need a moderation team, or can we rent one?" It wraps Alibaba Cloud's content moderation API (绿网 / Green Web) behind a Laravel-idiomatic facade, so the real decision it unlocks is buy the model, own the workflow — you still own thresholds, review queues, appeals, and takedown policy, but you don't own a classifier.
Feature decisions it de-risks. Anything where user-generated content becomes visible to other users:
Roadmap sequencing. Moderation is usually a hidden tax on every UGC feature. Committing to a provider lets you schedule community, marketplace, or social features without a parallel ML workstream. Conversely, if you can't pick a provider, that's a signal to defer UGC-heavy roadmap items.
Architecture decisions the integration forces. Moderating inline in a PHP request adds 100–500ms+ and a hard external dependency on your publish path. The package's existence is a prompt to decide up front:
Cost and capacity modeling. Per-call pricing differs sharply between text and image moderation, and image moderation is priced per image with volume tiers. This gives you a defensible unit-economics input for the UGC feature's business case.
Compliance posture. For a China-market product, content moderation is a legal obligation (Cybersecurity Law, ICP filing expectations, app store review for UGC). Choosing a domestic provider with domestic data residency is a compliance decision, not just an engineering one — this package makes that decision one composer require away, which is strategically useful in a roadmap conversation about "can we ship UGC in CN at all."
Human-in-the-loop sizing. Any real deployment needs a false-positive review queue and an appeals path. The package gives you machine labels; it says nothing about staffing. That gap is a budget line item you should surface now, not after launch.
Adopt it when:
Look elsewhere when:
Moderator interface with an Aliyun adapter is maybe a day of work and buys you the option to switch. For a compliance-critical path, that option is usually worth more than the saved day.alibabacloud/sdk directly. For a path that can block publishes or fail open, a single-maintainer dependency with no downstream users is a real risk. Mitigation: pin the version, read the source (it's small), and be prepared to fork.The MIT license is a genuine plus: no legal review friction, no copyleft contamination, forking is unambiguously permitted.
For executives — the one-paragraph version: "Content moderation is a launch gate for any feature where users see each other's content, and in China it's a legal requirement, not a nice-to-have. Building our own classifier is a multi-quarter ML investment we don't need to make. This package lets us rent Alibaba Cloud's moderation models from our existing Laravel codebase in about a day of engineering. Cost is per-call and predictable. The main caveat is that it's a small open-source project — so we'll isolate it behind our own internal interface, which costs us almost nothing and preserves our ability to switch providers if pricing, accuracy, or terms change."
For engineering:
ModerationService with our own DTOs, retry/timeout policy, and fail-open vs. fail-closed behavior per content type.For legal/compliance:
How can I help you explore Laravel packages today?