lbjlaq/Antigravity-Manager · error · Error
apiKeyFun.errors.queryFailed
Error message
apiKeyFun.errors.queryFailed
What it means
ApiKeyFun's balance query throws this when, after fetching usage and model data, neither a valid quota/remaining value nor a model list could be obtained — i.e. the key/address did not yield usable data. The message is shown via setQueryError.
Solutions
- Verify the API key is valid and has quota by calling the provider directly (curl /v1/models)
- Check the configured base URL matches the provider's OpenAI-compatible endpoint
- Inspect network responses for 200-with-error bodies and surface them
- Add a defaultValue fallback check before throwing so partial data (e.g. models only) is not discarded
Example fix
// before
throw new Error(t('apiKeyFun.errors.queryFailed', { defaultValue: '无法获取有效的额度数据...' }));
// after
if (usageSummary) { /* use partial result */ }
else throw new Error(t('apiKeyFun.errors.queryFailed', { defaultValue: '无法获取有效的额度数据或模型列表...' })); Defensive patterns
Strategy: validation
Validate before calling
const hasData = usageSummary?.remaining != null || (modelList && modelList.length > 0); if (!hasData) throw new Error('no valid quota/model data'); Type guard
const isValidUsage = (u: unknown): u is { remaining: number } => !!u && typeof (u as any).remaining === 'number'; Try / catch
try { await queryBalance(key); } catch (e) { setQueryError(e?.message); setManagedKeys(prev => prev.map(k => k.key === key ? { ...k, lastStatus: 'error' } : k)); } Prevention
- Verify keys with a cheap /v1/models call before full balance queries
- Normalize provider response shapes before use
- Validate base URL format before querying
When it happens
Trigger: Query completes without throwing but the parsed usage summary lacks balance/remaining data AND the model list is empty — e.g. wrong base URL, invalid API key returning 200 with an error body, or an unsupported provider shape.
Common situations: Typo in the API base URL (pointing at a non-OpenAI-compatible endpoint), revoked or mistyped API key, provider that returns 200 with an HTML/error payload.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
AI-assisted analysis of lbjlaq/Antigravity-Manager@90a2b6b207 (2026-09-19).
Data as JSON: /api/errors/b6cae173c18c1844.
Report an issue: GitHub.
Appendix: source
Thrown at src/pages/ApiKeyFun.tsx:249
baseUrl: endpoint // optionally update baseUrl
};
return updated;
} else {
// Automatically save new key
return [{
id: crypto.randomUUID(),
key,
name: maskKey(key),
baseUrl: endpoint,
createdAt: now,
lastUsedAt: now,
lastStatus: 'ok',
lastRemaining: usageSummary?.remaining
}, ...prev];
}
});
} else {
throw new Error(t('apiKeyFun.errors.queryFailed', { defaultValue: '无法获取有效的额度数据或模型列表,请确认 API Key 是否有效,以及接口地址是否正确。' }));
}
} catch (error: any) {
console.error('Balance query failed', error);
setQueryError(error?.message || 'Query failed. Please verify network or key validity.');
setManagedKeys(prev => {
const existingIndex = prev.findIndex(item => item.key === key);
const now = Date.now();
if (existingIndex >= 0) {
const updated = [...prev];
updated[existingIndex] = {
...updated[existingIndex],
lastStatus: 'bad',
lastUsedAt: now,
baseUrl: endpoint
};
return updated;
} else {View on GitHub (pinned to 90a2b6b207)