langchain - 💡(How to fix) Fix Feature Request: WhichModel integration for cost-optimized model selection [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36566Fetched 2026-04-08 03:01:04
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Participants
Timeline (top)
closed ×1commented ×1labeled ×1

WhichModel (https://whichmodel.dev) is an MCP server that helps AI agents choose the right LLM for every task at the best price. It tracks pricing and capabilities across 100+ models with 4-hour refresh cycles.

A LangChain integration could enable automatic model routing based on:

  • Task complexity (simple Q&A vs. complex reasoning)
  • Budget constraints (cost per token)
  • Required capabilities (vision, tool use, long context)

MCP Tools available:

  • recommend_model — get the best model for a task and budget
  • compare_models — side-by-side model comparison
  • get_pricing — current pricing for any model
  • check_price_changes — recent price changes across providers

Repo: https://github.com/Which-Model/whichmodel-mcp

Root Cause

WhichModel (https://whichmodel.dev) is an MCP server that helps AI agents choose the right LLM for every task at the best price. It tracks pricing and capabilities across 100+ models with 4-hour refresh cycles.

A LangChain integration could enable automatic model routing based on:

  • Task complexity (simple Q&A vs. complex reasoning)
  • Budget constraints (cost per token)
  • Required capabilities (vision, tool use, long context)

MCP Tools available:

  • recommend_model — get the best model for a task and budget
  • compare_models — side-by-side model comparison
  • get_pricing — current pricing for any model
  • check_price_changes — recent price changes across providers

Repo: https://github.com/Which-Model/whichmodel-mcp

Fix Action

Fix / Workaround

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Code Example

# Proposed integration with WhichModel for automatic model routing
from langchain_core.language_models import BaseChatModel

# WhichModel MCP endpoint: https://whichmodel.dev/mcp
# Returns cost-optimized model recommendations based on task type, budget, and requirements
RAW_BUFFERClick to expand / collapse

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

# Proposed integration with WhichModel for automatic model routing
from langchain_core.language_models import BaseChatModel

# WhichModel MCP endpoint: https://whichmodel.dev/mcp
# Returns cost-optimized model recommendations based on task type, budget, and requirements

Description

WhichModel (https://whichmodel.dev) is an MCP server that helps AI agents choose the right LLM for every task at the best price. It tracks pricing and capabilities across 100+ models with 4-hour refresh cycles.

A LangChain integration could enable automatic model routing based on:

  • Task complexity (simple Q&A vs. complex reasoning)
  • Budget constraints (cost per token)
  • Required capabilities (vision, tool use, long context)

MCP Tools available:

  • recommend_model — get the best model for a task and budget
  • compare_models — side-by-side model comparison
  • get_pricing — current pricing for any model
  • check_price_changes — recent price changes across providers

Repo: https://github.com/Which-Model/whichmodel-mcp

System Info

N/A — this is a feature request for a new integration.

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

extent analysis

TL;DR

To integrate WhichModel with LangChain for automatic model routing, create a new class that inherits from BaseChatModel and utilizes the WhichModel MCP endpoint to select the optimal model based on task requirements and budget.

Guidance

  • Review the WhichModel MCP endpoint documentation to understand the available tools and their usage, such as recommend_model and get_pricing.
  • Design a new class that extends BaseChatModel to incorporate the WhichModel integration, allowing for dynamic model selection based on task complexity, budget, and required capabilities.
  • Investigate how to handle errors and exceptions that may occur during the model selection process, such as network errors or invalid responses from the WhichModel MCP endpoint.
  • Consider implementing a caching mechanism to store the results of recent model recommendations to reduce the number of requests to the WhichModel MCP endpoint.

Example

from langchain_core.language_models import BaseChatModel
import requests

class WhichModelChatModel(BaseChatModel):
    def __init__(self, task_type, budget, requirements):
        self.task_type = task_type
        self.budget = budget
        self.requirements = requirements
        self.model = self.select_model()

    def select_model(self):
        response = requests.post("https://whichmodel.dev/mcp/recommend_model", json={
            "task_type": self.task_type,
            "budget": self.budget,
            "requirements": self.requirements
        })
        return response.json()["recommended_model"]

Notes

The implementation details of the WhichModel integration will depend on the specific requirements of the LangChain project and the WhichModel MCP endpoint. This example provides a basic starting point, but additional error handling and caching mechanisms may be necessary.

Recommendation

Apply workaround: Implement a custom solution using the WhichModel MCP endpoint to select the optimal model for each task, as there is no existing integration available in LangChain.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - 💡(How to fix) Fix Feature Request: WhichModel integration for cost-optimized model selection [1 comments, 2 participants]