Skip to content

[Bug]: OpenMeter integration fails due to incorrect CloudEvent subject field format #7569

@enricobellato

Description

@enricobellato

What happened?

The openmeter integration doesn't work correctly, the cloudevent subject field transmitted by litellm is invalid and the openmeter server throws a status code 400.

The cloudEvent config on the openmeter end is configured correctly (as shown in the official openmeter docs), as demonstrated by the following test curl that runs successfully:

curl -X POST https://openmeter.cloud/api/v1/events \
  -H 'Content-Type: application/cloudevents+json' \
  -H 'Authorization: Bearer <OPENMETER_PLACEHOLDER_API_KEY>' \
  --data-raw '
  {
    "specversion" : "1.0",
    "type": "litellm_tokens",
    "id": "3ed4f15f-8dcf-45cb-8ec3-0922f5a67ab7",
    "time": "2025-01-05T10:15:57.783Z",
    "source": "my-app",
    "subject": "customer-1",
    "data": {
      "completion_tokens": "123",
      "cost": "cost",
      "model": "model",
      "prompt_tokens": "prompt_tokens",
      "total_tokens": "total_tokens"
    }
  }
'

The problem appears to be in the extraction of the user field inside the openmeter code:

subject = (kwargs.get("user", None),) # end-user passed in via 'user' param

where the user OpenAI spec field is extracted and used as the subject for the cloudevent event.

Thanks for the great project!

Relevant log output

litellm-1                   | {"message": "LiteLLM.LoggingError: [Non-Blocking] Exception occurred while success logging Traceback (most recent call last):\n  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/openmeter.py\", line 124, in async_log_success_event\n    await self.async_http_handler.post(\n    ...<3 lines>...\n    )\n  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/custom_httpx/http_handler.py\", line 219, in post\n    raise e\n  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/custom_httpx/http_handler.py\", line 177, in post\n    response.raise_for_status()\n    ~~~~~~~~~~~~~~~~~~~~~~~~~^^\n  File \"/usr/local/lib/python3.13/site-packages/httpx/_models.py\", line 761, in raise_for_status\n    raise HTTPStatusError(message, request=request, response=self)\nhttpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://openmeter.cloud/api/v1/events'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/litellm_logging.py\", line 1602, in async_success_handler\n    await callback.async_log_success_event(\n    ...<6 lines>...\n    )\n  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/openmeter.py\", line 130, in async_log_success_event\n    raise Exception(f\"OpenMeter logging error: {e.response.text}\")\nException: OpenMeter logging error: {\"type\":\"about:blank\",\"title\":\"Bad Request\",\"status\":400,\"detail\":\"request body has an error: doesn't match schema #/components/schemas/Event: Error at \\\"/subject\\\": value must be a string\"}\n\n", "level": "ERROR", "timestamp": "2025-01-05T03:36:32.704192"}

Are you a ML Ops Team?

No

What LiteLLM version are you on ?

v1.56.9

Twitter / LinkedIn details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions