{"record":{"id":"4f911ab131487ed8","repo":"BerriAI/litellm","slug":"missing-keys-missing-keys-in-environment-4f911a","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/openmeter.py","lineNumber":49,"sourceCode":"        super().__init__()\n        self.validate_environment()\n        self.async_http_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.LoggingCallback)\n        self.sync_http_handler = HTTPHandler()\n\n    def validate_environment(self):\n        \"\"\"\n        Expects\n        OPENMETER_API_ENDPOINT,\n        OPENMETER_API_KEY,\n\n        in the environment\n        \"\"\"\n        missing_keys: Final = []\n        if os.getenv(\"OPENMETER_API_KEY\", None) is None:\n            missing_keys.append(\"OPENMETER_API_KEY\")\n\n        if len(missing_keys) > 0:\n            raise Exception(f\"Missing keys={missing_keys} in environment.\")\n\n    def _common_logic(self, kwargs: dict, response_obj):\n        call_id: Final = response_obj.get(\"id\", kwargs.get(\"litellm_call_id\"))\n        dt: Final = get_utc_datetime().isoformat()\n        cost: Final = kwargs.get(\"response_cost\", None)\n        model: Final = kwargs.get(\"model\")\n        usage = {}\n        if (\n            isinstance(response_obj, litellm.ModelResponse) or isinstance(response_obj, litellm.EmbeddingResponse)\n        ) and hasattr(response_obj, \"usage\"):\n            usage = {\n                \"prompt_tokens\": response_obj[\"usage\"].get(\"prompt_tokens\", 0),\n                \"completion_tokens\": response_obj[\"usage\"].get(\"completion_tokens\", 0),\n                \"total_tokens\": response_obj[\"usage\"].get(\"total_tokens\"),\n            }\n\n        # OPENMETER_TRUST_REQUEST_USER (default \"true\"): when set to \"false\",\n        # the request-supplied `user` field is ignored and the subject is","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/integrations/openmeter.py#L31-L67","documentation":"OpenMeterLogger.__init__ checks that OPENMETER_API_KEY exists in the environment (the docstring mentions OPENMETER_API_ENDPOINT too, but only the key is enforced) and raises with the list of missing keys. Events are CloudEvents POSTed to OpenMeter's /api/v1/events with a Bearer token, so without the key the logger cannot authenticate.","triggerScenarios":"Adding 'openmeter' to success callbacks without exporting OPENMETER_API_KEY; key defined in a .env file not loaded by the process; key set to an empty string.","commonSituations":"Proxy deployments enabling OpenMeter usage metering while secrets live in a vault not wired to env vars; local dev copying config from docs without the secrets block.","solutions":["export OPENMETER_API_KEY=<OpenMeter key> in the litellm process environment","Optionally set OPENMETER_API_ENDPOINT if not using the default https://openmeter.cloud","Verify inside the container: 'env | grep OPENMETER'","Drop the openmeter callback if usage metering to OpenMeter is not intended"],"exampleFix":"# before\nlitellm.success_callback = [\"openmeter\"]  # Exception: Missing keys=['OPENMETER_API_KEY']\n\n# after\nimport os\nos.environ[\"OPENMETER_API_KEY\"] = \"om-...\"\nlitellm.success_callback = [\"openmeter\"]","handlingStrategy":"validation","validationCode":"import os\n\nif not os.getenv(\"OPENMETER_API_KEY\"):\n    raise RuntimeError(\"OPENMETER_API_KEY required before enabling the openmeter callback\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate env vars in a startup gate for every enabled callback","Keep callback list and required secrets in the same config unit"],"tags":["python","openmeter","environment","configuration","usage-tracking"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}