QuantumNous/new-api · warning · Error
No enabled API keys found. Create or enable one first.
Error message
No enabled API keys found. Create or enable one first.
What it means
Thrown by fetchActiveChatKey() when the key list loads successfully but none of the first 50 keys has status ENABLED (API_KEY_STATUS.ENABLED). This is an expected account-state condition: the chat feature requires an active sk- key to build chat links, and the current user has none enabled.
Source
Thrown at web/src/features/chat/hooks/use-active-chat-key.ts:34
For commercial licensing, please contact support@quantumnous.com
*/
import { useQuery } from '@tanstack/react-query'
import { fetchTokenKey, getApiKeys } from '@/features/keys/api'
import { API_KEY_STATUS } from '@/features/keys/constants'
import { useAuthStore } from '@/stores/auth-store'
export async function fetchActiveChatKey() {
const result = await getApiKeys({ p: 1, size: 50 })
if (!result.success) {
throw new Error(result.message || 'Failed to load API keys')
}
const items = result.data?.items ?? []
const active = items.find((item) => item.status === API_KEY_STATUS.ENABLED)
if (!active) {
throw new Error('No enabled API keys found. Create or enable one first.')
}
const keyResult = await fetchTokenKey(active.id)
if (!keyResult.success || !keyResult.data?.key) {
throw new Error(keyResult.message || 'Failed to load API key')
}
return `sk-${keyResult.data.key}`
}
/**
* Get the currently active API key for chat links
*/
export function useActiveChatKey(enabled: boolean) {
const userId = useAuthStore((state) => state.auth.user?.id)
return useQuery({
queryKey: ['chat-active-key', userId],View on GitHub (pinned to e2c7aa7b10)
Solutions
- Go to the API Keys (tokens) page and create a new key, or enable an existing one.
- If an admin disabled the keys, resolve that with the admin (quota/billing).
- If you legitimately have >50 keys, raise the size parameter or paginate until an enabled key is found.
- Surface this message with a direct 'Create key' action in the UI instead of a bare error.
Example fix
// before
const result = await getApiKeys({ p: 1, size: 50 })
const active = items.find((item) => item.status === API_KEY_STATUS.ENABLED)
if (!active) throw new Error('No enabled API keys found. Create or enable one first.')
// after — search beyond the first page
async function findEnabledKey(): Promise<TokenInfo | undefined> {
for (let p = 1; p <= 5; p++) {
const r = await getApiKeys({ p, size: 100 })
if (!r.success) throw new Error(r.message || 'Failed to load API keys')
const hit = (r.data?.items ?? []).find(
(item) => item.status === API_KEY_STATUS.ENABLED
)
if (hit) return hit
if ((r.data?.items ?? []).length < 100) return undefined
}
return undefined
} Defensive patterns
Strategy: validation
Validate before calling
const { data: keyList } = useQuery({
queryKey: ['api-keys'],
queryFn: () => getApiKeys({ p: 1, size: 100 }),
})
const hasEnabledKey = (keyList?.data?.items ?? []).some(
(item) => item.status === API_KEY_STATUS.ENABLED
)
// render a 'Create API key' empty-state instead of triggering the error Type guard
const hasEnabledApiKey = (
items: { status: number }[] | undefined
): boolean =>
(items ?? []).some((item) => item.status === API_KEY_STATUS.ENABLED) Try / catch
try {
return await fetchActiveChatKey()
} catch (e) {
if (/No enabled API keys/i.test(getErrorMessage(e))) {
return renderCreateKeyPrompt() // guided recovery, not an error
}
throw e
} Prevention
- Create and enable at least one API key before using chat links
- Pre-check for an enabled key and render a create-key empty state
- Paginate past 50 keys (or raise size) if the account has many tokens
When it happens
Trigger: New user who never created a token; all tokens disabled or expired; user has more than 50 tokens with the enabled one beyond page 1; admin disabled the user's tokens.
Common situations: Fresh account opening the chat playground; tokens auto-disabled by quota exhaustion; keys beyond the hardcoded size:50 window.
Related errors
- Failed to load API keys
- Failed to initialize OAuth
- Failed to sign out session
- Unsupported verification method: {{method}}
- Failed to start verification
AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15).
Data as JSON: /api/errors/4b9581191d18c285.
Report an issue: GitHub.