serve: /v1/models/:id answers the model object, not a list of one

OpenAI's retrieve returns the entry itself, and its SDK reads `id` off the top level, where
the list of one this route answered before has none. /v1/models still answers the list.
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-08 15:57:51 +02:00
1 parent 86128c2e75
commit 3a3345951f
6 files changed
+65 -22

No files matched your search

+13 -5
View File
@@ -2205,19 +2205,27 @@ std::string embeddings_body(const OaiRequest& r, const std::vector<std::vector<f
return o.dump();
}
std::string models_body(const std::string& model_id, int64_t created, int64_t max_model_len) {
static json model_card(const ModelCard& c) {
json m;
m["id"] = model_id;
m["id"] = c.id;
m["object"] = "model";
m["created"] = created;
m["created"] = c.created;
m["owned_by"] = "radiance";
if (max_model_len > 0) m["max_model_len"] = max_model_len;
if (c.max_model_len > 0) m["max_model_len"] = c.max_model_len;
return m;
}
std::string models_body(const ModelCard& c) {
json o;
o["object"] = "list";
o["data"] = json::array({m});
o["data"] = json::array({model_card(c)});
return o.dump();
}
std::string model_body(const ModelCard& c) {
return model_card(c).dump();
}
/* ================================================================== SSE */
std::string sse_event(const std::string& json_text) {
+17 -7
View File
@@ -318,13 +318,23 @@ std::string text_completion_body(const OaiRequest& r, const std::vector<ChoiceOu
const UsageOut& u, const TimingsOut& t = TimingsOut());
std::string embeddings_body(const OaiRequest& r, const std::vector<std::vector<float>>& vecs,
const UsageOut& u);
/* `max_model_len` is the context the server was started with (--max-model-len, else the
* container's trained length), the field vLLM's model card carries. Clients size their own
* context from it -- an agent that compresses its history at the window's edge, a UI that shows
* how much is left -- and without it they guess from the model's name, which is wrong whenever the
* deployment sets its own length. 0 leaves the field out rather than reporting a length the
* server does not know. */
std::string models_body(const std::string& model_id, int64_t created, int64_t max_model_len = 0);
/* ONE MODEL ENTRY: what /v1/models lists and /v1/models/:id returns on its own. */
struct ModelCard {
std::string id;
int64_t created = 0;
/* The context the server was started with (--max-model-len, else the container's trained
* length), the field vLLM's model card carries. Clients size their own context from it -- an
* agent that compresses its history at the window's edge, a UI that shows how much is left --
* and without it they guess from the model's name, which is wrong whenever the deployment sets
* its own length. 0 leaves the field out rather than reporting a length the server does not
* know. */
int64_t max_model_len = 0;
};
/* The list, for GET /v1/models. */
std::string models_body(const ModelCard& m);
/* The entry itself, for GET /v1/models/:id: OpenAI's retrieve answers the model object, not a
* list of one, and its SDK reads `id` off the top level. */
std::string model_body(const ModelCard& m);
/* The usage chunk of each endpoint's stream: an SSE event whose choices array is empty and whose
* only payload is `usage`. Emitted when the request asked for stream_options.include_usage, ONCE
+5 -1
View File
@@ -1153,8 +1153,12 @@ HttpResponse Server::handle_models(const HttpRequest& req) {
e.message = "no such model: " + id;
return error_response(e, req.peer);
}
ModelCard c;
c.id = opt_.model_id;
c.created = started_at_;
c.max_model_len = opt_.max_ctx;
metrics_.observe_http(200);
return HttpResponse::json_body(200, models_body(opt_.model_id, started_at_, opt_.max_ctx));
return HttpResponse::json_body(200, id.empty() ? models_body(c) : model_body(c));
}
HttpResponse Server::handle_metrics(const HttpRequest&) {