[PR #649] serve: expose context_length and max_output_tokens on /v1/models for generic client discovery #648

Open
opened 2026-10-29 21:27:54 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/649
Author: @NorwinYu
Created: 10/29/2026
Status: 🔄 Open

Base: main ← Head: models-listing-capacities


📝 Commits (1)

  • 3c7b64b serve: list context_length and max_output_tokens on /v1/models for generic client discovery

📊 Changes

2 files changed (+7 additions, -0 deletions)

View changed files

📝 serve/server.py (+5 -0)
📝 serve/test_server.py (+2 -0)

📄 Description

Summary

The GET /v1/models (and /models) endpoint reports a model's context size only under meta.n_ctx. Common OpenAI-compatible clients that discover model capacities from the model listing read different, de-facto-standard field names on each entry, and never read meta.n_ctx. As a result such clients fall back to a hard-coded default for an unknown model. Concretely, DeepSeek Harness (its pi-ai model discovery, used for self-hosted routes) reads context_length / max_input_tokens for the context window and max_output_tokens for the output cap, and assumes a 262144-token window when neither is present.

This change adds the two standard names to each model entry, alongside the existing meta.n_ctx (kept for backwards compatibility). It is a server JSON-shape change only: no engine, sampling, or GPU behaviour is affected.

What changed

In serve/server.py, each /v1/models and /models entry now also carries:

  • context_length — the engine's max_context (the combined request + response limit the engine enforces);
  • max_output_tokens — the same value. Maya has no separate, lower fixed output cap: generation is clamped to max_context by the engine, so the output ceiling is the context window itself.

meta.n_ctx is unchanged.

Measured

GET /v1/models before:

{"id":"deepseek-v4.1-flash","object":"model","status":{"value":"loaded"},
 "meta":{"n_ctx":131072},
 "architecture":{"input_modalities":["text","image"],"output_modalities":["text"]}}

after:

{"id":"deepseek-v4.1-flash","object":"model","status":{"value":"loaded"},
 "meta":{"n_ctx":131072},
 "context_length":131072,
 "max_output_tokens":131072,
 "architecture":{"input_modalities":["text","image"],"output_modalities":["text"]}}

Testing

  • serve/test_server.py: extended the /v1/models and /models assertions to cover the two new fields; the full server suite passes (101 tests OK).
  • python tools/check_hip_compat.py passes — no CUDA names were added or changed.
  • python -m unittest discover -s tools -p 'test_*.py' passes (407 tests OK, 28 skipped; cmake must be on PATH for the HIP-arch tests).

Compatibility

  • Additive only: existing clients that read meta.n_ctx are unaffected.
  • No new configuration, no environment variables, no documentation changes required.

🔄 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/mw00/project-maya/pull/649 **Author:** [@NorwinYu](https://github.com/NorwinYu) **Created:** 10/29/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `models-listing-capacities` --- ### 📝 Commits (1) - [`3c7b64b`](https://github.com/mw00/project-maya/commit/3c7b64b7669a359a6fbae7ca4a3d07f23ca885c9) serve: list context_length and max_output_tokens on /v1/models for generic client discovery ### 📊 Changes **2 files changed** (+7 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+5 -0) 📝 `serve/test_server.py` (+2 -0) </details> ### 📄 Description ## Summary The `GET /v1/models` (and `/models`) endpoint reports a model's context size only under `meta.n_ctx`. Common OpenAI-compatible clients that discover model capacities from the model listing read different, de-facto-standard field names on each entry, and never read `meta.n_ctx`. As a result such clients fall back to a hard-coded default for an unknown model. Concretely, DeepSeek Harness (its `pi-ai` model discovery, used for self-hosted routes) reads `context_length` / `max_input_tokens` for the context window and `max_output_tokens` for the output cap, and assumes a 262144-token window when neither is present. This change adds the two standard names to each model entry, alongside the existing `meta.n_ctx` (kept for backwards compatibility). It is a server JSON-shape change only: no engine, sampling, or GPU behaviour is affected. ## What changed In `serve/server.py`, each `/v1/models` and `/models` entry now also carries: - `context_length` — the engine's `max_context` (the combined request + response limit the engine enforces); - `max_output_tokens` — the same value. Maya has no separate, lower fixed output cap: generation is clamped to `max_context` by the engine, so the output ceiling is the context window itself. `meta.n_ctx` is unchanged. ## Measured `GET /v1/models` before: ```json {"id":"deepseek-v4.1-flash","object":"model","status":{"value":"loaded"}, "meta":{"n_ctx":131072}, "architecture":{"input_modalities":["text","image"],"output_modalities":["text"]}} ``` after: ```json {"id":"deepseek-v4.1-flash","object":"model","status":{"value":"loaded"}, "meta":{"n_ctx":131072}, "context_length":131072, "max_output_tokens":131072, "architecture":{"input_modalities":["text","image"],"output_modalities":["text"]}} ``` ## Testing - `serve/test_server.py`: extended the `/v1/models` and `/models` assertions to cover the two new fields; the full server suite passes (101 tests OK). - `python tools/check_hip_compat.py` passes — no CUDA names were added or changed. - `python -m unittest discover -s tools -p 'test_*.py'` passes (407 tests OK, 28 skipped; `cmake` must be on `PATH` for the HIP-arch tests). ## Compatibility - Additive only: existing clients that read `meta.n_ctx` are unaffected. - No new configuration, no environment variables, no documentation changes required. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mw00/project-maya#648
No description provided.