Skip to content

serve: one model by name (GET /v1/models/{model}), Ollama's /api/tags and /api/show, and a 404 that names the request - #994

Merged
juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-models-api
Oct 30, 2026
Merged

juliankang4 merged 1 commit into
midagedev:mainfrom
juliankang4:dgx-spark-q38-usab-models-api

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

모델 이름 하나를 조회하는 API와 Ollama 클라이언트용 /api/tags, /api/show를 더하고, 없는 경로의 404가 요청한 method와 path를 말하게 했습니다.

What and why

Clients that talk to the server by model name need to ask for one model, and Ollama clients read /api/tags and /api/show to learn what is served. This adds GET /v1/models/{model} (and /models/{model}), which returns that model's /v1/models entry or a 404 that names the model being served. GET /api/tags returns the /v1/models listing. POST /api/show takes {"model": NAME} and returns the template, the file's format, architecture and quantization, the served context length, and the capabilities (completion, plus tools and vision when the server supports them). A side embedding model reports embedding only. The decision server answers /api/tags and the lookup, not /api/show. A request to an unknown path now gets a 404 that starts with File Not Found: <METHOD> <path> before the existing SystemOne hint. The new routes need the API key like /v1/models. Ollama's generation endpoints are not added.

Release notes: Added: GET /v1/models/{model}, /api/tags and /api/show on the server, and a 404 that names the requested method and path.

Code shape

  • No second copy. The listing owner in crates/serve/src/models.rs gained the lookup (named, lookup) and both servers call it. Request::not_found() in http.rs is the one 404 head for both servers and the stored responses.
  • Model code holds only architecture facts. No model file changed.
  • Dead code is gone. Nothing was made unused.
  • No silent failure. An unknown model is a 404 that names the served model, a missing or non-string model in /api/show is a 400.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line), or "none": none.

What I ran

Tests on the head: cargo test -p bloomery-serve --lib gave test result: ok. 431 passed; 0 failed, including models::tests::one_model_is_looked_up_by_its_id, api::tests::show_names_the_files_facts_and_capabilities, api::embeddings::tests::discovery_names_the_seated_models, decide::tests::the_routes_are_the_deciders_and_no_other and decide::tests::not_supported_is_501_and_the_models_are_listed. The whole serve suite including the --test serve -- --include-ignored integration tests passed with test result: ok. 111 passed; 0 failed.

The new discovery_names_the_seated_models fails on base (left: 404, right: 200 at /api/tags) and passes with the change.

Real binary on one NVIDIA GB10 (driver 595.84, CUDA 13.3, sm_121a), bloomery-serve 0.3.11 built with release features, serving the existing Qwen3.8 FP4-Local folder:

./target/release/bloomery-serve -m <Qwen3.8-Flash-Next-FP4-Local folder> --host 127.0.0.1 --port 18742 --ctx-size 2048
curl -s localhost:18742/v1/models
curl -s localhost:18742/api/tags
curl -s localhost:18742/v1/models/qwen3.8
curl -s localhost:18742/models/qwen3.8
curl -s localhost:18742/v1/models/nope
curl -s -d '{"model": "qwen3.8"}' localhost:18742/api/show
curl -s -d '{"model": "nope"}' localhost:18742/api/show
curl -s localhost:18742/api/nope
HTTP GET /v1/models  -> 200 {"models": [{"name": "qwen3.8", "model": "qwen3.8"}], "object": "list", "data": [{"id": "qwen3.8", ... "max_model_len": 2048}]}
HTTP GET /api/tags  -> 200 (same body as /v1/models)
HTTP GET /v1/models/qwen3.8  -> 200 {"id": "qwen3.8", "object": "model", ... "max_model_len": 2048}
HTTP GET /models/qwen3.8  -> 200 (same entry)
HTTP GET /v1/models/nope  -> 404 {"error": {"code": 404, "message": "model \"nope\" not found: this server serves qwen3.8", "type": "not_found_error"}}
HTTP POST /api/show {"model": "qwen3.8"} -> 200
HTTP POST /api/show {"model": "nope"} -> 404 (same message)
HTTP GET /api/nope  -> 404 {"error": {"code": 404, "message": "File Not Found: GET /api/nope; POST /v1/systemone answers a SystemOne decision request", "type": "not_found_error"}}
HTTP POST /v1/chat/completions -> 200
MODELS-API PASS

The run checked that /api/show returns general.architecture, that <arch>.context_length equals max_model_len (2048), that details.family equals the architecture, that capabilities contains completion, and that template is not empty.

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

@github-actions github-actions Bot added documentation Improvements or additions to documentation serve The HTTP server: crates/serve labels Oct 30, 2026

@github-actions github-actions Bot left a comment

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.

Verdict: MUST_FIX: model lookup confuses URL encoding with literal model names.

Must fix

1. Decode model names at the URL boundary

Kind A: crates/serve/src/models.rs:60 checks raw text first. With chat ID m/a and side-model ID m%2Fa, GET /v1/models/m%2Fa returns the side model instead of the URL-encoded chat model. The new assertion at line 126 pins this error.
crates/serve/src/api.rs:2406 passes JSON names through the same decoder: serving only mock, POST /api/show with {"model":"%6dock"} returns 200 instead of the promised unknown-model 404.
Cost: separating these representations now avoids changing published lookup behavior later.

Fix: decode once in named; keep lookup exact. Replace their definitions and update their comments accordingly. Point the decoder's doc link at named:

pub(crate) fn named(path: &str) -> Option<Result<String, String>> {
    crate::http::below(path, "models").map(|id| {
        crate::http::percent_decode(&id.replace('+', "%2B"))
            .map_err(|_| format!("invalid percent-encoded model name: {id:?}"))
    })
}
pub(crate) fn lookup(listing: &Value, id: &str) -> Result<Value, String> {
    let data = listing["data"].as_array().map_or(&[][..], Vec::as_slice);
    data.iter()
        .find(|m| m["id"] == id)
        .cloned()
        .ok_or_else(|| {
            let served: Vec<&str> = data.iter().filter_map(|m| m["id"].as_str()).collect();
            format!(
                "model {id:?} not found: this server serves {}",
                served.join(", ")
            )
        })
}

Replace the named-model arm in api::route:

("GET", p) if let Some(id) = crate::models::named(p) => {
    id.map_err(invalid).and_then(|id| {
        crate::models::lookup(&models(state), &id).map_err(not_found)
    })
}

Replace that arm in decide::reply:

("GET", p) if let Some(id) = crate::models::named(p) => {
    match id {
        Ok(id) => match crate::models::lookup(&s.fixed.models, &id) {
            Ok(entry) => Reply::json(200, &entry),
            Err(message) => Reply::error(404, "not_found_error", &message),
        },
        Err(message) => Reply::error(400, "invalid_request_error", &message),
    }
}

Update named expectations to Some(Ok(String)); unwrap it before looking up encoded paths. For the existing two-ID fixture, replace its collision assertion with:

let id = named("/v1/models/m%2Fa").unwrap().unwrap();
assert_eq!(lookup(&v, &id).unwrap(), v["data"][0]);
let id = named("/v1/models/m%252Fa").unwrap().unwrap();
assert_eq!(lookup(&v, &id).unwrap(), v["data"][1]);
assert_eq!(lookup(&v, "m%2Fa").unwrap(), v["data"][1]);

Extend the existing discovery test to require 404 for JSON {"model":"%6dock"}.

Checked

Duplicates: 17 new items checked; no duplicate owner found. The dryer pair, invalid/not_found, represents different HTTP errors.
Complexity: api::route rose 29 → 31 through new dispatch branches; lookup remains owned by models.
Silent failure: 3 lookup fallback/drop sites followed. Listing shape and ID types come from listing; decoding errors are discarded by the defect above.
Tests, static mutation analysis: disabling decoded matching at models.rs:63 fails the model-lookup assertions; dropping fields/capabilities at api.rs:2412–2425 fails the show test; dropping discovery arms at api.rs:1641–1645 or decide.rs:560–565 fails the two discovery tests; dropping request text at decide.rs:592 fails the decision-route test. The collision assertion currently requires the wrong result.
Gates: no thresholds or pins moved.
Escape catalog: no C1–C4 patterns matched. Authentication precedes dispatch; stored-response prefix behavior is preserved. No inference hot path changed.

Notes

Rust tests were not run; mutation results are source analysis.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4
juliankang4 force-pushed the dgx-spark-q38-usab-models-api branch from 471a5a4 to b0a49cf Compare October 30, 2026 02:04

@github-actions github-actions Bot left a comment

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.

Since the last review: the earlier URL/JSON model-name finding is fixed. models.rs:49 decodes URL names once; lookup matches JSON names literally.

Verdict: CLEAN: the revised lookup resolves the earlier failure, and no new must-fix finding survives.

Checked

Duplicates: 0 new definitions in the interdiff; changed lookup reuses the existing decoder. The dryer pair, invalid/not_found, represents different HTTP errors.
Complexity: crapper flagged decide::reply (9 → 14) and api::route (29 → 31). Existing dispatch functions gained route/error branches; model matching remains in the common owner.
Silent failure: 2 decoder-error paths followed; both return 400. Unknown literal model names return 404.
Tests (static mutation analysis): removing or repeating decoding at models.rs:51 breaks the model collision assertions; dropping literal-plus preservation breaks the plus assertions. Adding decoding at models.rs:60 breaks the literal-lookup and discovery assertions. Returning 404 for decoding errors at api.rs:1643 or decide.rs:566 breaks the two route tests.
Gates: no thresholds, pins or test cases removed or relaxed.
Escape catalog: no C1–C4 patterns matched.
Adversarial checks: encoded-name collisions, malformed escapes and invalid UTF-8 are handled; double-encoded names and literal plus signs preserve identity. No inference hot path changed.

Notes

Rust tests were not run. Mutation results are source analysis.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

… and /api/show, and a 404 that names the request

GET /v1/models/{model} (and /models/{model}) answers the listing's entry of that name, taken as sent or percent-decoded, on the generative and decision servers alike; a name the server does not serve is a 404 not_found_error naming the ones it does. GET /api/tags answers the /v1/models list, whose models array is Ollama's shape, as llama-server served it. POST /api/show answers the chat model's template, the file's format, architecture and quant, the served context as <arch>.context_length and its capabilities (completion, tools when the template's markup is one the server parses, vision with an image encoder); the embedding model answers embedding.

A route the server does not have was answered with the SystemOne route alone; its 404 now starts with the method and path the request named, then the route that note gave.
@juliankang4
juliankang4 force-pushed the dgx-spark-q38-usab-models-api branch from b0a49cf to 4fc7275 Compare October 30, 2026 03:23

@github-actions github-actions Bot left a comment

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.

Verdict: CLEAN: carried from b0a49cfa, not re-reviewed.

The approval of b0a49cfa stands for 4fc72752. This pull request's 1 commit are the same patches in the same order: git patch-id --verbatim (the changed lines, the lines around them and whitespace) and the subject are equal for every commit. That review ran under the reviewer instructions, tools and slag ledger that review this head, and it approved.

The base moved, and changed none of the files this pull request changes.

A carry covers each patch's own lines and the lines around them. What the base changed elsewhere is covered by CI on this head and by the landing gates.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 5585b26 into midagedev:main Oct 30, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation serve The HTTP server: crates/serve

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant