{"record":{"id":"4fe974558ca41cf2","repo":"BerriAI/litellm","slug":"missing-keys-missing-keys-in-environment","errorCode":null,"errorMessage":"Missing keys={missing_keys} in environment.","messagePattern":"Missing keys=(.+?) in environment\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/integrations/braintrust_logging.py","lineNumber":67,"sourceCode":"            \"Content-Type\": \"application/json\",\n        }\n        self._project_id_cache: dict[str, str] = {}  # Cache mapping project names to IDs\n        self.global_braintrust_http_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.LoggingCallback)\n        self.global_braintrust_sync_http_handler = HTTPHandler()\n\n    def validate_environment(self, api_key: str | None):\n        \"\"\"\n        Expects\n        BRAINTRUST_API_KEY\n\n        in the environment\n        \"\"\"\n        missing_keys: Final = []\n        if api_key is None and os.getenv(\"BRAINTRUST_API_KEY\", None) is None:\n            missing_keys.append(\"BRAINTRUST_API_KEY\")\n\n        if len(missing_keys) > 0:\n            raise Exception(f\"Missing keys={missing_keys} in environment.\")\n\n    def get_project_id_sync(self, project_name: str) -> str:\n        \"\"\"\n        Get project ID from name, using cache if available.\n        If project doesn't exist, creates it.\n        \"\"\"\n        if project_name in self._project_id_cache:\n            return self._project_id_cache[project_name]\n\n        try:\n            response: Final = self.global_braintrust_sync_http_handler.post(\n                f\"{self.api_base}/project\",\n                headers=self.headers,\n                json={\"name\": project_name},\n            )\n            project_dict: Final = response.json()\n            project_id: Final = project_dict[\"id\"]\n            self._project_id_cache[project_name] = project_id","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/braintrust_logging.py#L49-L85","documentation":"Raised by BraintrustLogger.validate_environment when neither an explicit api_key argument nor the BRAINTRUST_API_KEY environment variable is present. LiteLLM custom logging integrations are constructed at proxy startup, so this usually surfaces as a crash or logged error during initialization of the braintrust callback rather than per-request.","triggerScenarios":"Enabling the braintrust callback in litellm_settings.callbacks without exporting BRAINTRUST_API_KEY; running in a container/CI where the env var is not injected; passing api_key=None explicitly and relying solely on the environment.","commonSituations":"Docker/Kubernetes secrets not wired into the proxy container; .env file not loaded in the deployment; env var name typo (e.g. BRAINTRUST_KEY); disabling braintrust locally but the callback config leaked into shared config.","solutions":["Export BRAINTRUST_API_KEY in the environment where the LiteLLM proxy starts: export BRAINTRUST_API_KEY=...","In Docker/K8s, inject it via env or envFrom secret reference so the proxy process sees it","Verify with printenv | grep BRAINTRUST inside the exact container that runs the proxy","If braintrust logging is not intended, remove it from litellm_settings.callbacks / success_callback config"],"exampleFix":"# before\nlitellm_settings:\n  callbacks: [braintrust]  # container starts without BRAINTRUST_API_KEY\n\n# after\ndocker run --env BRAINTRUST_API_KEY=$BRAINTRUST_API_KEY ... ghcr.io/berriai/litellm:latest --config /app/config.yaml","handlingStrategy":"validation","validationCode":"import os\n\ndef braintrust_ready() -> bool:\n    return bool(os.getenv(\"BRAINTRUST_API_KEY\"))\n\nif \"braintrust\" in callbacks and not braintrust_ready():\n    raise RuntimeError(\"braintrust callback enabled but BRAINTRUST_API_KEY missing\")","typeGuard":null,"tryCatchPattern":"try:\n    logger = BraintrustLogger(...)\nexcept Exception as e:\n    if \"Missing keys\" in str(e):\n        raise RuntimeError(\"Set BRAINTRUST_API_KEY before enabling the braintrust callback\") from e\n    raise","preventionTips":["Fail fast at startup when callbacks are enabled without their env vars","Wire secrets via container env/envFrom, not baked images","Document required env vars per callback in the deployment checklist"],"tags":["braintrust","environment-variables","observability","configuration"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}