feat: add monthly quota to API response body
All checks were successful
Deploy QR Rapido / test (push) Successful in 51s
Deploy QR Rapido / build-and-push (push) Successful in 15m14s
Deploy QR Rapido / deploy-staging (push) Has been skipped
Deploy QR Rapido / deploy-production (push) Successful in 3m9s

Add monthlyQuotaRemaining/monthlyQuotaLimit fields to QRResponseDto
populated from X-Quota-* headers set by rate limiter. MCP server
now displays quota in tool result text instead of web credits.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Ricardo Carneiro 2026-05-07 22:01:20 -03:00
parent 1eb1a3207c
commit 4570e9b70b
4 changed files with 18 additions and 2 deletions

View File

@ -114,6 +114,14 @@ namespace QRRapidoApp.Controllers
};
}
// Inject monthly quota from response headers (set by ApiKeyAuthorizeAttribute)
if (HttpContext.Response.Headers.TryGetValue("X-Quota-Remaining", out var qr) &&
int.TryParse(qr, out var quotaRemaining))
result.MonthlyQuotaRemaining = quotaRemaining;
if (HttpContext.Response.Headers.TryGetValue("X-Quota-Limit", out var ql) &&
int.TryParse(ql, out var quotaLimit))
result.MonthlyQuotaLimit = quotaLimit;
// Map format and mimeType into the response
result.Format = format;
result.MimeType = format switch

View File

@ -18,5 +18,11 @@ namespace QRRapidoApp.Models.DTOs
/// <summary>MIME type of the encoded image (e.g. "image/png", "image/webp").</summary>
public string MimeType { get; set; } = "image/png";
/// <summary>Monthly API quota remaining (from rate limiter). -1 = unlimited.</summary>
public int MonthlyQuotaRemaining { get; set; } = -1;
/// <summary>Monthly API quota limit. -1 = unlimited.</summary>
public int MonthlyQuotaLimit { get; set; } = -1;
}
}

View File

@ -109,7 +109,9 @@ function successContent(data, label = "qr") {
file ? `🖼 Aberto em: ${file}` : "",
`${data.generationTimeMs}ms`,
`💾 Cache: ${data.fromCache ? "hit" : "miss"}`,
`📊 Créditos restantes: ${data.remainingCredits ?? "N/A"}`
data.monthlyQuotaLimit >= 0
? `📊 Quota mensal: ${data.monthlyQuotaRemaining}/${data.monthlyQuotaLimit}`
: `📊 Quota mensal: ilimitada`
].filter(Boolean).join("\n")
}
]

View File

@ -164,7 +164,7 @@ function createMcpServer(apiKey) {
return {
content: [
{ type: "image", data: data.qrCodeBase64, mimeType: data.mimeType || "image/png" },
{ type: "text", text: `✅ QR gerado (${type})\n${data.generationTimeMs}ms\n💾 cache: ${data.fromCache ? "hit" : "miss"}` }
{ type: "text", text: `✅ QR gerado (${type})\n${data.generationTimeMs}ms\n💾 cache: ${data.fromCache ? "hit" : "miss"}\n📊 quota: ${data.monthlyQuotaRemaining >= 0 ? `${data.monthlyQuotaRemaining}/${data.monthlyQuotaLimit}` : "ilimitada"}` }
]
};
}