Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
enricobellato opened this issue Jan 5, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@enricobellato
Copy link

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

@enricobellato enricobellato added the bug Something isn't working label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant