[Feature] Expose `max_model_len` (session_len) in `/v1/models` model card

Open Beginner friendly
#5,063 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

@FOWEPJF255 is already working on this.

Since Oct 27, 2026.

  • #5072 by @FOWEPJF255 — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api

Research direction

The issue names both files: add an optional max_model_len field to ModelCard in serve/openai/protocol.py, then populate it from server_config.session_len where cards are built in serve/openai/endpoints/models.py. Start by reading those two files and how the server context exposes the config. Done means GET /v1/models returns max_model_len matching the startup session_len while remaining absent-compatible for other clients; existing endpoint tests are the place to verify.

Written by the indexing model from the issue text.

Description

Motivation

Problem

GET /v1/models currently returns the bare OpenAI-compatible model card
(id / object / created / owned_by / root / parent / permission). It carries
no information about the served model's context window, so clients that rely
on the models endpoint for capability discovery (agentic clients, context
compaction logic, LLM gateways doing auto-discovery) cannot learn the engine's
real serving limit and have to hardcode it.

The limit is known to the server — it is exactly ServerConfig.session_len
passed at startup — but it is not surfaced on any HTTP endpoint today
(session_len only appears internally, e.g. when constructing the Prometheus
stat logger in serve/core/async_engine.py).

Prior art (de-facto standard)

  • vLLM already emits "max_model_len": <int> as an extra field on the
    /v1/models card (e.g. {"id": "...", "owned_by": "vllm", "max_model_len": 262144, ...}).
    Many gateway/proxy integrations (e.g. LiteLLM's model-info discovery since
    v1.103, which reads max_model_len / context_length off upstream cards)
    have converged on reading these fields from OpenAI-compatible backends.
  • SGLang likewise reports context length metadata.

Because LMDeploy's card omits it, an LMDeploy backend looks "limitless"
(unknown) through such gateways even though the server knows the number.

Proposed change

Small and additive (no behavior change for existing clients):

  1. serve/openai/protocol.py: add max_model_len: int | None = None to
    ModelCard (optional field → absent from serialization when unset, cards
    stay OpenAI-clean otherwise).
  2. serve/openai/endpoints/models.py: populate it from the server context's
    server_config.session_len when building each card.

Happy to send a PR if the field name/placement is agreed (max_model_len
recommended for wire-compat with vLLM; context_length as an alias if
preferred).

Environment

  • LMDeploy 0.18.0 (also checked current main: endpoints/models.py
    unchanged, still 7-field card).
  • Observed response (TurboMind backend):
{
  "object": "list",
  "data": [
    {
      "id": "...", "object": "model", "created": ..., "owned_by": "lmdeploy",
      "root": "...", "parent": null,
      "permission": [ { "id": "modelperm-...", "...": "..." } ]
    }
  ]
}
Related resources

No response

Additional context

No response

Dominant language
Python
Stars
8.2k
Forks
797
Avg merge
3d 15h
Merged PRs (30d)
52

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from InternLM/lmdeploy

All issues in InternLM/lmdeploy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.