[PR #5113] [CLOSED] Patch OpenRouter finish_reason bug #5304

Closed
opened 2026-06-05 15:20:54 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5113
Author: @shatfield4
Created: 3/2/2026
Status: Closed

Base: masterHead: 5112-bug-openrouter-failed-message-bug


📝 Commits (3)

  • 349b13d add guard clause to patch OpenRouter finish_reason bug
  • 51383f9 use real usage data from OpenRouter for stream metrics
  • a3721d7 lint

📊 Changes

1 file changed (+18 additions, -5 deletions)

View changed files

📝 server/utils/AiProviders/openRouter/index.js (+18 -5)

📄 Description

Pull Request Type

  • feat (New feature)
  • 🐛 fix (Bug fix)
  • ♻️ refactor (Code refactoring without changing behavior)
  • 💄 style (UI style changes)
  • 🔨 chore (Build, CI, maintenance)
  • 📝 docs (Documentation updates)

Relevant Issues

resolves #5112

Description

  • OpenRouter recently started sending a trailing stream chunk with an empty choices array containing usage data
  • This caused a crash (Cannot read properties of undefined (reading 'finish_reason')) because the code didn't account for chunks without choices
  • Added guard against chunks with no message to prevent last chunk from throwing an error
  • Store the real usage data given to us by OpenRouter and use this in TPS calculations done in endMeasurement for more accurate results

Visuals (if applicable)

Additional Information

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5113 **Author:** [@shatfield4](https://github.com/shatfield4) **Created:** 3/2/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `5112-bug-openrouter-failed-message-bug` --- ### 📝 Commits (3) - [`349b13d`](https://github.com/Mintplex-Labs/anything-llm/commit/349b13dc1db21539c6347bf3a0b7f04303975acd) add guard clause to patch OpenRouter finish_reason bug - [`51383f9`](https://github.com/Mintplex-Labs/anything-llm/commit/51383f9bb1053fece69dd9ec5df63b4fa1a07939) use real usage data from OpenRouter for stream metrics - [`a3721d7`](https://github.com/Mintplex-Labs/anything-llm/commit/a3721d7c46c3255657cc8fbcd66df3c87507db9b) lint ### 📊 Changes **1 file changed** (+18 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `server/utils/AiProviders/openRouter/index.js` (+18 -5) </details> ### 📄 Description ### Pull Request Type <!-- For change type, change [ ] to [x]. --> - [ ] ✨ feat (New feature) - [x] 🐛 fix (Bug fix) - [ ] ♻️ refactor (Code refactoring without changing behavior) - [ ] 💄 style (UI style changes) - [ ] 🔨 chore (Build, CI, maintenance) - [ ] 📝 docs (Documentation updates) ### Relevant Issues <!-- Use "resolves #xxx" to auto resolve on merge. Otherwise, please use "connect #xxx" --> resolves #5112 ### Description <!-- Describe the changes in this PR that are impactful to the repo. What problem does it solve? --> - OpenRouter recently started sending a trailing stream chunk with an empty choices array containing usage data - This caused a crash (Cannot read properties of undefined (reading 'finish_reason')) because the code didn't account for chunks without choices - Added guard against chunks with no message to prevent last chunk from throwing an error - Store the real usage data given to us by OpenRouter and use this in TPS calculations done in `endMeasurement` for more accurate results ### Visuals (if applicable) <!-- Add screenshots or screen recordings to demonstrate the changes, especially for UI updates. --> ### Additional Information <!-- Add any other context about the Pull Request here that was not captured above. --> ### Developer Validations <!-- All of the applicable items should be checked. --> - [x] I ran `yarn lint` from the root of the repo & committed changes - [x] Relevant documentation has been updated (if applicable) - [x] I have tested my code functionality - [x] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:20:54 -04:00
yindo closed this issue 2026-06-05 15:20:54 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5304