Text-to-Video Task Pattern
Extend the opt-in text-to-video demo with organization entitlements, quotas, credits, idempotency, and refunds.
Synced with starter commit
7d452a6.
The text-to-video screen is an opt-in development pattern, not a production AI provider. It is unavailable unless demo features and the text-to-video mock are enabled; demo flags are ignored in production. Replace only src/services/ai/video.ts with your provider adapter.
POST /api/tasks/text-to-video requires same origin, rate limit, authentication, the organization tasks.text_to_video entitlement, the shared monthly task limit, and sufficient pooled credits. Supply Idempotency-Key in the header or body. The service inserts one organization-scoped task, spends credits, records the root ledger transaction, calls the provider, and marks success. Provider failure marks the task failed and appends a credit refund.
Cost is configured in src/config/tasks.ts by seconds and aspect ratio. Plus currently allows 50 organization tasks/month and 500 monthly credits; Max has unlimited task count and 2,500 credits; Free has neither capability. Fetch a task through GET /api/tasks/[uuid]; access is organization-scoped.
For a real long-running provider, keep these invariants but move execution to durable asynchronous work, use provider idempotency, verify callbacks, persist external IDs, and test duplicate requests, insufficient balance, timeout, callback replay, and refund failure.