[PR #5075] [CLOSED] feat: add configurable sampling parameters for OpenRouter models #5290

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

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5075
Author: @angelplusultra
Created: 2/26/2026
Status: Closed

Base: masterHead: 3506-feat-parameters-for-openrouter-models


📝 Commits (7)

  • 5430cf1 add provider level OpenRouter parameters
  • b85c8c4 format
  • cd2ba91 add new openrouter variables to .env.example
  • 1f9bbaf Changed all 9 numeric defaultValue expressions to use nullish coalescing (??) instead of logical OR (||), so explicit 0 values display correctly in the UI
  • 1773a10 created server/utils/AiProviders/openRouter/openRouterModelParams.js with two exported functions and applied them in both openrouter providers
  • 2c82deb fix import path
  • 76c15cf Merge branch 'master' into 3506-feat-parameters-for-openrouter-models

📊 Changes

7 files changed (+302 additions, -15 deletions)

View changed files

📝 frontend/src/components/LLMSelection/OpenRouterOptions/index.jsx (+166 -15)
📝 server/.env.example (+10 -0)
📝 server/models/systemSettings.js (+9 -0)
📝 server/utils/AiProviders/openRouter/index.js (+12 -0)
server/utils/AiProviders/openRouter/openRouterModelParams.js (+57 -0)
📝 server/utils/agents/aibitat/providers/openrouter.js (+12 -0)
📝 server/utils/helpers/updateENV.js (+36 -0)

📄 Description

Pull Request Type

  • feat (New feature)

Relevant Issues

resolves #3506

Description

Adds configurable model sampling parameters for OpenRouter models at the provider level (ENV). This allows users to tune parameters like max_tokens, top_p, repetition_penalty, etc. — which is especially useful for models like QwQ 32B that can get stuck in loops without proper parameter tuning.

9 new parameters supported:

  • max_tokens — Max output tokens
  • top_p — Nucleus sampling (0-1)
  • top_k — Top-k sampling
  • min_p — Minimum probability sampling (0-1)
  • frequency_penalty — Frequency penalty (-2 to 2)
  • presence_penalty — Presence penalty (-2 to 2)
  • repetition_penalty — Repetition penalty (0-2, OpenRouter-specific)
  • top_a — Top-A sampling (0-1)
  • seed — Deterministic sampling seed

All parameters are optional — when left empty, OpenRouter uses its own model-specific defaults. Parameters are configured under Settings → LLM Preference → OpenRouter → Advanced Controls.

Files changed:

  • server/utils/helpers/updateENV.js — ENV key mappings
  • server/models/systemSettings.js — Expose settings to frontend
  • server/utils/AiProviders/openRouter/index.js — Pass params to chat/stream API calls
  • server/utils/AiProviders/openRouter/openRouterModelParams.js — Shared parameter parsing/building helper
  • server/utils/agents/aibitat/providers/openrouter.js — Pass params to agent API calls
  • frontend/src/components/LLMSelection/OpenRouterOptions/index.jsx — UI inputs in Advanced Controls

Visuals (if applicable)

image

Additional Information

  • Parameters apply globally at the provider level (ENV), not per-workspace.
  • Unset parameters are omitted from API calls entirely (not sent as 0/null), so OpenRouter's defaults are preserved.
  • Both the main chat provider and the agent provider respect these parameters.
  • Parameter parsing and API object building are extracted into a shared helper (openRouterModelParams.js) to avoid duplication between the chat provider and agent provider.
  • Frontend inputs use nullish coalescing (??) instead of logical OR (||) for defaultValue so that explicit 0 values (e.g. frequency_penalty=0) display correctly.

Developer Validations

  • I ran yarn lint from the root of the repo & committed changes
  • I have tested my code functionality

🔄 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/5075 **Author:** [@angelplusultra](https://github.com/angelplusultra) **Created:** 2/26/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `3506-feat-parameters-for-openrouter-models` --- ### 📝 Commits (7) - [`5430cf1`](https://github.com/Mintplex-Labs/anything-llm/commit/5430cf145ff0329898f19dd3f29b8b4631b151b3) add provider level OpenRouter parameters - [`b85c8c4`](https://github.com/Mintplex-Labs/anything-llm/commit/b85c8c4468bf3d445585eff62972539cf3fa66f1) format - [`cd2ba91`](https://github.com/Mintplex-Labs/anything-llm/commit/cd2ba91ff9af17230484c1d2b2666f432156b113) add new openrouter variables to .env.example - [`1f9bbaf`](https://github.com/Mintplex-Labs/anything-llm/commit/1f9bbafe74d6ead3861b4a97117bedb2ada3e56c) Changed all 9 numeric defaultValue expressions to use nullish coalescing (??) instead of logical OR (||), so explicit 0 values display correctly in the UI - [`1773a10`](https://github.com/Mintplex-Labs/anything-llm/commit/1773a10c2f519a71fde6aed146af7cb50f70a7c7) created server/utils/AiProviders/openRouter/openRouterModelParams.js with two exported functions and applied them in both openrouter providers - [`2c82deb`](https://github.com/Mintplex-Labs/anything-llm/commit/2c82deb720fda72f8bda20b5be45f38bdc0a2ca5) fix import path - [`76c15cf`](https://github.com/Mintplex-Labs/anything-llm/commit/76c15cfc1544ce6f048b0e0184029d85194a8bdd) Merge branch 'master' into 3506-feat-parameters-for-openrouter-models ### 📊 Changes **7 files changed** (+302 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `frontend/src/components/LLMSelection/OpenRouterOptions/index.jsx` (+166 -15) 📝 `server/.env.example` (+10 -0) 📝 `server/models/systemSettings.js` (+9 -0) 📝 `server/utils/AiProviders/openRouter/index.js` (+12 -0) ➕ `server/utils/AiProviders/openRouter/openRouterModelParams.js` (+57 -0) 📝 `server/utils/agents/aibitat/providers/openrouter.js` (+12 -0) 📝 `server/utils/helpers/updateENV.js` (+36 -0) </details> ### 📄 Description ### Pull Request Type - [x] ✨ feat (New feature) ### Relevant Issues resolves #3506 ### Description Adds configurable model sampling parameters for OpenRouter models at the provider level (ENV). This allows users to tune parameters like `max_tokens`, `top_p`, `repetition_penalty`, etc. — which is especially useful for models like QwQ 32B that can get stuck in loops without proper parameter tuning. **9 new parameters supported:** - `max_tokens` — Max output tokens - `top_p` — Nucleus sampling (0-1) - `top_k` — Top-k sampling - `min_p` — Minimum probability sampling (0-1) - `frequency_penalty` — Frequency penalty (-2 to 2) - `presence_penalty` — Presence penalty (-2 to 2) - `repetition_penalty` — Repetition penalty (0-2, OpenRouter-specific) - `top_a` — Top-A sampling (0-1) - `seed` — Deterministic sampling seed All parameters are optional — when left empty, OpenRouter uses its own model-specific defaults. Parameters are configured under **Settings → LLM Preference → OpenRouter → Advanced Controls**. **Files changed:** - `server/utils/helpers/updateENV.js` — ENV key mappings - `server/models/systemSettings.js` — Expose settings to frontend - `server/utils/AiProviders/openRouter/index.js` — Pass params to chat/stream API calls - `server/utils/AiProviders/openRouter/openRouterModelParams.js` — Shared parameter parsing/building helper - `server/utils/agents/aibitat/providers/openrouter.js` — Pass params to agent API calls - `frontend/src/components/LLMSelection/OpenRouterOptions/index.jsx` — UI inputs in Advanced Controls ### Visuals (if applicable) <img width="1261" height="1390" alt="image" src="https://github.com/user-attachments/assets/68b79a0d-df6e-4893-898d-0c1986f97484" /> ### Additional Information - Parameters apply globally at the provider level (ENV), not per-workspace. - Unset parameters are omitted from API calls entirely (not sent as 0/null), so OpenRouter's defaults are preserved. - Both the main chat provider and the agent provider respect these parameters. - Parameter parsing and API object building are extracted into a shared helper (`openRouterModelParams.js`) to avoid duplication between the chat provider and agent provider. - Frontend inputs use nullish coalescing (`??`) instead of logical OR (`||`) for `defaultValue` so that explicit `0` values (e.g. `frequency_penalty=0`) display correctly. ### Developer Validations - [x] I ran `yarn lint` from the root of the repo & committed changes - [x] I have tested my code functionality --- <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:52 -04:00
yindo closed this issue 2026-06-05 15:20:52 -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#5290