BerriAI/litellm · error · Exception

Missing keys={missing_keys} in environment.

Error message

Missing keys={missing_keys} in environment.

What it means

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.

Source

Thrown at litellm/integrations/openmeter.py:49

        super().__init__()
        self.validate_environment()
        self.async_http_handler = get_async_httpx_client(llm_provider=httpxSpecialProvider.LoggingCallback)
        self.sync_http_handler = HTTPHandler()

    def validate_environment(self):
        """
        Expects
        OPENMETER_API_ENDPOINT,
        OPENMETER_API_KEY,

        in the environment
        """
        missing_keys: Final = []
        if os.getenv("OPENMETER_API_KEY", None) is None:
            missing_keys.append("OPENMETER_API_KEY")

        if len(missing_keys) > 0:
            raise Exception(f"Missing keys={missing_keys} in environment.")

    def _common_logic(self, kwargs: dict, response_obj):
        call_id: Final = response_obj.get("id", kwargs.get("litellm_call_id"))
        dt: Final = get_utc_datetime().isoformat()
        cost: Final = kwargs.get("response_cost", None)
        model: Final = kwargs.get("model")
        usage = {}
        if (
            isinstance(response_obj, litellm.ModelResponse) or isinstance(response_obj, litellm.EmbeddingResponse)
        ) and hasattr(response_obj, "usage"):
            usage = {
                "prompt_tokens": response_obj["usage"].get("prompt_tokens", 0),
                "completion_tokens": response_obj["usage"].get("completion_tokens", 0),
                "total_tokens": response_obj["usage"].get("total_tokens"),
            }

        # OPENMETER_TRUST_REQUEST_USER (default "true"): when set to "false",
        # the request-supplied `user` field is ignored and the subject is

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. export OPENMETER_API_KEY=<OpenMeter key> in the litellm process environment
  2. Optionally set OPENMETER_API_ENDPOINT if not using the default https://openmeter.cloud
  3. Verify inside the container: 'env | grep OPENMETER'
  4. Drop the openmeter callback if usage metering to OpenMeter is not intended

Example fix

# before
litellm.success_callback = ["openmeter"]  # Exception: Missing keys=['OPENMETER_API_KEY']

# after
import os
os.environ["OPENMETER_API_KEY"] = "om-..."
litellm.success_callback = ["openmeter"]
Defensive patterns

Strategy: validation

Validate before calling

import os

if not os.getenv("OPENMETER_API_KEY"):
    raise RuntimeError("OPENMETER_API_KEY required before enabling the openmeter callback")

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/4f911ab131487ed8. Report an issue: GitHub.