gproxy-protocol 1.0.20

Wire-format types and cross-protocol transforms for Claude, OpenAI, and Gemini LLM APIs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
use std::collections::BTreeMap;

use http::StatusCode;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

/// API version for the `anthropic-version` request header.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Default)]
pub enum AnthropicVersion {
    /// Latest stable API version.
    #[default]
    #[serde(rename = "2023-06-01")]
    V20230601,
    /// Initial API release version.
    #[serde(rename = "2023-01-01")]
    V20230101,
}

/// HTTP method used by generated request descriptors.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "UPPERCASE")]
pub enum HttpMethod {
    Get,
    Post,
    Put,
    Patch,
    Delete,
}

/// Common envelope for HTTP responses from Claude endpoints.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ClaudeApiResponse<T> {
    /// HTTP status code returned by server.
    #[serde(with = "crate::claude::types::status_code_serde")]
    pub stats_code: StatusCode,
    /// Response headers.
    pub headers: ClaudeResponseHeaders,
    /// Response body.
    pub body: T,
}

/// Common response headers returned by Claude endpoints.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)]
pub struct ClaudeResponseHeaders {
    /// Additional response headers.
    #[serde(flatten, default, skip_serializing_if = "BTreeMap::is_empty")]
    pub extra: BTreeMap<String, String>,
}

/// Serde helpers for `http::StatusCode` as numeric code (e.g. 200, 404, 529).
pub mod status_code_serde {
    use http::StatusCode;
    use serde::de::Error as _;
    use serde::{Deserialize, Deserializer, Serializer};

    pub fn serialize<S>(value: &StatusCode, serializer: S) -> Result<S::Ok, S::Error>
    where
        S: Serializer,
    {
        serializer.serialize_u16(value.as_u16())
    }

    pub fn deserialize<'de, D>(deserializer: D) -> Result<StatusCode, D::Error>
    where
        D: Deserializer<'de>,
    {
        let code = u16::deserialize(deserializer)?;
        StatusCode::from_u16(code).map_err(D::Error::custom)
    }
}

/// Anthropic beta header value.
///
/// The API accepts both known beta tags and arbitrary strings.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AnthropicBeta {
    Known(AnthropicBetaKnown),
    Custom(String),
}

/// Known Anthropic beta tags documented by upstream specs.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum AnthropicBetaKnown {
    #[serde(rename = "message-batches-2024-09-24")]
    MessageBatches20240924,
    #[serde(rename = "prompt-caching-2024-07-31")]
    PromptCaching20240731,
    #[serde(rename = "computer-use-2024-10-22")]
    ComputerUse20241022,
    #[serde(rename = "computer-use-2025-01-24")]
    ComputerUse20250124,
    #[serde(rename = "pdfs-2024-09-25")]
    Pdfs20240925,
    #[serde(rename = "token-counting-2024-11-01")]
    TokenCounting20241101,
    #[serde(rename = "token-efficient-tools-2025-02-19")]
    TokenEfficientTools20250219,
    #[serde(rename = "output-128k-2025-02-19")]
    Output128k20250219,
    #[serde(rename = "files-api-2025-04-14")]
    FilesApi20250414,
    #[serde(rename = "mcp-client-2025-04-04")]
    McpClient20250404,
    #[serde(rename = "mcp-client-2025-11-20")]
    McpClient20251120,
    #[serde(rename = "dev-full-thinking-2025-05-14")]
    DevFullThinking20250514,
    #[serde(rename = "interleaved-thinking-2025-05-14")]
    InterleavedThinking20250514,
    #[serde(rename = "code-execution-2025-05-22")]
    CodeExecution20250522,
    #[serde(rename = "extended-cache-ttl-2025-04-11")]
    ExtendedCacheTtl20250411,
    #[serde(rename = "context-1m-2025-08-07")]
    Context1m20250807,
    #[serde(rename = "context-management-2025-06-27")]
    ContextManagement20250627,
    #[serde(rename = "model-context-window-exceeded-2025-08-26")]
    ModelContextWindowExceeded20250826,
    #[serde(rename = "skills-2025-10-02")]
    Skills20251002,
    #[serde(rename = "fast-mode-2026-02-01")]
    FastMode20260201,
    #[serde(rename = "compact-2026-01-12")]
    Compact20260112,
    #[serde(rename = "task-budgets-2026-03-13")]
    TaskBudgets20260313,
}

/// Claude model metadata returned by list/get model endpoints.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaModelInfo {
    /// Unique model identifier.
    pub id: String,
    /// RFC 3339 datetime representing model release timestamp.
    #[serde(with = "time::serde::rfc3339")]
    pub created_at: OffsetDateTime,
    /// Human-readable model name.
    pub display_name: String,
    /// Maximum input token count.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_input_tokens: Option<u64>,
    /// Maximum output token count.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max_tokens: Option<u64>,
    /// Model capabilities.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub capabilities: Option<BetaModelCapabilities>,
    /// Object type, always "model".
    #[serde(rename = "type")]
    pub type_: BetaModelType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaModelCapabilities {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub batch: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub citations: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub code_execution: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub context_management: Option<BetaContextManagementCapability>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub effort: Option<BetaEffortCapability>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub image_input: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pdf_input: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub structured_outputs: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub thinking: Option<BetaThinkingCapability>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaCapabilitySupport {
    pub supported: bool,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaContextManagementCapability {
    pub supported: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub clear_thinking_20251015: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub clear_tool_uses_20250919: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub compact_20260112: Option<BetaCapabilitySupport>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaEffortCapability {
    pub supported: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub high: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub low: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub max: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub medium: Option<BetaCapabilitySupport>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaThinkingCapability {
    pub supported: bool,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub types: Option<BetaThinkingTypes>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaThinkingTypes {
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub adaptive: Option<BetaCapabilitySupport>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub enabled: Option<BetaCapabilitySupport>,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaModelType {
    #[serde(rename = "model")]
    Model,
}

// ---------------------------------------------------------------------------
// Files API types (beta)
// ---------------------------------------------------------------------------

/// Metadata for a file stored via the Files API.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct FileMetadata {
    /// Unique object identifier (format may change over time).
    pub id: String,
    /// RFC 3339 datetime representing when the file was created.
    pub created_at: String,
    /// Original filename of the uploaded file.
    pub filename: String,
    /// MIME type of the file.
    pub mime_type: String,
    /// Size of the file in bytes.
    pub size_bytes: u64,
    /// Object type — always `"file"`.
    #[serde(rename = "type")]
    pub type_: FileObjectType,
    /// Whether the file can be downloaded.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub downloadable: Option<bool>,
}

/// Object type tag for file metadata — always `"file"`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum FileObjectType {
    #[serde(rename = "file")]
    File,
}

/// Response returned when a file is deleted.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DeletedFile {
    /// ID of the deleted file.
    pub id: String,
    /// Deleted object type — always `"file_deleted"`.
    #[serde(rename = "type", default, skip_serializing_if = "Option::is_none")]
    pub type_: Option<DeletedFileType>,
}

/// Object type tag for deleted file — always `"file_deleted"`.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum DeletedFileType {
    #[serde(rename = "file_deleted")]
    FileDeleted,
}

/// Typed beta error codes.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaErrorType {
    /// HTTP 400 (and may be used for other unlisted 4XX errors).
    #[serde(rename = "invalid_request_error")]
    InvalidRequestError,
    /// HTTP 401.
    #[serde(rename = "authentication_error")]
    AuthenticationError,
    /// Billing-related error type; HTTP status is not explicitly defined in `Errors.md`.
    #[serde(rename = "billing_error")]
    BillingError,
    /// HTTP 403.
    #[serde(rename = "permission_error")]
    PermissionError,
    /// HTTP 413.
    #[serde(rename = "request_too_large")]
    RequestTooLarge,
    /// HTTP 404.
    #[serde(rename = "not_found_error")]
    NotFoundError,
    /// HTTP 429.
    #[serde(rename = "rate_limit_error")]
    RateLimitError,
    /// Timeout-related error type; HTTP status is not explicitly defined in `Errors.md`.
    #[serde(rename = "timeout_error")]
    TimeoutError,
    /// HTTP 500.
    #[serde(rename = "api_error")]
    ApiError,
    /// HTTP 529.
    #[serde(rename = "overloaded_error")]
    OverloadedError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaApiError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaApiErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaApiErrorType {
    #[serde(rename = "api_error")]
    ApiError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaAuthenticationError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaAuthenticationErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaAuthenticationErrorType {
    #[serde(rename = "authentication_error")]
    AuthenticationError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaBillingError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaBillingErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaBillingErrorType {
    #[serde(rename = "billing_error")]
    BillingError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaGatewayTimeoutError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaGatewayTimeoutErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaGatewayTimeoutErrorType {
    #[serde(rename = "timeout_error")]
    TimeoutError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaInvalidRequestError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaInvalidRequestErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaInvalidRequestErrorType {
    #[serde(rename = "invalid_request_error")]
    InvalidRequestError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaNotFoundError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaNotFoundErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaNotFoundErrorType {
    #[serde(rename = "not_found_error")]
    NotFoundError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaOverloadedError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaOverloadedErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaOverloadedErrorType {
    #[serde(rename = "overloaded_error")]
    OverloadedError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaPermissionError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaPermissionErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaPermissionErrorType {
    #[serde(rename = "permission_error")]
    PermissionError,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaRateLimitError {
    pub message: String,
    #[serde(rename = "type")]
    pub type_: BetaRateLimitErrorType,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaRateLimitErrorType {
    #[serde(rename = "rate_limit_error")]
    RateLimitError,
}

/// Error union returned by beta endpoints.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BetaError {
    InvalidRequest(BetaInvalidRequestError),
    Authentication(BetaAuthenticationError),
    Billing(BetaBillingError),
    Permission(BetaPermissionError),
    NotFound(BetaNotFoundError),
    RateLimit(BetaRateLimitError),
    GatewayTimeout(BetaGatewayTimeoutError),
    Api(BetaApiError),
    Overloaded(BetaOverloadedError),
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum BetaErrorResponseType {
    #[serde(rename = "error")]
    Error,
}

/// Top-level beta error response wrapper.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BetaErrorResponse {
    pub error: BetaError,
    pub request_id: String,
    #[serde(rename = "type")]
    pub type_: BetaErrorResponseType,
}