//! Anthropic Messages API request and response types. //! //! These mirror the `/v1/messages` format used by the Anthropic API. //! The gateway accepts these, translates to OpenAI format, proxies to //! the inference backend (neuron), then translates the response back. use serde::{Deserialize, Serialize}; use serde_json::Value; // ── Messages request ───────────────────────────────────────────────── #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MessagesRequest { pub model: String, pub messages: Vec, pub max_tokens: u64, #[serde(skip_serializing_if = "Option::is_none")] pub system: Option, #[serde(skip_serializing_if = "Option::is_none")] pub temperature: Option, #[serde(skip_serializing_if = "Option::is_none")] pub top_p: Option, #[serde(skip_serializing_if = "Option::is_none")] pub stream: Option, #[serde(flatten)] pub extra: Value, } #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum SystemPrompt { Text(String), Blocks(Vec), } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicMessage { pub role: String, pub content: AnthropicContent, } #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] pub enum AnthropicContent { Text(String), Blocks(Vec), } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ContentBlock { #[serde(rename = "type")] pub block_type: String, #[serde(flatten)] pub data: Value, } // ── Messages response ──────────────────────────────────────────────── #[derive(Debug, Clone, Serialize, Deserialize)] pub struct MessagesResponse { pub id: String, #[serde(rename = "type")] pub response_type: String, pub role: String, pub content: Vec, pub model: String, pub stop_reason: Option, pub usage: AnthropicUsage, #[serde(flatten)] pub extra: Value, } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct AnthropicUsage { pub input_tokens: u64, pub output_tokens: u64, } // ── Streaming events ───────────────────────────────────────────────── #[derive(Debug, Clone, Serialize, Deserialize)] pub struct StreamEvent { #[serde(rename = "type")] pub event_type: String, #[serde(flatten)] pub data: Value, }