Public API / MCP report 0 video credits while the web app shows credits (subscription.createdAt not loaded for API key & OAuth orgs)
Description
On hosted platform.postiz.com, video generation is refused through every non-browser route, while the web app for the same organization shows credits and generates successfully:
- The web app's Seedance 2.0 dialog shows "49 credits left", and generating from the UI works.
POST /public/v1/generate-video(API key) returns402 "You have reached the maximum number of generated videos for your subscription."- MCP
generateVideoTool(API key) returns"Video generation failed: No AI video credits are available on this account."
The API key is for the same org: /public/v1/integrations returns the same channels as the web app.
Root cause (from reading the source at 2a46d88): SubscriptionService.checkCredits() derives the billing window from organization.subscription.createdAt:
let date = dayjs(organization.subscription.createdAt);
while (date.isBefore(dayjs())) date = date.add(1, 'month');
const checkFromMonth = date.subtract(1, 'month');The web path's organization lookup selects subscription.createdAt (organization.repository.ts around line 274). These lookups don't:
OrganizationRepository.getOrgByApiKey(), used by the public API and by MCP API-key auth (start.mcp.ts→resolveAuth)OAuthRepository.findByAccessToken(), used by MCP OAuth (pos_tokens)OrganizationRepository.getUserOrg()
With createdAt undefined, dayjs(undefined) is "now". The loop normally doesn't run (same millisecond), so checkFromMonth = now − 1 month. API/MCP/OAuth callers are therefore metered on a rolling 30-day window, and web users from the subscription anniversary. After a busy month, the API reports 0 credits while the web still has credits.
Reproduction steps
- Use an org on a paid tier that used most of its monthly video allowance in the 30 days before its subscription anniversary.
- After the anniversary, open the web Seedance dialog. It shows credits, and generating works.
- With that org's API key, call
POST /public/v1/generate-videowith{"type":"seedance","output":"horizontal","customParams":{...}}, or MCPgenerateVideoTool. - You get a 402 / "No AI video credits are available on this account."
Expected behavior
The API, MCP and OAuth routes use the same billing window as the web app, so the same org sees the same credit balance everywhere.
Actual Behavior with Screenshots
The API/MCP routes refuse with 402 while the web dialog shows 49 credits and generates.
Operating system
Windows
Node Version
v24.15.0 (client side; the bug is in the hosted backend)
Provide any additional context for the Bug.
Suggested fix: add createdAt: true to the subscription.select in the three lookups above (3 added lines). A ready commit is on a fork for reference: https://github.com/alkhunizan/postiz-app/commit/02a2b6a3be9c1aa0089982e61c196499d7e3836e
It's not opened as a PR because the PR template requires confirming no AI was used. This analysis and the patch were produced with an AI coding assistant, so please treat the commit as a pointer only.
A second, smaller frontend bug: apps/frontend/src/components/launches/ai.video.tsx (/copilot/credits?type=ai_videos) and polonto/polonto.picture.generation.tsx (/copilot/credits, which defaults to ai_images) share the SWR key 'copilot-credits'. Whichever loads first can make the other dialog display the wrong credit type.
Have you spent some time to check if this bug has been raised before?
- I checked and didn't find similar issue
Source: gitroomhq/postiz-app