Skip to content

feat: add NanoGPT API quota monitoring support#1490

Merged
looplj merged 3 commits into
looplj:unstablefrom
djdembeck:feat/nanogpt-quota-support
Apr 26, 2026
Merged

feat: add NanoGPT API quota monitoring support#1490
looplj merged 3 commits into
looplj:unstablefrom
djdembeck:feat/nanogpt-quota-support

Conversation

@djdembeck

@djdembeck djdembeck commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

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.

Screenshot From 2026-04-25 15-23-45

Spirit / Intent

Enable visibility into NanoGPT API subscription usage through the existing quota monitoring infrastructure.

Key Changes

  • New NanoGPT quota checker — Fetches subscription usage from NanoGPT's /api/subscription/v1/usage endpoint, maps state values (active/grace/inactive) to normalized statuses (available/warning/exhausted), and computes the earliest window reset time.
  • Schema extension — Added nanogpt to the ProviderQuotaStatusProviderType enum in the Ent schema and GraphQL API, enabling quota status persistence for NanoGPT channels.
  • Quota service integration — Registered the NanoGPT checker in the quota service, extended channel type filtering to include nanogpt and nanogpt_responses, and added API-key credential validation (vs. OAuth required for other providers).
  • Frontend quota display — Added NanoGPT-specific quota row rendering showing per-window usage bars (weekly input tokens, daily input tokens, daily images), percentage indicators, and reset countdowns. Includes deduplication of multiple NanoGPT channels in the quota panel.
  • Test coverage — 14 unit tests covering happy path, warning/exhausted/grace states, missing credentials, API errors, HTTP non-2xx status, custom base URLs, unknown states, malformed JSON, null windows, and URL construction.

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.

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
@djdembeck djdembeck force-pushed the feat/nanogpt-quota-support branch from 91298e1 to 88dc417 Compare April 25, 2026 19:16
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.
@djdembeck djdembeck force-pushed the feat/nanogpt-quota-support branch from 88dc417 to fdae5ac Compare April 25, 2026 19:19

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

high

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)

medium

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;
}

@djdembeck

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread frontend/src/components/quota-badges.tsx Outdated
Comment thread internal/server/biz/provider_quota/nanogpt_checker.go Outdated
@djdembeck djdembeck marked this pull request as draft April 25, 2026 19:56
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.
@djdembeck djdembeck marked this pull request as ready for review April 25, 2026 20:28

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@looplj looplj merged commit 41964a5 into looplj:unstable Apr 26, 2026
4 checks passed
@djdembeck djdembeck deleted the feat/nanogpt-quota-support branch April 26, 2026 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants