diegosouzapw/OmniRoute · error
missing_self_usage_scope
Error message
missing_self_usage_scope
What it means
Authorization error code from the API-key self-service build path: while assembling the per-key status (cost summary via getCostSummary, budget check via checkBudget), the caller's key lacks the self-usage scope required to view its own usage. It surfaces as the machine-readable code missing_self_usage_scope so the API layer can map it to a 403.
Solutions
- Grant the self-usage scope to the API key in settings
- Use an admin endpoint or dashboard to view usage instead
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at src/lib/usage/apiKeySelfService.ts:388 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diegosouzapw/OmniRoute@a179ffed5b (2026-08-25).
Data as JSON: /api/errors/36ba5635b5a1e736.
Report an issue: GitHub.
Appendix: source
Thrown at src/lib/usage/apiKeySelfService.ts:388
return {
now: deps.now ?? Date.now,
getCostSummary: deps.getCostSummary ?? costRules!.getCostSummary,
checkBudget: deps.checkBudget ?? costRules!.checkBudget,
getDbInstance: deps.getDbInstance ?? dbCore!.getDbInstance,
getProviderConnectionById: deps.getProviderConnectionById ?? localDb!.getProviderConnectionById,
getProviderConnections: deps.getProviderConnections ?? localDb!.getProviderConnections,
fetchAndPersistProviderLimits:
deps.fetchAndPersistProviderLimits ?? providerLimits!.fetchAndPersistProviderLimits,
};
}
export async function buildApiKeySelfServiceStatus(
metadata: ApiKeySelfServiceMetadata,
deps: ApiKeySelfServiceDeps = {}
) {
if (!hasSelfUsageScope(metadata.scopes)) {
throw new Error("missing_self_usage_scope");
}
const resolvedDeps = await normalizeDeps(deps);
const summary = resolvedDeps.getCostSummary(metadata.id);
resolvedDeps.checkBudget(metadata.id);
const cost = buildCostStatus(summary, resolvedDeps.now());
const tokens = aggregateTokens(
resolvedDeps.getDbInstance() as DbLike,
metadata.id,
cost.periodStartAt ?? new Date(getCurrentMonthWindow(resolvedDeps.now()).periodStartAt).toISOString()
);
const accountQuotas = await resolveAccountQuotas(metadata, resolvedDeps);
const accountQuota =
accountQuotas && accountQuotas.length === 1 ? accountQuotas[0] : undefined;
return {
apiKey: {View on GitHub (pinned to a179ffed5b)