Files
Alex 1e14605ee7 fix(quotas): keyless agent chat bucket, keep disabled policies disabled, cached rates
- check_usage treats a request through a keyless (draft) agent as agent
  traffic, matching how its usage rows are bucketed and the headless rule
- dashboard edits carry the stored enabled flag instead of re-enabling the
  policy; disabled policies are labelled in the Quotas tab and the editor
- quota 429s send x-should-retry: false so OpenAI SDK clients do not retry
  a refusal that cannot succeed before the reset
- cached-input and cache-write rates for Anthropic, OpenRouter and Groq
  gpt-oss-120b; refresh OpenRouter deepseek-v3.2 list prices
- UsageQuota reuses usagePercent; docs note that a user override needs an
  existing user
2026-09-21 15:26:29 +01:00

17 lines
629 B
Python

"""HTTP rendering of a quota refusal."""
from __future__ import annotations
from flask import Response, jsonify, make_response
from docsgpt.quotas.service import QuotaExceeded
def quota_exceeded_response(exceeded: QuotaExceeded) -> Response:
"""Return the 429 for an exhausted quota, with ``Retry-After`` set to the reset."""
response = make_response(jsonify(exceeded.to_payload()), 429)
response.headers["Retry-After"] = str(exceeded.retry_after_seconds)
# The reset can be weeks away; the OpenAI SDKs would otherwise retry with backoff.
response.headers["x-should-retry"] = "false"
return response