{"record":{"id":"1fed67e8b0cae147","repo":"chatboxai/chatbox","slug":"missing-token-for-rerank-provider-providerid","errorCode":null,"errorMessage":"Missing token for rerank provider: ${providerId}","messagePattern":"Missing token for rerank provider: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/main/session-attachment-rag/model-providers.ts","lineNumber":98,"sourceCode":"        const settings = getSettings()\n        const { providerSetting, formattedApiHost } = getProviderSettings(\n          {\n            ...settings,\n            provider: providerId,\n            modelId,\n          },\n          settings\n        )\n\n        let apiHost = formattedApiHost\n        let token = providerSetting.apiKey\n        if (providerId === 'chatbox-ai') {\n          apiHost = getChatboxAPIOrigin()\n          token = store.get('settings.licenseKey')\n        }\n\n        if (!token) {\n          throw new Error(`Missing token for rerank provider: ${providerId}`)\n        }\n\n        const client = new CohereClient({\n          environment: apiHost,\n          token,\n        })\n        return { client, modelId }\n      } catch (error) {\n        log.error(`[MODEL] Failed to resolve session attachment rerank provider: ${modelString}`, error)\n        sentry.withScope((scope) => {\n          scope.setTag('component', 'session-attachment-rag-model')\n          scope.setTag('operation', 'get_rerank_provider')\n          scope.setExtra('rerankModel', modelString)\n          sentry.captureException(error)\n        })\n        throw error\n      }\n    },","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/chatboxai/chatbox/blob/81571269addb6bafb589a920b2883f1e1e084fd1/src/main/session-attachment-rag/model-providers.ts#L80-L116","documentation":"Thrown when constructing the CohereClient for reranking if no auth token could be obtained: for providerId==='chatbox-ai' it requires store.get('settings.licenseKey'); for any other provider it requires providerSetting.apiKey. The model string parsed successfully ([93] passed) but the credential is missing.","triggerScenarios":"Rerank model set to a third-party provider whose apiKey is empty in provider settings; or rerank model set to 'chatbox-ai:...' while settings.licenseKey is absent/cleared. The CohereClient constructor would otherwise be called with token=undefined.","commonSituations":"User configured a rerank model but never entered the provider's API key; license expired for chatbox-ai rerank; provider settings reset; switching providers without migrating credentials.","solutions":["For chatbox-ai rerank, activate a license (settings.licenseKey).","For third-party rerank providers, fill in the provider's apiKey in settings before enabling reranking.","Disable reranking (clear the model string) until credentials are configured.","Validate apiKey presence at settings-save time so the UI blocks an invalid rerank config."],"exampleFix":"// before\nif (!token) throw new Error(`Missing token for rerank provider: ${providerId}`)\n\n// caller pre-check\nif (providerId === 'chatbox-ai' ? !store.get('settings.licenseKey') : !providerSetting.apiKey) {\n  warnUser(`Add credentials for ${providerId} to enable reranking`)\n  return null\n}","handlingStrategy":"validation","validationCode":"const parsed = parseKnowledgeBaseModelString(modelString)\nif (parsed) {\n  const token = parsed.providerId === 'chatbox-ai' ? store.get('settings.licenseKey') : getProviderSettings({...settings, provider: parsed.providerId, modelId: parsed.modelId}, settings).providerSetting.apiKey\n  if (!token) { warn(`Add credentials for ${parsed.providerId}`); return null }\n}","typeGuard":"function isMissingRerankToken(e: unknown): e is Error { return e instanceof Error && e.message.startsWith('Missing token for rerank provider:') }","tryCatchPattern":"try { return await getSessionAttachmentRerankProvider(modelString) } catch (e) { if (isMissingRerankToken(e)) { ui.promptAddCredentials(e.message); return null } throw e }","preventionTips":["Require credentials when saving a rerank model.","For chatbox-ai rerank, keep the license active.","Disable reranking when its credentials are removed."],"tags":["session-attachment-rag","rerank","configuration","auth","typescript"],"backgroundTag":null,"analyzedSha":"81571269addb6bafb589a920b2883f1e1e084fd1","analyzedAt":"2026-08-12T21:51:44.981Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}