Developing a platform for the sale and distribution of AI models
The AI Model Sales Platform is a commercial infrastructure for monetizing ML developments: secure model delivery, intellectual property protection, flexible licensing schemes, and billing.
Monetization models
SaaS (API-as-a-Service): The consumer does not receive model weights, but calls them via an API. This is the most secure IP model. The provider fully controls access and can instantly revoke the license.
On-Premise Deployment: The consumer deploys the model on their own infrastructure. Requires hardware-based licensing (linked to a hardware fingerprint or cloud account ID). The risk of data leakage is higher.
Hybrid: API for development and testing, on-premise for production - a popular enterprise scheme.
Secure Delivery Model
from cryptography.fernet import Fernet
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
import base64
class SecureModelPackager:
def package_model(self, model_path: str, license_id: str,
hardware_fingerprint: str) -> bytes:
"""Упаковка модели с привязкой к лицензии и железу"""
# Генерация ключа, привязанного к лицензии + fingerprint
key_material = f"{license_id}:{hardware_fingerprint}".encode()
kdf = PBKDF2HMAC(
algorithm=hashes.SHA256(),
length=32,
salt=b"model_license_v1",
iterations=100000,
)
key = base64.urlsafe_b64encode(kdf.derive(key_material))
fernet = Fernet(key)
# Чтение и шифрование весов модели
with open(model_path, 'rb') as f:
model_bytes = f.read()
encrypted = fernet.encrypt(model_bytes)
# Создание manifest с лицензионными ограничениями
manifest = {
"license_id": license_id,
"hardware_fingerprint": hardware_fingerprint,
"model_hash": hashlib.sha256(model_bytes).hexdigest(),
"valid_until": (datetime.utcnow() + timedelta(days=365)).isoformat(),
"usage_limit_requests": 1_000_000
}
return package_with_manifest(encrypted, manifest)
class SecureModelLoader:
def load(self, package_path: str, license_key: str) -> torch.nn.Module:
"""Загрузка и расшифровка модели"""
manifest, encrypted_model = unpack(package_path)
# Валидация лицензии
if not self._validate_license(manifest, license_key):
raise LicenseError("Invalid or expired license")
# Расшифровка
fernet = Fernet(self._derive_key(manifest['license_id']))
model_bytes = fernet.decrypt(encrypted_model)
# Проверка целостности
if hashlib.sha256(model_bytes).hexdigest() != manifest['model_hash']:
raise IntegrityError("Model file corrupted")
return torch.load(io.BytesIO(model_bytes))
License Server
class LicenseServer:
async def issue_license(self, purchase_id: str, customer_id: str,
model_id: str, tier: str) -> str:
license_key = secrets.token_hex(32)
await self.db.create_license({
'license_key': license_key,
'customer_id': customer_id,
'model_id': model_id,
'tier': tier,
'requests_limit': self.get_tier_limits(tier)['requests'],
'valid_until': datetime.utcnow() + self.get_tier_duration(tier),
'created_at': datetime.utcnow()
})
return license_key
async def validate_and_track(self, license_key: str) -> dict:
license = await self.db.get_license(license_key)
if not license:
raise LicenseError("License not found")
if license['valid_until'] < datetime.utcnow():
raise LicenseError("License expired")
if license['requests_used'] >= license['requests_limit']:
raise LicenseError("Request limit exceeded")
# Инкремент счётчика использования
await self.db.increment_usage(license_key)
return license
Typical client type: AI startups selling specialized models (medical diagnostics, legal analysis, industrial defect detection) to enterprises with on-premise requirements.







