Skip to content

Conversation

@waldekmastykarz
Copy link
Collaborator

Adds OpenAIUsageDebuggingPlugin. Closes #1413

@waldekmastykarz waldekmastykarz requested a review from a team as a code owner October 25, 2025 11:04
Copilot AI review requested due to automatic review settings October 25, 2025 11:04
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new OpenAIUsageDebuggingPlugin that tracks and logs OpenAI API usage metrics to a CSV file, while refactoring shared utility code from OpenAITelemetryPlugin into reusable components.

  • Extracts TryGetOpenAIRequest, IsStreamingResponse, and GetBodyFromStreamingResponse to shared utilities
  • Implements OpenAIUsageDebuggingPlugin to record token usage, rate limits, and error details to CSV
  • Adds PromptTokenDetails model to capture cached token metrics

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
DevProxy.Plugins/Utils/HttpUtils.cs New utility class containing shared HTTP response handling methods for streaming responses
DevProxy.Plugins/Inspection/OpenAIUsageDebuggingPlugin.cs New plugin that logs OpenAI API usage metrics (tokens, rate limits, errors) to CSV files
DevProxy.Plugins/Inspection/OpenAITelemetryPlugin.cs Refactored to use shared utilities from HttpUtils and OpenAIRequest
DevProxy.Abstractions/LanguageModel/OpenAIModels.cs Added TryGetOpenAIRequest static method and PromptTokenDetails class for cached token tracking

garrytrinder
garrytrinder previously approved these changes Oct 28, 2025
- Use DateTime.TryParse for the response Date header and fall back to DateTime.Now when missing/invalid.
- Extract TryParseHeaderAsLong helper to centralize/parsing of numeric headers.
- Replace inline parsing for x-ratelimit-remaining-tokens and x-ratelimit-remaining-requests with the new helper.
- Add missing using for Titanium.Web.Proxy.Http.
@waldekmastykarz waldekmastykarz merged commit daace7f into dotnet:main Oct 28, 2025
4 checks passed
@waldekmastykarz waldekmastykarz deleted the llmusagedebug branch October 28, 2025 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create an LLM usage debug plugin

2 participants