{"record":{"id":"deb5d38687a6bc09","repo":"Mintplex-Labs/anything-llm","slug":"xai-api-key-must-be-provided-to-use-agents","errorCode":null,"errorMessage":"xAI API Key must be provided to use agents.","messagePattern":"xAI API Key must be provided to use agents\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/agents/index.js","lineNumber":219,"sourceCode":"          );\n        break;\n      case \"deepseek\":\n        if (!process.env.DEEPSEEK_API_KEY)\n          throw new Error(\"DeepSeek API Key must be provided to use agents.\");\n        break;\n      case \"litellm\":\n        if (!process.env.LITE_LLM_BASE_PATH)\n          throw new Error(\n            \"LiteLLM API base path and key must be provided to use agents.\"\n          );\n        break;\n      case \"apipie\":\n        if (!process.env.APIPIE_LLM_API_KEY)\n          throw new Error(\"ApiPie API Key must be provided to use agents.\");\n        break;\n      case \"xai\":\n        if (!process.env.XAI_LLM_API_KEY)\n          throw new Error(\"xAI API Key must be provided to use agents.\");\n        break;\n      case \"zai\":\n        if (!process.env.ZAI_API_KEY)\n          throw new Error(\"Z.AI API Key must be provided to use agents.\");\n        break;\n      case \"novita\":\n        if (!process.env.NOVITA_LLM_API_KEY)\n          throw new Error(\"Novita API Key must be provided to use agents.\");\n        break;\n      case \"nvidia-nim\":\n        if (!process.env.NVIDIA_NIM_LLM_BASE_PATH)\n          throw new Error(\n            \"NVIDIA NIM base path must be provided to use agents.\"\n          );\n        break;\n      case \"ppio\":\n        if (!process.env.PPIO_API_KEY)\n          throw new Error(\"PPIO API Key must be provided to use agents.\");","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/agents/index.js#L201-L237","documentation":"Thrown by AgentHandler.checkSetup() (server/utils/agents/index.js:218) when the workspace agent provider is 'xai' but XAI_LLM_API_KEY is unset/empty. xAI (Grok) exposes its API behind this single key, which the guard validates before the agent session is created.","triggerScenarios":"An agent invocation runs with workspace.agentProvider === 'xai' while XAI_LLM_API_KEY is absent from process.env. Path: #providerSetupAndCheck() -> checkSetup() at index.js:476.","commonSituations":"xAI selected in System > LLM Preference without a key; key from console.x.ai not added to .env; .env edited but the server not restarted; key revoked after rotation.","solutions":["Create an API key at https://console.x.ai and set XAI_LLM_API_KEY in .env.","Restart AnythingLLM to reload process.env.","Validate with curl -H 'Authorization: Bearer $XAI_LLM_API_KEY' https://api.x.ai/v1/models.","Confirm the agent model is a valid xAI model id (e.g. grok-beta)."],"exampleFix":"// before (.env)\n// XAI_LLM_API_KEY=\n\n// after (.env)\nXAI_LLM_API_KEY=xai-...your-key","handlingStrategy":"validation","validationCode":"const key = process.env.XAI_LLM_API_KEY;\nif (!key) {\n  throw new Error(\n    'Cannot start xAI agent: set XAI_LLM_API_KEY (from console.x.ai) in .env.'\n  );\n}","typeGuard":null,"tryCatchPattern":"try {\n  await agentHandler.start();\n} catch (e) {\n  if (/xAI API Key must be provided/.test(e.message)) {\n    return respondConfigError('xai', ['XAI_LLM_API_KEY']);\n  }\n  throw e;\n}","preventionTips":["Create the key at console.x.ai and paste it into .env in one step.","Restart AnythingLLM to load the new env.","Add a startup provider->env-var validator.","Keep .env out of git; rotate keys on suspected compromise."],"tags":["agents","llm-provider","xai","grok","api-key","environment-variables","config"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}