feat: add NanoGPT API quota monitoring support#1490
Conversation
Add NanoGPT provider to the quota monitoring system across the full stack: - Frontend: quota badges component with windowed usage bars, token formatting, and account state badges for NanoGPT channels - Data layer: NanoGPT quota types and discriminated union extension - i18n: English and Chinese translations for NanoGPT quota labels - Ent schema: nanogpt provider type enum in schema and migrations - Business logic: NanoGPT quota checker with subscription usage API, state mapping (active/grace/inactive), multi-window reset tracking, proxy support, and API key fallback - GraphQL: nanogpt added to ProviderQuotaStatusProviderType enum - Bug fix: strengthened auth guard to skip empty APIKey/zero-length APIKeys in quota checks - Cleanup: removed stale gqlgen resolver stub
91298e1 to
88dc417
Compare
Raw data now groups dailyImages, dailyInputTokens, and weeklyInputTokens under a single 'windows' key instead of scattered top-level entries. This aligns the response structure with the consumer-facing model, making it easier to iterate over windows and keep related fields together.
88dc417 to
fdae5ac
Compare
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
There was a problem hiding this comment.
Code Review
This pull request introduces support for the NanoGPT provider, implementing backend quota checking logic and frontend visualization for specific usage windows like tokens and images. It also includes extensive code formatting and import reorganization across the frontend. Feedback highlights a critical bug in the Go backend where taking the address of a loop variable in the findEarliestResetAt function could result in incorrect timestamps. Furthermore, the frontend deduplication logic for NanoGPT channels should be refined to ensure that multiple accounts are correctly represented in the quota panel.
I am having trouble creating individual review comments. Click here to see my feedback.
internal/server/biz/provider_quota/nanogpt_checker.go (227-244)
The findEarliestResetAt function incorrectly takes the address of a local loop variable t. In Go versions prior to 1.22, loop variables are shared across iterations, meaning earliest would always point to the value of t from the last iteration that satisfied the condition. Even in Go 1.22+, taking the address of a local variable and returning it relies on escape analysis; it is safer and clearer to store the value and return a pointer to a fresh copy at the end.
func findEarliestResetAt(windows ...*NanoGPTQuotaWindow) *time.Time {
var earliest time.Time
found := false
for _, w := range windows {
if w == nil || w.ResetAt == nil || *w.ResetAt <= 0 {
continue
}
t := time.UnixMilli(*w.ResetAt)
if !found || t.Before(earliest) {
earliest = t
found = true
}
}
if !found {
return nil
}
return &earliest
}frontend/src/components/quota-badges.tsx (647-664)
The deduplicateChannels function deduplicates NanoGPT channels based solely on their provider type. This means if a user has multiple NanoGPT channels configured with different API keys (e.g., from different accounts), only one of them will be displayed in the quota panel. It would be better to deduplicate based on a unique identifier per account or simply use the channel ID to ensure that quotas for different accounts are all visible.
function deduplicateChannels(channels: ProviderQuotaChannel[]): ProviderQuotaChannel[] {
const seen = new Set<string>();
const result: ProviderQuotaChannel[] = [];
for (const ch of channels) {
// Deduplicate by type and ID to ensure multiple accounts are visible
const key = ch.type + ":" + ch.id;
if (seen.has(key)) continue;
seen.add(key);
result.push(ch);
}
return result;
}
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request implements quota tracking for NanoGPT, including a new backend checker to fetch usage data from the NanoGPT API, database schema updates to support the new provider type, and frontend components for displaying usage windows and limits. The review feedback identifies a bug in how reset timestamps are passed to the formatting utility in the UI and suggests a more robust URL construction method to handle protocol-relative base URLs in the backend checker.
Update nanogpt provider quota checker with enhanced validation logic. Refactor quota badge components for clearer tier display. Add comprehensive test coverage for quota checker scenarios.
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Summary
Adds quota monitoring for NanoGPT API key–based channels. Users can now view their NanoGPT usage across weekly input tokens, daily input tokens, and daily images limits directly from the quota badges in the AxonHub UI.
Spirit / Intent
Enable visibility into NanoGPT API subscription usage through the existing quota monitoring infrastructure.
Key Changes
/api/subscription/v1/usageendpoint, mapsstatevalues (active/grace/inactive) to normalized statuses (available/warning/exhausted), and computes the earliest window reset time.nanogptto theProviderQuotaStatusProviderTypeenum in the Ent schema and GraphQL API, enabling quota status persistence for NanoGPT channels.nanogptandnanogpt_responses, and added API-key credential validation (vs. OAuth required for other providers).Value
Users with NanoGPT channels can now see their API quota consumption at a glance and set up alerts when usage exceeds 80% of any window limit.