{"record":{"id":"498366846b342d48","repo":"abhigyanpatwari/GitNexus","slug":"glm-api-key-is-required-but-was-not-provided","errorCode":null,"errorMessage":"GLM API key is required but was not provided","messagePattern":"GLM API key is required but was not provided","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"gitnexus-web/src/core/llm/agent.ts","lineNumber":311,"sourceCode":"\n      return new ChatAnthropic({\n        anthropicApiKey: minimaxConfig.apiKey,\n        model: minimaxConfig.model,\n        ...(temperature !== undefined ? { temperature } : {}),\n        maxTokens: minimaxConfig.maxTokens ?? 8192,\n        streaming: true,\n        ...(thinking ? { thinking } : {}),\n        clientOptions: {\n          baseURL: minimaxConfig.baseUrl ?? MINIMAX_ANTHROPIC_BASE_URLS.global_en,\n        },\n      });\n    }\n\n    case 'glm': {\n      const glmConfig = config as GLMConfig;\n\n      if (!glmConfig.apiKey || glmConfig.apiKey.trim() === '') {\n        throw new Error('GLM API key is required but was not provided');\n      }\n\n      return new ChatOpenAI({\n        apiKey: glmConfig.apiKey,\n        modelName: glmConfig.model,\n        temperature: glmConfig.temperature ?? 0.1,\n        maxTokens: glmConfig.maxTokens,\n        configuration: {\n          apiKey: glmConfig.apiKey,\n          baseURL: glmConfig.baseUrl ?? 'https://api.z.ai/api/coding/paas/v4',\n        },\n        streaming: true,\n      });\n    }\n\n    case 'deepseek': {\n      const deepseekConfig = config as DeepSeekConfig;\n","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/abhigyanpatwari/GitNexus/blob/d540b00184d71a896261ee02670da9a92d59d8f7/gitnexus-web/src/core/llm/agent.ts#L293-L329","documentation":"Thrown by createChatModel() in the 'glm' provider branch when glmConfig.apiKey is falsy or whitespace-only. GLM (Zhipu AI) is accessed through a ChatOpenAI wrapper pointed at https://api.z.ai/api/coding/paas/v4 (overridable via baseUrl); the key is required at construction time. Fails fast to avoid a 401 from the Z.AI API on first request.","triggerScenarios":"Calling createChatModel({ provider: 'glm', apiKey: undefined | '' | '   ', model: 'glm-4.6', ... }).","commonSituations":"The GLM/Z.AI key wasn't set in provider settings; the env var is unset in the deployed environment; switching to glm without a z.ai account.","solutions":["Obtain a key from api.z.ai (Zhipu AI) and enter it in provider settings","Ensure the key is non-empty and non-whitespace","If using a custom GLM-compatible endpoint, set baseUrl accordingly","Recreate the agent after setting the key"],"exampleFix":"// before\ncreateChatModel({ provider: 'glm', apiKey: '', model: 'glm-4.6' }); // throws\n\n// after\ncreateChatModel({ provider: 'glm', apiKey: userKey, model: 'glm-4.6' });","handlingStrategy":"validation","validationCode":"function hasGlmKey(cfg: { apiKey?: string }): boolean {\n  return typeof cfg.apiKey === 'string' && cfg.apiKey.trim().length > 0;\n}\nif (cfg.provider === 'glm' && !hasGlmKey(cfg)) {\n  throw new Error('Configure a GLM/Z.AI API key (from api.z.ai)');\n}","typeGuard":"function isGlmConfigReady(cfg: unknown): cfg is { provider: 'glm'; apiKey: string } {\n  return typeof cfg === 'object' && cfg !== null\n    && (cfg as any).provider === 'glm'\n    && typeof (cfg as any).apiKey === 'string'\n    && (cfg as any).apiKey.trim().length > 0;\n}","tryCatchPattern":"try {\n  createChatModel({ provider: 'glm', apiKey, model });\n} catch (e) {\n  if (e instanceof Error && /GLM API key is required/.test(e.message)) {\n    promptUserForKey('glm');\n    return;\n  }\n  throw e;\n}","preventionTips":["Obtain a key from api.z.ai (Zhipu AI)","Default baseURL is https://api.z.ai/api/coding/paas/v4 — override with baseUrl only if you have a compatible proxy","Re-create the agent after entering the key","If no GLM key, consider openrouter which proxies GLM models behind its own key"],"tags":["llm","glm","zhipu","config","api-key"],"backgroundTag":null,"analyzedSha":"d540b00184d71a896261ee02670da9a92d59d8f7","analyzedAt":"2026-08-12T19:50:25.132Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}