[Feature] Expose `max_model_len` (session_len) in `/v1/models` model card
Maintainers usually reply within 2 days
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
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/modelscard (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 readsmax_model_len/context_lengthoff 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):
serve/openai/protocol.py: addmax_model_len: int | None = Noneto
ModelCard(optional field → absent from serialization when unset, cards
stay OpenAI-clean otherwise).serve/openai/endpoints/models.py: populate it from the server context's
server_config.session_lenwhen 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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InternLM/lmdeploy
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
[Bug] apply_rotary_pos_emb: leaves output tails unwritten with partial rotationPossibly taken @shotsan claimed this 15 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
[Bug] PyTorch engine ignores use_rslora, so rsLoRA adapters run sqrt(r) times too weakPossibly taken @Andreas-Hum claimed this 26 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 2 days
All issues in InternLM/lmdeploy
Similar issues
-
accepted
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
future-agi/future-agi#5908 ·
Maintainers usually reply within 1 day
-
Placeholder export disables HTML image input for picture descriptionPossibly taken @cloudiful claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
docling-project/docling-serve#817 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
Parse truncated verbose GC logs up to the first XML errorPossibly taken A pull request linked to this issue is open or already merged. Openbug verbose GC
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
IBM/javacore-analyser#677 ·
Maintainers usually reply within 1 day
-
Prefix list view Location filter only shows Locations whose Location Type allows VLANs, not Prefixes.Possibly taken @swanandtambe claimed this today. Opentriage type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Maintainers usually reply within 1 day