Skip to content

Conversation

@roomote
Copy link
Collaborator

@roomote roomote commented Jun 30, 2025

Summary

This PR addresses issue #5144 by adding comprehensive test coverage for OpenRouter's upstream_inference_cost functionality.

Changes

  • Added test for BYOK cost calculation using upstream_inference_cost
  • Added test for graceful handling of missing upstream_inference_cost
  • Added test for reasoning tokens support
  • Verified cached token display functionality

Investigation Results

Upon investigation, I found that the OpenRouter implementation was already correctly using upstream_inference_cost in the cost calculation (line 171 in src/api/providers/openrouter.ts):

totalCost: (lastUsage.cost_details?.upstream_inference_cost || 0) + (lastUsage.cost || 0),

The implementation also properly handles cached tokens:

cacheReadTokens: lastUsage.prompt_tokens_details?.cached_tokens,

Testing

All tests pass, confirming the existing implementation correctly:

  • Uses upstream_inference_cost for BYOK cost calculation
  • Falls back gracefully when upstream_inference_cost is missing
  • Displays cached tokens properly
  • Supports reasoning tokens

The issue appears to have been resolved in a previous change, and this PR adds the missing test coverage to ensure the functionality is properly validated.

Fixes #5144


Important

Adds comprehensive test coverage for upstream_inference_cost in OpenRouterHandler, ensuring correct cost calculation and token handling.

  • Tests Added:
    • upstream_inference_cost for BYOK cost calculation in openrouter.spec.ts.
    • Graceful handling of missing upstream_inference_cost in openrouter.spec.ts.
    • Support for reasoning tokens in openrouter.spec.ts.
    • Verification of cached token display in openrouter.spec.ts.
  • Implementation Verification:
    • Confirmed upstream_inference_cost is used correctly in cost calculation.
    • Confirmed cached tokens are handled properly.
  • Misc:
    • All tests pass, confirming correct functionality.

This description was created by Ellipsis for 098ca59. You can customize this summary. It will automatically update as commits are pushed.

…inference_cost

- Added test for BYOK cost calculation using upstream_inference_cost
- Added test for graceful handling of missing upstream_inference_cost
- Added test for reasoning tokens support
- Verified cached token display functionality
- All tests pass, confirming existing implementation correctly uses upstream_inference_cost
@roomote roomote requested review from cte, jr and mrubens as code owners June 30, 2025 08:22
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 30, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jun 30, 2025

No security or compliance issues detected. Reviewed everything up to 098ca59.

Security Overview
  • 🔎 Scanned files: 1 changed file(s)
Detected Code Changes

The diff is too large to display a summary of code changes.

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 30, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jul 7, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Use upstream_inference_cost for OpenRouter BYOK cost calculation

3 participants