{"record":{"id":"71deb3ae9f52df10","repo":"wandb/openui","slug":"you-ve-exceeded-our-usage-quota-come-back-tomorro","errorCode":null,"errorMessage":"You've exceeded our usage quota, come back tomorrow to generate more UI.","messagePattern":"You've exceeded our usage quota, come back tomorrow to generate more UI\\.","errorType":"http","errorClass":"HTTPException","httpStatus":429,"severity":"warning","filePath":"backend/openui/server.py","lineNumber":123,"sourceCode":"\n\n@router.post(\"/v1/chat/completions\", tags=[\"openui/chat\"])\n@router.post(\n    \"/chat/completions\",\n    tags=[\"openui/chat\"],\n)\nasync def chat_completions(\n    request: Request,\n    # chat_request: CompletionCreateParams,  # TODO: lots' fo weirdness here, just using raw json\n    # ctx: Any = Depends(weave_context),\n):\n    if request.session.get(\"user_id\") is None:\n        raise HTTPException(status_code=401, detail=\"Login required to use OpenUI\")\n    user_id = request.session[\"user_id\"]\n    yesterday = datetime.now() - timedelta(days=1)\n    tokens = Usage.tokens_since(user_id, yesterday.date())\n    if config.ENV == config.Env.PROD and tokens > config.MAX_TOKENS:\n        raise HTTPException(\n            status_code=429,\n            detail=\"You've exceeded our usage quota, come back tomorrow to generate more UI.\",\n        )\n    try:\n        data = await request.json()  # chat_request.model_dump(exclude_unset=True)\n        input_tokens = count_tokens(data[\"messages\"])\n        # TODO: we always assume 4096 max tokens (random fudge factor here)\n        data[\"max_tokens\"] = 4096 - input_tokens - 20\n        # TODO: refactor all these blocks into one once Ollama supports vision\n        # OpenAI Models\n        if data.get(\"model\").startswith(\"gpt\"):\n            if data[\"model\"] == \"gpt-4\" or data[\"model\"] == \"gpt-4-32k\":\n                raise HTTPException(status=400, data=\"Model not supported\")\n            response: AsyncStream[\n                ChatCompletionChunk\n            ] = await openai.chat.completions.create(\n                **data,\n            )","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/wandb/openui/blob/42d7ab4ab6650433486dfb12eb3783c393a3e475/backend/openui/server.py#L105-L141","documentation":"chat_completions enforces a daily usage quota in PROD: if a user's token usage in the last 24h (Usage.tokens_since) exceeds config.MAX_TOKENS, it raises HTTP 429 with the quota message. This protects the hosted service from runaway generation costs.","triggerScenarios":"Accumulating more than MAX_TOKENS of usage within one day in ENV=PROD, then calling chat completions again; the window is rolling from `datetime.now() - timedelta(days=1)`.","commonSituations":"Automated scripts/benchmarks hammering the endpoint; shared account used by a team; MAX_TOKENS left at the low default while doing heavy dev work in PROD mode.","solutions":["Wait until the 24h rolling window expires and usage drops below MAX_TOKENS.","Run with config.ENV != PROD for development (quota check is skipped outside PROD).","Raise config.MAX_TOKENS if you control the deployment.","Track Usage.tokens_since client-side and throttle requests before hitting the cap."],"exampleFix":"// before\nexport ENV=PROD && python -m openui\n// after\nexport ENV=DEV && python -m openui  # quota check bypassed outside PROD","handlingStrategy":"retry","validationCode":"# client-side quota pre-check if the endpoint exposes usage\nusage = s.get('http://localhost:7878/usage').json()\nif usage['tokens'] > MAX_TOKENS: raise RuntimeError('Quota exhausted for today')","typeGuard":null,"tryCatchPattern":"try:\n    r = s.post(url, json=payload)\n    if r.status_code == 429:\n        time.sleep(seconds_until_window_reset())\n        r = s.post(url, json=payload)\nexcept requests.RequestException:\n    backoff_and_retry()","preventionTips":["Throttle generation requests and monitor daily token usage","Use ENV=DEV for development work; reserve PROD quota","Implement client-side backoff on 429 responses","Avoid running bulk jobs against a shared account"],"tags":["http","rate-limit","quota","python","fastapi"],"backgroundTag":"rate-limit-exceeded-429","analyzedSha":"42d7ab4ab6650433486dfb12eb3783c393a3e475","analyzedAt":"2026-09-01T05:00:32.200Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}