Skip to main content

ramvamp_server/
response.rs

1//! `/v1/chat/completions` response shapes, streaming and not, plus the
2//! `/v1/models` and `/health` bodies.
3//!
4//! The shapes are OpenAI's to the byte, including the parts that look
5//! redundant. `object` is a literal discriminant some clients switch on;
6//! `finish_reason` is serialized as `null` on non-final chunks rather than
7//! omitted, because a client that reads `choices[0].finish_reason` positionally
8//! sees a missing key as a malformed chunk. Where a field is genuinely optional
9//! (`usage` on a chunk, `tool_calls` on a delta) it is omitted, which is what
10//! OpenAI's own stream does for at least one of them and no client objects to.
11//!
12//! Nothing here reads a clock or a random source: `id` and `created` are
13//! parameters. That keeps the crate free of I/O and every assertion below
14//! deterministic — a test can pin the exact bytes of a chunk, which is the only
15//! way to pin a streaming contract.
16
17use serde::{Deserialize, Serialize};
18
19/// The `object` discriminant of a non-streaming completion.
20pub const OBJECT_CHAT_COMPLETION: &str = "chat.completion";
21
22/// The prefix every completion id carries.
23///
24/// Lives here rather than at the mint site because it is also *read*: a call
25/// id is derived from the completion id with this stripped off (see
26/// [`crate::toolcall::call_id`]), and the two must not drift apart.
27pub const COMPLETION_ID_PREFIX: &str = "chatcmpl-";
28
29/// The `object` discriminant of a streaming chunk.
30pub const OBJECT_CHAT_COMPLETION_CHUNK: &str = "chat.completion.chunk";
31
32/// The `object` discriminant of a list body.
33pub const OBJECT_LIST: &str = "list";
34
35/// The `object` discriminant of a model card.
36pub const OBJECT_MODEL: &str = "model";
37
38/// Why generation stopped, in OpenAI's vocabulary.
39#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
40#[serde(rename_all = "snake_case")]
41pub enum FinishReason {
42    /// A stop token or stop sequence ended the reply.
43    Stop,
44    /// The token budget ran out.
45    Length,
46    /// The model asked to call a tool.
47    ToolCalls,
48    /// Output was withheld. Never produced by this build; present because the
49    /// value round-trips through client-side transcripts.
50    ContentFilter,
51}
52
53/// Token accounting for one request.
54#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
55pub struct Usage {
56    /// Tokens prefilled, including the ChatML markers this server adds.
57    pub prompt_tokens: u32,
58    /// Tokens generated, stop token excluded.
59    pub completion_tokens: u32,
60    /// Their sum.
61    pub total_tokens: u32,
62}
63
64impl Usage {
65    /// Usage with the total derived, so the three numbers cannot disagree.
66    ///
67    /// Saturating rather than wrapping: an implausible count should report an
68    /// implausible total, never a small one.
69    pub fn new(prompt_tokens: u32, completion_tokens: u32) -> Self {
70        Usage {
71            prompt_tokens,
72            completion_tokens,
73            total_tokens: prompt_tokens.saturating_add(completion_tokens),
74        }
75    }
76}
77
78/// The assistant message of a non-streaming completion.
79#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
80pub struct ResponseMessage {
81    /// Always `assistant`.
82    pub role: String,
83    /// The reply text.
84    pub content: Option<String>,
85    /// Calls the model requested. Omitted when there are none.
86    #[serde(default, skip_serializing_if = "Option::is_none")]
87    pub tool_calls: Option<Vec<crate::request::ToolCall>>,
88}
89
90impl ResponseMessage {
91    /// An assistant message carrying `content`.
92    pub fn assistant(content: impl Into<String>) -> Self {
93        ResponseMessage::calling(content, Vec::new())
94    }
95
96    /// An assistant message carrying `content` and the calls it asked for.
97    ///
98    /// No calls means the key is omitted rather than serialized as `[]`:
99    /// clients branch on the field being *present*, and an empty array reads
100    /// to some of them as "this turn wants tools" — which then waits forever
101    /// for a `tool` message that is never coming.
102    ///
103    /// `content` stays a `Some`, empty string included, rather than becoming
104    /// `null` on a pure tool-call turn. Both are legal and clients accept
105    /// either; the empty string is the one that cannot be rendered as the
106    /// literal text `None` by a client that formats it naively.
107    pub fn calling(content: impl Into<String>, tool_calls: Vec<crate::request::ToolCall>) -> Self {
108        ResponseMessage {
109            role: crate::request::MessageRole::Assistant.as_str().to_owned(),
110            content: Some(content.into()),
111            tool_calls: (!tool_calls.is_empty()).then_some(tool_calls),
112        }
113    }
114}
115
116/// One choice of a non-streaming completion.
117#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
118pub struct Choice {
119    /// Position in `choices`. Always 0 here: `n > 1` is refused.
120    pub index: u32,
121    /// The reply.
122    pub message: ResponseMessage,
123    /// Why it ended.
124    pub finish_reason: Option<FinishReason>,
125}
126
127/// A non-streaming `chat.completion`.
128#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
129pub struct ChatCompletion {
130    /// Completion id, conventionally `chatcmpl-...`.
131    pub id: String,
132    /// Always [`OBJECT_CHAT_COMPLETION`].
133    pub object: String,
134    /// Unix seconds.
135    pub created: u64,
136    /// The model name the client asked for, echoed back.
137    pub model: String,
138    /// Exactly one choice.
139    pub choices: Vec<Choice>,
140    /// Token accounting.
141    pub usage: Usage,
142}
143
144impl ChatCompletion {
145    /// The single-choice completion this server always returns.
146    pub fn single(
147        id: impl Into<String>,
148        created: u64,
149        model: impl Into<String>,
150        content: impl Into<String>,
151        finish_reason: FinishReason,
152        usage: Usage,
153    ) -> Self {
154        ChatCompletion::from_message(
155            id,
156            created,
157            model,
158            ResponseMessage::assistant(content),
159            finish_reason,
160            usage,
161        )
162    }
163
164    /// The same, around a message that was assembled elsewhere — a reply that
165    /// carries tool calls, whose content and calls come out of one parse.
166    pub fn from_message(
167        id: impl Into<String>,
168        created: u64,
169        model: impl Into<String>,
170        message: ResponseMessage,
171        finish_reason: FinishReason,
172        usage: Usage,
173    ) -> Self {
174        ChatCompletion {
175            id: id.into(),
176            object: OBJECT_CHAT_COMPLETION.to_owned(),
177            created,
178            model: model.into(),
179            choices: vec![Choice {
180                index: 0,
181                message,
182                finish_reason: Some(finish_reason),
183            }],
184            usage,
185        }
186    }
187}
188
189/// One entry of a streaming `tool_calls` delta.
190///
191/// OpenAI fragments this shape across many deltas — it streams `arguments` as
192/// the model generates them, so a client is handed a name, then argument text
193/// in pieces, and reassembles them by `index`. This server has the whole block
194/// buffered before it recognises it as a call at all (see
195/// [`crate::toolcall::CallStream`]), so every field is filled on the one delta
196/// the call produces. A client that assembles fragments handles a complete
197/// entry as the trivial case of the same rule.
198///
199/// `index` is therefore the one field that is not decoration: it is how a
200/// client knows which call an entry belongs to, and two calls in one turn are
201/// indistinguishable without it.
202#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
203pub struct ToolCallDelta {
204    /// Position in this response's `tool_calls`.
205    pub index: u32,
206    /// The call id, matched by the `tool` message's `tool_call_id`. Minted by
207    /// [`crate::toolcall::wire_call`], the same function the buffered path
208    /// uses, so both paths name the same call identically.
209    pub id: String,
210    /// Always `function`.
211    #[serde(rename = "type")]
212    pub kind: String,
213    /// Name and arguments, complete.
214    pub function: crate::request::FunctionCall,
215}
216
217/// The incremental half of a streaming choice.
218///
219/// Every field is optional and every absent field is omitted, which is what
220/// makes the four chunk shapes distinguishable on the wire: `{"role":...,
221/// "content":""}`, `{"content":"..."}`, `{"tool_calls":[...]}`, and `{}`.
222#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
223pub struct Delta {
224    /// Sent once, on the first chunk.
225    #[serde(default, skip_serializing_if = "Option::is_none")]
226    pub role: Option<String>,
227    /// A slice of the reply.
228    #[serde(default, skip_serializing_if = "Option::is_none")]
229    pub content: Option<String>,
230    /// Calls the model asked for, one entry per call. Omitted rather than
231    /// empty: a client branches on the key being present.
232    #[serde(default, skip_serializing_if = "Option::is_none")]
233    pub tool_calls: Option<Vec<ToolCallDelta>>,
234}
235
236/// One choice of a streaming chunk.
237#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
238pub struct ChunkChoice {
239    /// Always 0.
240    pub index: u32,
241    /// What changed.
242    pub delta: Delta,
243    /// `null` until the final chunk. Serialized even when null: a client
244    /// reading the key positionally treats an absent one as a broken chunk.
245    pub finish_reason: Option<FinishReason>,
246}
247
248/// A streaming `chat.completion.chunk`.
249#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
250pub struct ChatCompletionChunk {
251    /// Same id for every chunk of one response.
252    pub id: String,
253    /// Always [`OBJECT_CHAT_COMPLETION_CHUNK`].
254    pub object: String,
255    /// Unix seconds, same for every chunk of one response.
256    pub created: u64,
257    /// The model name the client asked for.
258    pub model: String,
259    /// One choice, or none at all on the usage chunk.
260    pub choices: Vec<ChunkChoice>,
261    /// Present only on the usage chunk.
262    #[serde(default, skip_serializing_if = "Option::is_none")]
263    pub usage: Option<Usage>,
264}
265
266/// Builds the chunks of one streaming response.
267///
268/// Holds the fields that must be identical across every chunk (`id`,
269/// `created`, `model`) so they cannot drift, and names the four chunk shapes
270/// so the emission order is readable at the call site:
271///
272/// 1. [`role`](Self::role) — `delta: {"role":"assistant","content":""}`
273/// 2. [`content`](Self::content) — `delta: {"content":"..."}`, repeated
274/// 3. [`tool_call`](Self::tool_call) — `delta: {"tool_calls":[...]}`, once per
275///    call the model asked for, interleaved with the content
276/// 4. [`usage`](Self::usage) — `choices: []` plus `usage`, only when
277///    `stream_options.include_usage` was set, and immediately *before* the
278///    sentinel rather than after: a client stops reading at `[DONE]`, so usage
279///    emitted after it is usage nobody receives
280/// 5. [`finish`](Self::finish) — `delta: {}` plus `finish_reason`
281///
282/// The order on the wire is 1, (2|3)*, 5, 4?, then `data: [DONE]`.
283#[derive(Debug, Clone)]
284pub struct ChunkBuilder {
285    id: String,
286    created: u64,
287    model: String,
288}
289
290impl ChunkBuilder {
291    /// A builder for the response identified by `id`.
292    pub fn new(id: impl Into<String>, created: u64, model: impl Into<String>) -> Self {
293        ChunkBuilder {
294            id: id.into(),
295            created,
296            model: model.into(),
297        }
298    }
299
300    /// The completion id every chunk carries.
301    pub fn id(&self) -> &str {
302        &self.id
303    }
304
305    fn chunk(&self, choices: Vec<ChunkChoice>, usage: Option<Usage>) -> ChatCompletionChunk {
306        ChatCompletionChunk {
307            id: self.id.clone(),
308            object: OBJECT_CHAT_COMPLETION_CHUNK.to_owned(),
309            created: self.created,
310            model: self.model.clone(),
311            choices,
312            usage,
313        }
314    }
315
316    /// The opening chunk: role plus empty content.
317    ///
318    /// `content` is `""` and not omitted because clients that concatenate
319    /// `delta.content` unconditionally would otherwise see their first read
320    /// fail on a missing key.
321    pub fn role(&self) -> ChatCompletionChunk {
322        self.chunk(
323            vec![ChunkChoice {
324                index: 0,
325                delta: Delta {
326                    role: Some(crate::request::MessageRole::Assistant.as_str().to_owned()),
327                    content: Some(String::new()),
328                    tool_calls: None,
329                },
330                finish_reason: None,
331            }],
332            None,
333        )
334    }
335
336    /// A content chunk.
337    pub fn content(&self, text: impl Into<String>) -> ChatCompletionChunk {
338        self.chunk(
339            vec![ChunkChoice {
340                index: 0,
341                delta: Delta {
342                    role: None,
343                    content: Some(text.into()),
344                    tool_calls: None,
345                },
346                finish_reason: None,
347            }],
348            None,
349        )
350    }
351
352    /// One call, complete, in a single delta.
353    ///
354    /// `content` is absent rather than `""`: a client concatenating
355    /// `delta.content` would otherwise append an empty string for a chunk that
356    /// carries no text at all, and a client switching on which key is present
357    /// would see two answers to that question in one delta.
358    ///
359    /// `index` saturates rather than wrapping. A turn with four billion calls
360    /// in it is not a case worth modelling, and reporting call `u32::MAX` twice
361    /// is a visible fault where wrapping to `0` would silently overwrite the
362    /// first call in the client's table.
363    pub fn tool_call(&self, index: usize, call: crate::request::ToolCall) -> ChatCompletionChunk {
364        self.chunk(
365            vec![ChunkChoice {
366                index: 0,
367                delta: Delta {
368                    role: None,
369                    content: None,
370                    tool_calls: Some(vec![ToolCallDelta {
371                        index: u32::try_from(index).unwrap_or(u32::MAX),
372                        id: call.id,
373                        kind: call.kind,
374                        function: call.function,
375                    }]),
376                },
377                finish_reason: None,
378            }],
379            None,
380        )
381    }
382
383    /// The closing chunk: empty delta plus the reason.
384    pub fn finish(&self, reason: FinishReason) -> ChatCompletionChunk {
385        self.chunk(
386            vec![ChunkChoice {
387                index: 0,
388                delta: Delta::default(),
389                finish_reason: Some(reason),
390            }],
391            None,
392        )
393    }
394
395    /// The usage-only chunk: no choices, one usage object.
396    pub fn usage(&self, usage: Usage) -> ChatCompletionChunk {
397        self.chunk(Vec::new(), Some(usage))
398    }
399}
400
401/// One entry of `GET /v1/models`.
402#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
403pub struct ModelCard {
404    /// The model name, as it must be sent back in `model`.
405    pub id: String,
406    /// Always [`OBJECT_MODEL`].
407    pub object: String,
408    /// Unix seconds; the install time is the honest value.
409    pub created: u64,
410    /// Owner. `ramvamp` for a local install — there is no account behind it.
411    pub owned_by: String,
412}
413
414/// The `GET /v1/models` body.
415///
416/// A list of one: this process serves the install it was started with, and a
417/// client's model picker should show exactly that.
418#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
419pub struct ModelList {
420    /// Always [`OBJECT_LIST`].
421    pub object: String,
422    /// The models.
423    pub data: Vec<ModelCard>,
424}
425
426impl ModelList {
427    /// The one-model listing.
428    pub fn single(id: impl Into<String>, created: u64) -> Self {
429        ModelList {
430            object: OBJECT_LIST.to_owned(),
431            data: vec![ModelCard {
432                id: id.into(),
433                object: OBJECT_MODEL.to_owned(),
434                created,
435                owned_by: "ramvamp".to_owned(),
436            }],
437        }
438    }
439}
440
441/// The `GET /health` body when the model is up.
442///
443/// Mirrors llama.cpp's contract — `{"status":"ok"}` on 200, an error body on
444/// 503 while loading — because local tooling already probes that endpoint and
445/// expects that pair. See [`crate::error::ServerError::ModelLoading`] for the
446/// other half.
447#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
448pub struct Health {
449    /// `ok`.
450    pub status: String,
451}
452
453impl Health {
454    /// The ready body.
455    pub fn ok() -> Self {
456        Health {
457            status: "ok".to_owned(),
458        }
459    }
460}
461
462#[cfg(test)]
463mod tests {
464    use super::*;
465    use crate::error::ServerError;
466
467    fn json(value: &impl Serialize) -> serde_json::Value {
468        serde_json::to_value(value).expect("response types always serialize")
469    }
470
471    #[test]
472    fn completion_object_is_the_literal_discriminant() {
473        let completion = ChatCompletion::single(
474            "chatcmpl-1",
475            1_700_000_000,
476            "qwen3-30b-a3b",
477            "hi",
478            FinishReason::Stop,
479            Usage::new(10, 2),
480        );
481        let value = json(&completion);
482        assert_eq!(value["object"], OBJECT_CHAT_COMPLETION);
483        assert_eq!(value["object"], "chat.completion");
484        assert_eq!(value["id"], "chatcmpl-1");
485        assert_eq!(value["created"], 1_700_000_000u64);
486        assert_eq!(value["model"], "qwen3-30b-a3b");
487        assert_eq!(value["choices"][0]["index"], 0);
488        assert_eq!(value["choices"][0]["message"]["role"], "assistant");
489        assert_eq!(value["choices"][0]["message"]["content"], "hi");
490        assert_eq!(value["choices"][0]["finish_reason"], "stop");
491        assert_eq!(value["usage"]["prompt_tokens"], 10);
492        assert_eq!(value["usage"]["completion_tokens"], 2);
493        assert_eq!(value["usage"]["total_tokens"], 12);
494    }
495
496    #[test]
497    fn usage_total_is_derived_and_saturates() {
498        assert_eq!(Usage::new(3, 4).total_tokens, 7);
499        assert_eq!(Usage::new(u32::MAX, 1).total_tokens, u32::MAX);
500    }
501
502    #[test]
503    fn finish_reasons_use_openai_spellings() {
504        for (reason, wire) in [
505            (FinishReason::Stop, "stop"),
506            (FinishReason::Length, "length"),
507            (FinishReason::ToolCalls, "tool_calls"),
508            (FinishReason::ContentFilter, "content_filter"),
509        ] {
510            assert_eq!(json(&reason), wire);
511        }
512    }
513
514    /// The whole streaming contract in one place: shape, order, and the exact
515    /// keys present in each delta.
516    #[test]
517    fn streaming_chunk_sequence_is_exact() {
518        let builder = ChunkBuilder::new("chatcmpl-x", 42, "m");
519
520        let role = json(&builder.role());
521        assert_eq!(role["object"], "chat.completion.chunk");
522        assert_eq!(role["id"], "chatcmpl-x");
523        assert_eq!(role["created"], 42);
524        assert_eq!(role["model"], "m");
525        assert_eq!(role["choices"][0]["delta"]["role"], "assistant");
526        assert_eq!(role["choices"][0]["delta"]["content"], "");
527        assert!(role["choices"][0]["finish_reason"].is_null());
528        assert!(
529            role.get("usage").is_none(),
530            "no usage outside the usage chunk"
531        );
532
533        let content = json(&builder.content("hel"));
534        assert_eq!(content["choices"][0]["delta"]["content"], "hel");
535        assert!(
536            content["choices"][0]["delta"].get("role").is_none(),
537            "role is sent once, on the first chunk only"
538        );
539        assert!(content["choices"][0]["finish_reason"].is_null());
540
541        let finish = json(&builder.finish(FinishReason::Stop));
542        assert_eq!(
543            finish["choices"][0]["delta"],
544            serde_json::json!({}),
545            "the final delta is empty"
546        );
547        assert_eq!(finish["choices"][0]["finish_reason"], "stop");
548
549        let usage = json(&builder.usage(Usage::new(7, 3)));
550        assert_eq!(
551            usage["choices"],
552            serde_json::json!([]),
553            "the usage chunk carries no choices"
554        );
555        assert_eq!(usage["usage"]["prompt_tokens"], 7);
556        assert_eq!(usage["usage"]["completion_tokens"], 3);
557        assert_eq!(usage["usage"]["total_tokens"], 10);
558
559        // Every chunk of one response shares id, object, created and model.
560        for chunk in [role, content, finish, usage] {
561            assert_eq!(chunk["id"], "chatcmpl-x");
562            assert_eq!(chunk["object"], "chat.completion.chunk");
563            assert_eq!(chunk["created"], 42);
564            assert_eq!(chunk["model"], "m");
565        }
566    }
567
568    /// The tool-call delta, pinned field by field. This is the shape an agent
569    /// client switches on, and `index` is the field it cannot do without.
570    #[test]
571    fn a_tool_call_delta_carries_one_complete_call_with_its_index() {
572        let builder = ChunkBuilder::new("chatcmpl-x", 42, "m");
573        let call = crate::request::ToolCall {
574            id: "call_x_0".to_owned(),
575            kind: "function".to_owned(),
576            function: crate::request::FunctionCall {
577                name: "glob".to_owned(),
578                arguments: r#"{"pattern": "*/.rs"}"#.to_owned(),
579            },
580        };
581        let value = json(&builder.tool_call(0, call.clone()));
582
583        assert_eq!(value["object"], "chat.completion.chunk");
584        let delta = &value["choices"][0]["delta"];
585        assert_eq!(delta["tool_calls"][0]["index"], 0);
586        assert_eq!(delta["tool_calls"][0]["id"], "call_x_0");
587        assert_eq!(delta["tool_calls"][0]["type"], "function");
588        assert_eq!(delta["tool_calls"][0]["function"]["name"], "glob");
589        // `arguments` is a JSON *string*, byte for byte what the model wrote.
590        assert_eq!(
591            delta["tool_calls"][0]["function"]["arguments"],
592            r#"{"pattern": "*/.rs"}"#
593        );
594        assert!(
595            delta.get("content").is_none(),
596            "a call delta carries no content key: {delta}"
597        );
598        assert!(delta.get("role").is_none(), "{delta}");
599        assert!(value["choices"][0]["finish_reason"].is_null());
600
601        // A second call in the same turn is index 1, which is the only thing
602        // telling a client the two apart.
603        let second = json(&builder.tool_call(1, call));
604        assert_eq!(second["choices"][0]["delta"]["tool_calls"][0]["index"], 1);
605    }
606
607    /// `finish_reason` must be an explicit `null`, not an absent key.
608    #[test]
609    fn non_final_chunks_serialize_a_null_finish_reason() {
610        let builder = ChunkBuilder::new("id", 0, "m");
611        for chunk in [builder.role(), builder.content("x")] {
612            let text = serde_json::to_string(&chunk).expect("serializes");
613            assert!(text.contains(r#""finish_reason":null"#), "{text}");
614        }
615    }
616
617    #[test]
618    fn chunks_round_trip_through_json() -> Result<(), ServerError> {
619        let builder = ChunkBuilder::new("id", 1, "m");
620        for chunk in [
621            builder.role(),
622            builder.content("text"),
623            builder.tool_call(
624                0,
625                crate::request::ToolCall {
626                    id: "call_id_0".to_owned(),
627                    kind: "function".to_owned(),
628                    function: crate::request::FunctionCall {
629                        name: "read".to_owned(),
630                        arguments: "{}".to_owned(),
631                    },
632                },
633            ),
634            builder.finish(FinishReason::Length),
635            builder.usage(Usage::new(1, 2)),
636        ] {
637            let text = serde_json::to_string(&chunk)?;
638            let back: ChatCompletionChunk = serde_json::from_str(&text)?;
639            assert_eq!(back, chunk);
640        }
641        Ok(())
642    }
643
644    #[test]
645    fn models_listing_is_a_list_of_one() {
646        let value = json(&ModelList::single("qwen3-30b-a3b", 1_700_000_000));
647        assert_eq!(value["object"], "list");
648        assert_eq!(value["data"][0]["id"], "qwen3-30b-a3b");
649        assert_eq!(value["data"][0]["object"], "model");
650        assert_eq!(value["data"][0]["created"], 1_700_000_000u64);
651        assert_eq!(value["data"][0]["owned_by"], "ramvamp");
652        assert_eq!(
653            value["data"].as_array().map(Vec::len),
654            Some(1),
655            "one process serves one install"
656        );
657    }
658
659    #[test]
660    fn health_ok_matches_the_llama_cpp_contract() {
661        assert_eq!(json(&Health::ok()), serde_json::json!({"status": "ok"}));
662        // The loading half is an error body, not a `status` field.
663        assert_eq!(ServerError::ModelLoading.status(), 503);
664    }
665}