Skip to content

feat: expose richer model metadata in v1/models#721

Merged
doringeman merged 2 commits intodocker:mainfrom
VedantMadane:feat/rich-model-metadata
Mar 27, 2026
Merged

feat: expose richer model metadata in v1/models#721
doringeman merged 2 commits intodocker:mainfrom
VedantMadane:feat/rich-model-metadata

Conversation

@VedantMadane
Copy link
Copy Markdown
Contributor

Fixes #143.

This PR expands the model schema returned by the /v1/models\ endpoint to include additional metadata about each model, similar to what other providers like OpenRouter expose.

New fields added to OpenAIModel:

  • \context_window: Maximum context length supported by the model.
  • \�rchitecture: Technical architecture of the model.
  • \parameters: Description of model parameters.
  • \quantization: Quantization method used.
  • \size: Parameter size (e.g., " 8B).

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
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 enhances the /v1/models endpoint by including additional metadata for each model, such as context window size and architecture. The changes look good, but I've found a critical issue where the code could panic if a model's configuration is missing. I've provided a suggestion to handle this case gracefully.

Comment on lines 85 to 105
config, err := m.Config()
if err != nil {
return nil, fmt.Errorf("get config: %w", err)
}

var contextWindow int32
if cw := config.GetContextSize(); cw != nil {
contextWindow = *cw
}

return &OpenAIModel{
ID: id,
Object: "model",
Created: created,
OwnedBy: "docker",
ID: id,
Object: "model",
Created: created,
OwnedBy: "docker",
ContextWindow: contextWindow,
Architecture: config.GetArchitecture(),
Parameters: config.GetParameters(),
Quantization: config.GetQuantization(),
Size: config.GetSize(),
}, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The m.Config() method can return a nil config with a nil error. If this happens, the subsequent calls to methods on config (e.g., config.GetContextSize() on line 91) will cause a nil pointer dereference, leading to a panic. You should add a check to handle the case where config is nil.

 	config, err := m.Config()
 	if err != nil {
 		return nil, fmt.Errorf("get config: %w", err)
 	}

 	if config == nil {
 		// If there's no config, return the model with only basic info.
 		return &OpenAIModel{
 			ID:      id,
 			Object:  "model",
 			Created: created,
 			OwnedBy: "docker",
 		}, nil
 	}

 	var contextWindow int32
 	if cw := config.GetContextSize(); cw != nil {
 		contextWindow = *cw
 	}

 	return &OpenAIModel{
 		ID:            id,
 		Object:        "model",
 		Created:       created,
 		OwnedBy:       "docker",
 		ContextWindow: contextWindow,
 		Architecture:  config.GetArchitecture(),
 		Parameters:    config.GetParameters(),
 		Quantization:  config.GetQuantization(),
 		Size:          config.GetSize(),
 	}, nil

@doringeman
Copy link
Copy Markdown
Contributor

Hey @VedantMadane, why do you need this?
This API you've modified corresponds with the official List models.
Isn't /models what you're looking for? E.g., curl -s http://localhost:12434/models | jq .

@VedantMadane
Copy link
Copy Markdown
Contributor Author

Hi @doringeman, good question! The /engines/llama.cpp/v1/models endpoint (OpenAI-compatible List Models) currently returns only id and object fields, while the /models endpoint returns more details but in a non-standard format.

This PR enriches the OpenAI-compatible response with metadata fields like architecture, parameters, quantization, context_window, and size — so consumers using the standard OpenAI SDK can access model capabilities without needing a separate non-standard call.

The idea is to keep the interface OpenAI-compatible while exposing the richer metadata that Docker Model Runner already has.

@ericcurtin
Copy link
Copy Markdown
Contributor

ericcurtin commented Mar 21, 2026

Missing unit tests for new fields, ContextWindow should be *int32 for proper omitempty behavior.

@doringeman
Copy link
Copy Markdown
Contributor

Hey @VedantMadane , WDYT about adding all the new extra fields under a common field called "dmr"?
E.g.,

{
  "id": "VAR_chat_model_id",
  "object": "model",
  "created": 1686935002,
  "owned_by": "openai",
  "dmr": {
     "custom-field":"custom-vaalue"
   }
}

Fixes docker#143

Enrich the OpenAI-compatible /v1/models response with Docker Model
Runner-specific metadata nested under a `dmr` field, keeping the
response OpenAI-compatible while exposing richer model capabilities.

New `dmr` object fields:
- context_window (*int32, omitempty)
- architecture
- parameters
- quantization
- size

Addresses review feedback:
- Nest metadata under `dmr` per @doringeman suggestion
- Use *int32 for context_window for proper omitempty per @ericcurtin
- Guard against nil config per @gemini-code-assist
- Add unit tests for ToOpenAI and ToOpenAIList

Signed-off-by: Vedant Madane <6527493+VedantMadane@users.noreply.github.com>
@VedantMadane VedantMadane force-pushed the feat/rich-model-metadata branch from c442bd1 to ebb47fd Compare March 25, 2026 19:03
Copy link
Copy Markdown
Contributor

@doringeman doringeman left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 🙌

Signed-off-by: Dorin Geman <dorin.geman@docker.com>
@doringeman doringeman merged commit 660346c into docker:main Mar 27, 2026
6 of 7 checks passed
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.

Enhancement: Expose richer model metadata in /engines/v1/models (similar to OpenRouter)

3 participants