Skip to main content

gproxy_protocol/gemini/count_tokens/
response.rs

1use http::StatusCode;
2use serde::{Deserialize, Serialize};
3
4use crate::gemini::count_tokens::types::GeminiModalityTokenCount;
5use crate::gemini::types::{GeminiApiErrorResponse, GeminiResponseHeaders};
6
7/// Successful response body for Gemini `models.countTokens`.
8#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
9pub struct ResponseBody {
10    /// Number of tokens in the prompt input.
11    #[serde(rename = "totalTokens")]
12    pub total_tokens: u64,
13    /// Number of tokens in cached content, when cache is used.
14    #[serde(
15        rename = "cachedContentTokenCount",
16        default,
17        skip_serializing_if = "Option::is_none"
18    )]
19    pub cached_content_token_count: Option<u64>,
20    /// Per-modality token details for prompt input.
21    #[serde(
22        rename = "promptTokensDetails",
23        default,
24        skip_serializing_if = "Option::is_none"
25    )]
26    pub prompt_tokens_details: Option<Vec<GeminiModalityTokenCount>>,
27    /// Per-modality token details for cached input.
28    #[serde(
29        rename = "cacheTokensDetails",
30        default,
31        skip_serializing_if = "Option::is_none"
32    )]
33    pub cache_tokens_details: Option<Vec<GeminiModalityTokenCount>>,
34}
35
36/// Full HTTP response for Gemini `models.countTokens` endpoint.
37#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GeminiCountTokensResponse {
40    Success {
41        /// HTTP status code returned by server (should be `200 OK`).
42        #[serde(with = "crate::gemini::types::status_code_serde")]
43        stats_code: StatusCode,
44        /// Response headers.
45        headers: GeminiResponseHeaders,
46        /// Successful body.
47        body: ResponseBody,
48    },
49    Error {
50        /// HTTP status code returned by server (typically non-2xx).
51        #[serde(with = "crate::gemini::types::status_code_serde")]
52        stats_code: StatusCode,
53        /// Response headers.
54        headers: GeminiResponseHeaders,
55        /// Error body.
56        body: GeminiApiErrorResponse,
57    },
58}