Skip to main content

rig_core/providers/anthropic/
wire.rs

1//! Configuration and wires for Messages-format completion, model listing,
2//! and credential verification. [`Dialect`] describes endpoint defaults and capabilities.
3//!
4//! ```no_run
5//! use rig_core::providers::anthropic::{Anthropic, completion::CLAUDE_SONNET_4_6};
6//!
7//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
8//! let wire = Anthropic::from_env()?.completion(CLAUDE_SONNET_4_6);
9//! # Ok(())
10//! # }
11//! ```
12
13use crate::client::env::{self, EnvError};
14use crate::completion::{CompletionRequest, ProviderCapabilities};
15use crate::error::EncodeError;
16use crate::error::ProviderError;
17use crate::message::Issuer;
18use crate::model::{ModelInfo, ModelList};
19pub use crate::operation::VerifyDecoder;
20use crate::operation::{Completion, ModelListing, ModelPage, Verify as VerifyOp};
21use crate::providers::internal::named_dialect;
22use crate::wire::Flow;
23use crate::wire::{
24    Body, Capabilities, Decoder, Descriptor, Encoded, Framing, Mode, Out, Secret, Wire, WireEvent,
25    WireFrame,
26};
27use serde::{Deserialize, Serialize};
28
29use super::completion::{
30    AnthropicCompletionRequest, AnthropicRequestParams, CacheTtl, ToolDefinition,
31    default_max_tokens_for_model, rejects_forced_tool_choice, sanitize_strict_tool_schema,
32};
33use super::streaming::MessagesDecoder;
34
35/// Endpoint defaults and capabilities for a Messages-format provider.
36/// Serializes by registered name. Serialization rejects modified or unregistered
37/// dialects; deserialization rejects unknown names.
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
39pub struct Dialect {
40    /// The provider descriptor name, as records and telemetry spell it.
41    pub name: &'static str,
42    /// The default base URL.
43    pub base_url: &'static str,
44    /// The environment variable carrying the API key.
45    pub api_key_env: &'static str,
46    /// The environment variable overriding the base URL, when the provider
47    /// documents one.
48    pub base_url_env: Option<&'static str>,
49    /// The reply header carrying the provider's transport request id.
50    pub request_id_header: Option<&'static str>,
51    /// Everything that is not identity.
52    pub quirks: Quirks,
53}
54
55/// Token defaults and schema capabilities for a Messages-format dialect.
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57#[non_exhaustive]
58pub struct Quirks {
59    /// How `max_tokens` is defaulted when the caller sets none. Anthropic
60    /// requires the field, so a wire that cannot supply it fails the request
61    /// rather than sending one the API rejects.
62    pub max_tokens: MaxTokens,
63    /// Whether the provider implements Anthropic's constrained tool schemas.
64    /// A gateway that does not leaves Rig-generated tools unchanged.
65    pub strict_tool_schemas: bool,
66}
67
68impl Quirks {
69    /// Anthropic's own contract.
70    pub const fn anthropic() -> Self {
71        Self {
72            max_tokens: MaxTokens::ByModel,
73            strict_tool_schemas: true,
74        }
75    }
76
77    /// Default to 4096 output tokens without constrained tool schemas.
78    pub const fn gateway() -> Self {
79        Self {
80            max_tokens: MaxTokens::Fixed(4096),
81            strict_tool_schemas: false,
82        }
83    }
84}
85
86/// Where a dialect's `max_tokens` default comes from.
87#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
88pub enum MaxTokens {
89    /// Anthropic's published per-model output limits.
90    ByModel,
91    /// One ceiling for every model, which is all a gateway documents.
92    Fixed(u64),
93}
94
95/// Anthropic itself.
96pub const ANTHROPIC: Dialect = Dialect {
97    name: "anthropic",
98    base_url: "https://api.anthropic.com",
99    api_key_env: "ANTHROPIC_API_KEY",
100    base_url_env: Some("ANTHROPIC_BASE_URL"),
101    request_id_header: Some("request-id"),
102    quirks: Quirks::anthropic(),
103};
104
105/// Registered Messages-format dialects in declaration order.
106const ALL: &[&Dialect] = &[&ANTHROPIC, &ZAI, &MINIMAX, &MOONSHOT, &XIAOMIMIMO];
107
108/// Every Messages-format dialect this build knows, in declaration order.
109pub fn all() -> impl Iterator<Item = &'static Dialect> {
110    ALL.iter().copied()
111}
112
113impl Dialect {
114    /// The dialect this crate ships under `name`.
115    pub fn by_name(name: &str) -> Option<Self> {
116        all().copied().find(|dialect| dialect.name == name)
117    }
118}
119
120impl Serialize for Dialect {
121    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
122        let registered = Self::by_name(self.name).as_ref() == Some(self);
123        named_dialect::serialize(serializer, "Anthropic", self.name, registered)
124    }
125}
126
127impl<'de> Deserialize<'de> for Dialect {
128    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
129        named_dialect::deserialize(deserializer, "Anthropic", Self::by_name)
130    }
131}
132
133/// Build a Messages-format dialect with `request-id` response headers and
134/// [`Quirks::gateway`] defaults. Only registered dialects support serialization.
135pub const fn compatible(
136    name: &'static str,
137    base_url: &'static str,
138    api_key_env: &'static str,
139    base_url_env: Option<&'static str>,
140) -> Dialect {
141    Dialect {
142        name,
143        base_url,
144        api_key_env,
145        base_url_env,
146        request_id_header: Some("request-id"),
147        quirks: Quirks::gateway(),
148    }
149}
150
151/// The strict-tool transform Anthropic's constrained decoding needs.
152pub(crate) fn strict_tool_transform(tool: &mut ToolDefinition) {
153    sanitize_strict_tool_schema(&mut tool.input_schema);
154    tool.strict = true;
155}
156
157impl Dialect {
158    /// The `max_tokens` this dialect defaults `model` to.
159    pub fn default_max_tokens(&self, model: &str) -> Option<u64> {
160        match self.quirks.max_tokens {
161            MaxTokens::ByModel => default_max_tokens_for_model(model),
162            MaxTokens::Fixed(tokens) => Some(tokens),
163        }
164    }
165}
166
167/// Z.AI's Anthropic-format endpoint.
168pub const ZAI: Dialect = compatible(
169    "zai",
170    "https://api.z.ai/api/anthropic",
171    "ZAI_API_KEY",
172    Some("ZAI_ANTHROPIC_API_BASE"),
173);
174
175/// MiniMax's Anthropic-format endpoint.
176pub const MINIMAX: Dialect = compatible(
177    "minimax",
178    "https://api.minimax.io/anthropic",
179    "MINIMAX_API_KEY",
180    Some("MINIMAX_ANTHROPIC_API_BASE"),
181);
182
183/// Moonshot's Anthropic-format endpoint.
184pub const MOONSHOT: Dialect = compatible(
185    "moonshot",
186    "https://api.moonshot.ai/anthropic",
187    "MOONSHOT_API_KEY",
188    Some("MOONSHOT_ANTHROPIC_API_BASE"),
189);
190
191/// Xiaomi MiMo's Anthropic-format endpoint.
192pub const XIAOMIMIMO: Dialect = compatible(
193    "xiaomimimo",
194    "https://api.xiaomimimo.com/anthropic/v1",
195    "XIAOMI_MIMO_API_KEY",
196    Some("XIAOMI_MIMO_ANTHROPIC_API_BASE"),
197);
198
199/// The settings of a Messages-format provider: serializable, and the
200/// credential is never serialized. [`connect`](Self::connect) puts it on a
201/// transport as an [`Anthropic`](super::Anthropic) client.
202#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
203#[serde(deny_unknown_fields)]
204pub struct AnthropicConfig {
205    /// The API key, sent as `x-api-key`.
206    pub api_key: Secret,
207    /// The API root, without a trailing `/v1`.
208    pub base_url: String,
209    /// The `anthropic-version` header.
210    pub version: String,
211    /// The `anthropic-beta` flags, joined with commas when non-empty.
212    pub betas: Vec<String>,
213    /// Which Messages-format provider this is.
214    pub dialect: Dialect,
215}
216
217impl AnthropicConfig {
218    /// Anthropic itself, with default settings.
219    pub fn new(api_key: impl Into<Secret>) -> Self {
220        Self::with_dialect(api_key, &ANTHROPIC)
221    }
222
223    /// A Messages-format provider with default settings.
224    pub fn with_dialect(api_key: impl Into<Secret>, dialect: &Dialect) -> Self {
225        Self {
226            api_key: api_key.into(),
227            base_url: dialect.base_url.to_owned(),
228            version: super::completion::ANTHROPIC_VERSION_LATEST.to_owned(),
229            betas: Vec::new(),
230            dialect: *dialect,
231        }
232    }
233
234    /// Anthropic from `ANTHROPIC_API_KEY` and `ANTHROPIC_BASE_URL`.
235    pub fn from_env() -> Result<Self, EnvError> {
236        Self::from_env_with(&ANTHROPIC)
237    }
238
239    /// A Messages-format provider from the variables its dialect names.
240    pub fn from_env_with(dialect: &Dialect) -> Result<Self, EnvError> {
241        let mut provider = Self::with_dialect(env::required(dialect.api_key_env)?, dialect);
242        if let Some(name) = dialect.base_url_env
243            && let Some(base_url) = env::optional(name)?
244        {
245            provider.base_url = normalize_base_url(&base_url);
246        }
247        Ok(provider)
248    }
249
250    /// Pin the `anthropic-version` header.
251    pub fn with_version(mut self, version: impl Into<String>) -> Self {
252        self.version = version.into();
253        self
254    }
255
256    /// Request an `anthropic-beta` flag.
257    pub fn with_beta(mut self, beta: impl Into<String>) -> Self {
258        self.betas.push(beta.into());
259        self
260    }
261
262    /// Point the wire at another API root.
263    pub fn with_base_url(mut self, base_url: impl AsRef<str>) -> Self {
264        self.base_url = normalize_base_url(base_url.as_ref());
265        self
266    }
267
268    /// The Messages wire for `model`.
269    pub(crate) fn completion(&self, model: impl Into<String>) -> Messages {
270        let model = model.into();
271        Messages {
272            default_max_tokens: self.dialect.default_max_tokens(&model),
273            provider: self.clone(),
274            model,
275            prompt_caching: false,
276            automatic_caching: false,
277            automatic_caching_ttl: None,
278            static_prefix_cache_ttl: None,
279            strict_tools: false,
280        }
281    }
282
283    /// The model-listing wire.
284    pub(crate) fn models(&self) -> Models {
285        Models {
286            provider: self.clone(),
287        }
288    }
289
290    /// The credential-check wire.
291    pub(crate) fn verify(&self) -> Verify {
292        Verify {
293            provider: self.clone(),
294        }
295    }
296
297    /// The request headers every Messages-format endpoint takes.
298    fn headers(&self, builder: http::request::Builder) -> http::request::Builder {
299        let builder = builder
300            .header("x-api-key", self.api_key.expose())
301            .header("anthropic-version", &self.version);
302        if self.betas.is_empty() {
303            builder
304        } else {
305            builder.header("anthropic-beta", self.betas.join(","))
306        }
307    }
308}
309
310/// Trim the suffixes a user may paste from the API docs, so a base URL that
311/// already names the endpoint does not produce `/v1/messages/v1/messages`.
312pub fn normalize_base_url(base_url: &str) -> String {
313    let trimmed = base_url.trim_end_matches('/');
314    for suffix in ["/v1/messages", "/messages", "/v1"] {
315        if let Some(stripped) = trimmed.strip_suffix(suffix) {
316            return stripped.to_owned();
317        }
318    }
319    trimmed.to_owned()
320}
321
322/// The Messages wire: `POST /v1/messages`, SSE when streamed.
323#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
324pub struct Messages {
325    /// The provider this wire speaks to.
326    pub provider: AnthropicConfig,
327    /// The model to address.
328    pub model: String,
329    /// What `max_tokens` defaults to when the caller sets none. Anthropic
330    /// requires the field; `None` means a request without one is rejected
331    /// here rather than by the API.
332    pub default_max_tokens: Option<u64>,
333    /// Manual prompt caching: `cache_control` breakpoints on the system
334    /// prompt, the last tool definition, and the last content block of the
335    /// last message.
336    pub prompt_caching: bool,
337    /// Anthropic's automatic prompt caching: one top-level `cache_control`
338    /// the API advances as the conversation grows.
339    pub automatic_caching: bool,
340    /// TTL for the automatic breakpoint. `None` takes the API default.
341    pub automatic_caching_ttl: Option<CacheTtl>,
342    /// TTL for the static prefix (tools + system), independent of the
343    /// conversation tail. `None` inherits the top-level TTL.
344    pub static_prefix_cache_ttl: Option<CacheTtl>,
345    /// Whether Rig-generated tools request the provider's strict validation.
346    pub strict_tools: bool,
347}
348
349impl Messages {
350    /// Set the `max_tokens` a request without one defaults to.
351    pub fn with_default_max_tokens(mut self, tokens: u64) -> Self {
352        self.default_max_tokens = Some(tokens);
353        self
354    }
355
356    /// Enable cache breakpoints on the system prompt, final tool, and final message block.
357    /// With automatic caching, the provider owns the moving message breakpoint.
358    /// Existing tool markers are preserved and count toward the four-breakpoint budget.
359    pub fn with_prompt_caching(mut self) -> Self {
360        self.prompt_caching = true;
361        self
362    }
363
364    /// Enable top-level `cache_control`, advancing the last cacheable block
365    /// as the conversation grows. No beta header is required.
366    /// Caching is skipped below the model-specific minimum prompt length.
367    ///
368    /// ```no_run
369    /// use rig_core::providers::anthropic::completion::CLAUDE_SONNET_4_6;
370    /// use rig_core::providers::anthropic::Anthropic;
371    ///
372    /// # fn run() -> Result<(), Box<dyn std::error::Error>> {
373    /// let mut messages = Anthropic::from_env()?.completion(CLAUDE_SONNET_4_6);
374    /// messages.wire = messages.wire.with_automatic_caching();
375    /// # Ok(())
376    /// # }
377    /// ```
378    pub fn with_automatic_caching(mut self) -> Self {
379        self.automatic_caching = true;
380        self
381    }
382
383    /// Automatic caching with the one-hour TTL rather than the default five
384    /// minutes. Identical to [`Self::with_automatic_caching`] but sets
385    /// `ttl: "1h"` on the top-level `cache_control` field.
386    ///
387    /// ```no_run
388    /// use rig_core::providers::anthropic::completion::CLAUDE_SONNET_4_6;
389    /// use rig_core::providers::anthropic::Anthropic;
390    ///
391    /// # fn run() -> Result<(), Box<dyn std::error::Error>> {
392    /// let mut messages = Anthropic::from_env()?.completion(CLAUDE_SONNET_4_6);
393    /// messages.wire = messages.wire.with_automatic_caching_1h();
394    /// # Ok(())
395    /// # }
396    /// ```
397    pub fn with_automatic_caching_1h(mut self) -> Self {
398        self.automatic_caching = true;
399        self.automatic_caching_ttl = Some(CacheTtl::OneHour);
400        self
401    }
402
403    /// Cache the static prefix (tool definitions and system prompt) at its
404    /// own TTL, independent of the conversation tail's.
405    ///
406    /// Mark the final tool definition and system prompt at `ttl` without
407    /// changing the conversation tail's TTL.
408    ///
409    /// ```no_run
410    /// use rig_core::providers::anthropic::completion::{CLAUDE_SONNET_4_6, CacheTtl};
411    /// use rig_core::providers::anthropic::Anthropic;
412    ///
413    /// # fn run() -> Result<(), Box<dyn std::error::Error>> {
414    /// let mut messages = Anthropic::from_env()?.completion(CLAUDE_SONNET_4_6);
415    /// messages.wire = messages.wire.with_automatic_caching().with_static_prefix_cache_ttl(CacheTtl::OneHour);
416    /// # Ok(())
417    /// # }
418    /// ```
419    ///
420    /// One-hour markers must precede five-minute markers. A five-minute
421    /// prefix with [`Self::with_automatic_caching_1h`] fails during encoding.
422    /// Each marker must meet the model's minimum cacheable prompt length.
423    pub fn with_static_prefix_cache_ttl(mut self, ttl: CacheTtl) -> Self {
424        self.static_prefix_cache_ttl = Some(ttl);
425        self
426    }
427
428    /// Request Anthropic's strict tool use for every Rig-generated tool.
429    ///
430    /// Anthropic constrains tool inputs to the supported JSON Schema subset
431    /// when `strict: true` is present on a tool definition. Rig sanitizes
432    /// each generated schema for that subset and leaves provider-specific
433    /// tools supplied through `additional_params` unchanged. Unsupported
434    /// validation keywords are retained only as model guidance in schema
435    /// descriptions; neither Anthropic nor Rig enforces them, so validate
436    /// tool inputs before execution when those constraints matter.
437    ///
438    /// Anthropic caches compiled schemas for up to 24 hours: do not include
439    /// PHI in schema property names, enum or const values, or regex
440    /// patterns. A dialect that does not implement constrained tool schemas
441    /// ignores this.
442    pub fn with_strict_tools(mut self) -> Self {
443        self.strict_tools = true;
444        self
445    }
446
447    /// The typed request body, shared by both modes.
448    fn body(
449        &self,
450        mut request: CompletionRequest,
451        mode: Mode,
452    ) -> Result<serde_json::Value, EncodeError> {
453        if request.max_tokens.is_none() {
454            let Some(tokens) = self.default_max_tokens else {
455                return Err(EncodeError::request(
456                    "`max_tokens` must be set for Anthropic",
457                ));
458            };
459            request.max_tokens = Some(tokens);
460        }
461        let model = request.model.clone().unwrap_or_else(|| self.model.clone());
462        // Only reasoning this dialect issued is replayed here.
463        let issuers = [Issuer::from_static(self.provider.dialect.name)];
464        let request = request.replayable_to(&issuers)?;
465        let typed = AnthropicCompletionRequest::try_from_params(
466            AnthropicRequestParams {
467                model: &model,
468                issuers: &issuers,
469                request,
470                prompt_caching: self.prompt_caching,
471                automatic_caching: self.automatic_caching,
472                automatic_caching_ttl: self.automatic_caching_ttl.clone(),
473                static_prefix_cache_ttl: self.static_prefix_cache_ttl.clone(),
474            },
475            (self.strict_tools && self.provider.dialect.quirks.strict_tool_schemas)
476                .then_some(strict_tool_transform as fn(&mut ToolDefinition)),
477        )?;
478        let mut body = serde_json::to_value(&typed)?;
479        if mode == Mode::Unary {
480            return Ok(body);
481        }
482        // Anthropic rejects tool_choice without tools.
483        if let Some(map) = body.as_object_mut() {
484            map.insert("stream".to_owned(), serde_json::Value::Bool(true));
485            if map.contains_key("tools") {
486                map.entry("tool_choice")
487                    .or_insert_with(|| serde_json::json!({ "type": "auto" }));
488            } else {
489                map.remove("tool_choice");
490            }
491        }
492        Ok(body)
493    }
494}
495
496impl Wire for Messages {
497    type Op = Completion;
498    type Payload = crate::wire::Encoded;
499    type Frame = crate::wire::WireFrame;
500    type Decoder<'id> = MessagesDecoder<'id>;
501
502    /// Constrained output decoding does not suppress strict tool calls.
503    fn describe(&self) -> Descriptor<'_> {
504        Descriptor::new(self.provider.dialect.name)
505            .model(self.model.as_str())
506            .capabilities(Capabilities::completion(
507                ProviderCapabilities::default()
508                    .with_native_output_tool_composition(true)
509                    .with_forced_tool_choice_rejected(rejects_forced_tool_choice(&self.model)),
510            ))
511    }
512
513    fn encode(&self, request: CompletionRequest, mode: Mode) -> Result<Encoded, EncodeError> {
514        let body = self.body(request, mode)?;
515        crate::providers::internal::trace_json(
516            crate::providers::internal::LogTarget::Completions,
517            "Anthropic completion request",
518            &body,
519        );
520        let request = self
521            .provider
522            .headers(http::Request::post(format!(
523                "{}/v1/messages",
524                self.provider.base_url
525            )))
526            .header(http::header::CONTENT_TYPE, "application/json")
527            .body(Body::Bytes(serde_json::to_vec(&body)?))?;
528        Ok(Encoded::new(
529            request,
530            match mode {
531                Mode::Unary => Framing::Whole,
532                Mode::Streaming => Framing::Sse,
533            },
534        )
535        .with_request_id_header(self.provider.dialect.request_id_header)
536        .with_projection(MessagesDecoder::project))
537    }
538
539    fn decoder<'id>(&self) -> Self::Decoder<'id> {
540        MessagesDecoder::new()
541    }
542}
543
544/// The model-listing wire: `GET /v1/models`, cursor-paged.
545#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
546pub struct Models {
547    /// The provider this wire speaks to.
548    pub provider: AnthropicConfig,
549}
550
551impl Wire for Models {
552    type Op = ModelListing;
553    type Payload = crate::wire::Encoded;
554    type Frame = crate::wire::WireFrame;
555    type Decoder<'id> = ModelsDecoder;
556
557    fn describe(&self) -> Descriptor<'_> {
558        Descriptor::new(self.provider.dialect.name)
559    }
560
561    fn encode(&self, cursor: Option<String>, _mode: Mode) -> Result<Encoded, EncodeError> {
562        Ok(Encoded::new(
563            self.models_request(cursor.as_deref())?,
564            Framing::Whole,
565        ))
566    }
567
568    fn decoder<'id>(&self) -> Self::Decoder<'id> {
569        ModelsDecoder
570    }
571}
572
573impl Models {
574    /// One page's request, after `cursor` when the previous page named one.
575    fn models_request(&self, cursor: Option<&str>) -> Result<http::Request<Body>, EncodeError> {
576        let uri = match cursor {
577            Some(cursor) => format!(
578                "{}{}",
579                self.provider.base_url,
580                crate::providers::internal::with_query_pairs("/v1/models", &[("after_id", cursor)],)
581            ),
582            None => format!("{}/v1/models", self.provider.base_url),
583        };
584        self.provider
585            .headers(http::Request::get(uri))
586            .body(Body::empty())
587            .map_err(EncodeError::from)
588    }
589}
590
591/// One page of `GET /v1/models`.
592#[derive(Debug, Deserialize)]
593#[doc(hidden)]
594pub struct ModelsPage {
595    data: Vec<ModelEntry>,
596    #[serde(default)]
597    has_more: bool,
598    #[serde(default)]
599    last_id: Option<String>,
600}
601
602#[derive(Debug, Deserialize)]
603struct ModelEntry {
604    id: String,
605    display_name: String,
606}
607
608impl From<ModelEntry> for ModelInfo {
609    fn from(entry: ModelEntry) -> Self {
610        ModelInfo::new(entry.id, entry.display_name)
611    }
612}
613
614/// Decodes `GET /v1/models` and the cursor Anthropic names.
615pub struct ModelsDecoder;
616
617impl<'id> Decoder<'id, ModelListing> for ModelsDecoder {
618    type Event = ModelsPage;
619
620    fn classify(&self, frame: WireFrame) -> WireEvent<Self::Event> {
621        crate::providers::internal::wire::classify_marker_keyed_frame(&frame.as_str(), &["data"])
622    }
623
624    fn decode(
625        &mut self,
626        page: Self::Event,
627        out: Out<'id, ModelListing>,
628    ) -> Result<Flow, ProviderError> {
629        // Missing or empty cursors would repeatedly fetch page one, even with has_more.
630        let next = page
631            .last_id
632            .filter(|cursor| page.has_more && !cursor.is_empty());
633        Ok(out.end(ModelPage {
634            models: ModelList::new(page.data.into_iter().map(ModelInfo::from).collect()),
635            next,
636        }))
637    }
638}
639
640/// The credential-check wire: `GET /v1/models`, status only, decoded by
641/// the shared [`VerifyDecoder`].
642#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
643pub struct Verify {
644    /// The provider this wire speaks to.
645    pub provider: AnthropicConfig,
646}
647
648impl Wire for Verify {
649    type Op = VerifyOp;
650    type Payload = crate::wire::Encoded;
651    type Frame = crate::wire::WireFrame;
652    type Decoder<'id> = VerifyDecoder;
653
654    fn describe(&self) -> Descriptor<'_> {
655        Descriptor::new(self.provider.dialect.name)
656    }
657
658    fn encode(&self, _request: (), _mode: Mode) -> Result<Encoded, EncodeError> {
659        let request = self
660            .provider
661            .headers(http::Request::get(format!(
662                "{}/v1/models",
663                self.provider.base_url
664            )))
665            .body(Body::empty())?;
666        Ok(Encoded::new(request, Framing::Whole))
667    }
668
669    fn decoder<'id>(&self) -> Self::Decoder<'id> {
670        VerifyDecoder
671    }
672}
673
674#[cfg(test)]
675mod tests;