{"record":{"id":"a4adff76004d46c0","repo":"Budibase/budibase","slug":"budibase-ai-is-not-configured-in-this-environment","errorCode":null,"errorMessage":"Budibase AI is not configured in this environment (BBAI_LITELLM_KEY is missing). Ensure the key is available to every service that runs agents, including the automation worker.","messagePattern":"Budibase AI is not configured in this environment \\(BBAI_LITELLM_KEY is missing\\)\\. Ensure the key is available to every service that runs agents, including the automation worker\\.","errorType":"http","errorClass":"HTTPError","httpStatus":500,"severity":"critical","filePath":"packages/server/src/sdk/workspace/ai/llm/bbai.ts","lineNumber":28,"sourceCode":"  LLMResponse,\n  ReasoningEffort,\n} from \"@budibase/types\"\nimport tracer from \"dd-trace\"\nimport { licensing, quotas } from \"@budibase/pro\"\nimport { wrapLanguageModel } from \"ai\"\nimport { TransformStream } from \"node:stream/web\"\nimport environment from \"../../../../environment\"\nimport { Readable } from \"stream\"\nimport { blob } from \"stream/consumers\"\nimport { unwrapLiteLLMFileId } from \"./litellm\"\n\n// The OpenAI client resolves its API key lazily, so an undefined key would\n// otherwise surface later as a misleading \"OpenAI API key is missing\" error.\n// Validate up front so a missing key fails with an explicit message.\nexport function getBBAIKey(): string {\n  const apiKey = environment.BBAI_LITELLM_KEY\n  if (!apiKey) {\n    throw new HTTPError(\n      \"Budibase AI is not configured in this environment (BBAI_LITELLM_KEY is missing). \" +\n        \"Ensure the key is available to every service that runs agents, including the automation worker.\",\n      500\n    )\n  }\n  return apiKey\n}\n\ninterface OpenAIUsage {\n  prompt_tokens?: number\n  completion_tokens?: number\n  input_tokens?: number\n  output_tokens?: number\n}\n\nconst calculateBudibaseAICredits = (\n  inputTokens: number,\n  outputTokens: number","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/llm/bbai.ts#L10-L46","documentation":"Thrown by getBBAIKey when the BBAI_LITELLM_KEY environment variable is unset or empty. Budibase AI's OpenAI client resolves its key lazily, so without this up-front check the failure would surface later as a misleading \"OpenAI API key is missing\" error. It is an HTTPError with status 500.","triggerScenarios":"Any Budibase AI agent/LLM call (chat, automation agent, reviewer) when environment.BBAI_LITELLM_KEY is not set in the process running the agent — server or worker.","commonSituations":"Self-hosted deployments where the key was added to the server .env but not the worker's env; docker-compose files missing the env passthrough; upgrades that introduced Budibase AI without updating env config.","solutions":["Set BBAI_LITELLM_KEY in the environment of every service that runs agents (server AND automation worker)","Restart the server and worker processes so the new env var is picked up","If using docker-compose/Kubernetes, add the variable to each backend service's env configuration"],"exampleFix":"// before: worker env missing key\nservices:\n  worker:\n    environment:\n      - LITELLM_URL=...\n// after\nservices:\n  worker:\n    environment:\n      - BBAI_LITELLM_KEY=${BBAI_LITELLM_KEY}\n      - LITELLM_URL=...","handlingStrategy":"validation","validationCode":"if (!process.env.BBAI_LITELLM_KEY) {\n  throw new Error(\"BBAI_LITELLM_KEY must be set before starting agents\")\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runAgent(input)\n} catch (e) {\n  if (e.message.includes(\"BBAI_LITELLM_KEY is missing\")) {\n    return { error: \"Budibase AI is not configured in this environment\" }\n  }\n  throw e\n}","preventionTips":["Add BBAI_LITELLM_KEY to server AND worker env files/docker-compose services","Add a startup health check that fails fast when the key is absent","Document the variable in deployment runbooks for self-hosted installs"],"tags":["configuration","environment-variable","budibase-ai","litellm"],"backgroundTag":"missing-env-var","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}