Skip to content

Conversation

llm-net
Copy link

@llm-net llm-net commented Aug 11, 2025

Description

This PR adds support for the max_model_len field in the router's /v1/models endpoint.

Problem

The vLLM backend returns max_model_len (context window size) in its /v1/models response, but the router was not forwarding this field. This made it impossible to know the context window size of models through the router API.

Solution

  • Added max_model_len field to ModelInfo dataclass in service_discovery.py
  • Added max_model_len field to ModelCard in protocols.py
  • Updated main_router.py to pass max_model_len when creating ModelCard

Testing

Tested with a deployment running Qwen3-235B model which has a context window of 131072 tokens.

Before this change:

{
  "id": "Qwen/Qwen3-235B-A22B-Thinking-2507-FP8",
  "object": "model",
  "created": 1754905632,
  "owned_by": "vllm",
  "root": null,
  "parent": null
}

After this change (expected):

{
  "id": "Qwen/Qwen3-235B-A22B-Thinking-2507-FP8",
  "object": "model",
  "created": 1754905632,
  "owned_by": "vllm",
  "root": null,
  "parent": null,
  "max_model_len": 131072
}

This makes the router fully compatible with vLLM's extended OpenAI API format.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @llm-net, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've implemented support for the max_model_len field within the router's /v1/models endpoint. Previously, while the vLLM backend provided this crucial context window size information, the router was not forwarding it, making it impossible for clients to determine a model's context capabilities via the router's API. My changes ensure that this max_model_len value is now properly propagated and exposed, making the router fully compatible with vLLM's extended OpenAI API format and providing complete model information to consumers.

Highlights

  • ModelInfo Update: I've added the max_model_len field to the ModelInfo dataclass, which is used internally for service discovery.
  • ModelCard Enhancement: I've included the max_model_len field in the ModelCard dataclass, which defines the structure for model information exposed via the API.
  • Router Logic Adjustment: I've updated the main router logic to ensure that the max_model_len value, retrieved from the backend, is correctly passed through and included when constructing the ModelCard for the /v1/models endpoint.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adds support for the max_model_len field, propagating it from the service discovery layer to the /v1/models API endpoint. The changes are well-implemented. My feedback includes suggestions to add a unit test to cover this new functionality and to extend support for this field to the StaticServiceDiscovery for feature consistency.

created=model_info.created,
owned_by=model_info.owned_by,
parent=model_info.parent,
max_model_len=model_info.max_model_len,
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change correctly passes the max_model_len to the ModelCard. To ensure this functionality is robust and to prevent future regressions, it would be beneficial to add a unit test for the /v1/models endpoint. The test should verify that when a model's ModelInfo includes a max_model_len, this value is correctly included in the API response.

root: Optional[str] = None
parent: Optional[str] = None
is_adapter: bool = False
max_model_len: Optional[int] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While max_model_len is correctly added to ModelInfo and populated for Kubernetes-based service discovery, StaticServiceDiscovery currently has no mechanism to configure this value; it will always default to None. To ensure feature parity across discovery methods, consider enhancing StaticServiceDiscovery to allow static configuration of max_model_len for each model. This could be done by adding a max_model_lens list to its constructor, similar to how urls and models are handled.

…lity

- Added max_model_len field to ModelInfo dataclass in service_discovery.py
- Added max_model_len field to ModelCard in protocols.py
- Updated main_router.py to pass max_model_len when creating ModelCard
- This allows the router to properly forward the max_model_len field from vLLM endpoints

This fixes the issue where /v1/models endpoint was not showing the context window size for models.

Signed-off-by: llm-net <[email protected]>
@llm-net llm-net force-pushed the fix-max-model-len branch from 00ead58 to 2f2be41 Compare August 11, 2025 10:09
@llm-net llm-net force-pushed the fix-max-model-len branch from 2f2be41 to 0a7e331 Compare August 11, 2025 17:34
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.

1 participant