Skip to main content

gproxy_protocol/
spec.rs

1//! Declared wire surfaces, independent of routing and provider capabilities.
2//!
3//! This table describes the protocol models available in this crate. It is not
4//! a transform matrix or a list of operations every upstream must implement.
5//! Error responses can use other bodies. Paths, TLS/client configuration,
6//! authentication, billing and affinity belong to their respective adapters or
7//! engine layers. No request is validated or sent by consulting this table.
8
9use crate::{Dialect, Operation, OperationKey, connection::StreamFraming};
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum HttpBodyFormat {
13    Empty,
14    Json,
15    Multipart,
16    Binary,
17    Text,
18    /// A sequence of JSON payloads carried using HTTP stream framing.
19    JsonStream(StreamFraming),
20}
21
22#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum OperationTransport {
24    Http {
25        request: &'static [HttpBodyFormat],
26        response: &'static [HttpBodyFormat],
27    },
28    /// The HTTP handshake is followed by an independent duplex connection.
29    WebSocket,
30}
31
32#[derive(Debug, Clone, Copy, PartialEq, Eq)]
33pub struct OperationSpec {
34    pub key: OperationKey,
35    pub transport: OperationTransport,
36}
37
38/// Format alternatives describe the modelled wire surfaces, not runtime
39/// capabilities or default selection. Headers/query choose a format; ordering
40/// here does not imply a default or infer boundaries from transport chunks.
41pub const OPERATION_SPECS: &[OperationSpec] = &[
42    OperationSpec {
43        key: OperationKey {
44            operation: Operation::ListModels,
45            dialect: Dialect::OpenAi,
46        },
47        transport: OperationTransport::Http {
48            request: &[HttpBodyFormat::Empty],
49            response: &[HttpBodyFormat::Json],
50        },
51    },
52    OperationSpec {
53        key: OperationKey {
54            operation: Operation::ListModels,
55            dialect: Dialect::Claude,
56        },
57        transport: OperationTransport::Http {
58            request: &[HttpBodyFormat::Empty],
59            response: &[HttpBodyFormat::Json],
60        },
61    },
62    OperationSpec {
63        key: OperationKey {
64            operation: Operation::ListModels,
65            dialect: Dialect::Gemini,
66        },
67        transport: OperationTransport::Http {
68            request: &[HttpBodyFormat::Empty],
69            response: &[HttpBodyFormat::Json],
70        },
71    },
72    OperationSpec {
73        key: OperationKey {
74            operation: Operation::GetModel,
75            dialect: Dialect::OpenAi,
76        },
77        transport: OperationTransport::Http {
78            request: &[HttpBodyFormat::Empty],
79            response: &[HttpBodyFormat::Json],
80        },
81    },
82    OperationSpec {
83        key: OperationKey {
84            operation: Operation::GetModel,
85            dialect: Dialect::Claude,
86        },
87        transport: OperationTransport::Http {
88            request: &[HttpBodyFormat::Empty],
89            response: &[HttpBodyFormat::Json],
90        },
91    },
92    OperationSpec {
93        key: OperationKey {
94            operation: Operation::GetModel,
95            dialect: Dialect::Gemini,
96        },
97        transport: OperationTransport::Http {
98            request: &[HttpBodyFormat::Empty],
99            response: &[HttpBodyFormat::Json],
100        },
101    },
102    OperationSpec {
103        key: OperationKey {
104            operation: Operation::CountTokens,
105            dialect: Dialect::OpenAi,
106        },
107        transport: OperationTransport::Http {
108            request: &[HttpBodyFormat::Json],
109            response: &[HttpBodyFormat::Json],
110        },
111    },
112    OperationSpec {
113        key: OperationKey {
114            operation: Operation::CountTokens,
115            dialect: Dialect::Claude,
116        },
117        transport: OperationTransport::Http {
118            request: &[HttpBodyFormat::Json],
119            response: &[HttpBodyFormat::Json],
120        },
121    },
122    OperationSpec {
123        key: OperationKey {
124            operation: Operation::CountTokens,
125            dialect: Dialect::Gemini,
126        },
127        transport: OperationTransport::Http {
128            request: &[HttpBodyFormat::Json],
129            response: &[HttpBodyFormat::Json],
130        },
131    },
132    OperationSpec {
133        key: OperationKey {
134            operation: Operation::GenerateContent,
135            dialect: Dialect::OpenAi,
136        },
137        transport: OperationTransport::Http {
138            request: &[HttpBodyFormat::Json],
139            response: &[HttpBodyFormat::Json],
140        },
141    },
142    OperationSpec {
143        key: OperationKey {
144            operation: Operation::GenerateContent,
145            dialect: Dialect::Claude,
146        },
147        transport: OperationTransport::Http {
148            request: &[HttpBodyFormat::Json],
149            response: &[HttpBodyFormat::Json],
150        },
151    },
152    OperationSpec {
153        key: OperationKey {
154            operation: Operation::GenerateContent,
155            dialect: Dialect::Gemini,
156        },
157        transport: OperationTransport::Http {
158            request: &[HttpBodyFormat::Json],
159            response: &[HttpBodyFormat::Json],
160        },
161    },
162    OperationSpec {
163        key: OperationKey {
164            operation: Operation::GenerateContent,
165            dialect: Dialect::OpenAiChat,
166        },
167        transport: OperationTransport::Http {
168            request: &[HttpBodyFormat::Json],
169            response: &[HttpBodyFormat::Json],
170        },
171    },
172    OperationSpec {
173        key: OperationKey {
174            operation: Operation::StreamGenerateContent,
175            dialect: Dialect::OpenAi,
176        },
177        transport: OperationTransport::Http {
178            request: &[HttpBodyFormat::Json],
179            response: &[HttpBodyFormat::JsonStream(StreamFraming::Sse)],
180        },
181    },
182    OperationSpec {
183        key: OperationKey {
184            operation: Operation::StreamGenerateContent,
185            dialect: Dialect::Claude,
186        },
187        transport: OperationTransport::Http {
188            request: &[HttpBodyFormat::Json],
189            response: &[HttpBodyFormat::JsonStream(StreamFraming::Sse)],
190        },
191    },
192    OperationSpec {
193        key: OperationKey {
194            operation: Operation::StreamGenerateContent,
195            dialect: Dialect::OpenAiChat,
196        },
197        transport: OperationTransport::Http {
198            request: &[HttpBodyFormat::Json],
199            response: &[HttpBodyFormat::JsonStream(StreamFraming::Sse)],
200        },
201    },
202    OperationSpec {
203        key: OperationKey {
204            operation: Operation::StreamGenerateContent,
205            dialect: Dialect::Gemini,
206        },
207        transport: OperationTransport::Http {
208            request: &[HttpBodyFormat::Json],
209            response: &[
210                HttpBodyFormat::JsonStream(StreamFraming::Sse),
211                HttpBodyFormat::JsonStream(StreamFraming::JsonArray),
212            ],
213        },
214    },
215    OperationSpec {
216        key: OperationKey {
217            operation: Operation::CreateModeration,
218            dialect: Dialect::OpenAi,
219        },
220        transport: OperationTransport::Http {
221            request: &[HttpBodyFormat::Json],
222            response: &[HttpBodyFormat::Json],
223        },
224    },
225    OperationSpec {
226        key: OperationKey {
227            operation: Operation::CreateDecision,
228            dialect: Dialect::OpenAi,
229        },
230        transport: OperationTransport::Http {
231            request: &[HttpBodyFormat::Json],
232            response: &[HttpBodyFormat::Json],
233        },
234    },
235    OperationSpec {
236        key: OperationKey {
237            operation: Operation::GuardianReview,
238            dialect: Dialect::OpenAi,
239        },
240        transport: OperationTransport::Http {
241            request: &[HttpBodyFormat::Json],
242            response: &[HttpBodyFormat::JsonStream(StreamFraming::Sse)],
243        },
244    },
245    OperationSpec {
246        key: OperationKey {
247            operation: Operation::GuardianClassify,
248            dialect: Dialect::OpenAi,
249        },
250        transport: OperationTransport::Http {
251            request: &[HttpBodyFormat::Json],
252            response: &[HttpBodyFormat::JsonStream(StreamFraming::Sse)],
253        },
254    },
255    OperationSpec {
256        key: OperationKey {
257            operation: Operation::CompactContent,
258            dialect: Dialect::OpenAi,
259        },
260        transport: OperationTransport::Http {
261            request: &[HttpBodyFormat::Json],
262            response: &[HttpBodyFormat::Json],
263        },
264    },
265    OperationSpec {
266        key: OperationKey {
267            operation: Operation::SummarizeMemory,
268            dialect: Dialect::OpenAi,
269        },
270        transport: OperationTransport::Http {
271            request: &[HttpBodyFormat::Json],
272            response: &[HttpBodyFormat::Json],
273        },
274    },
275    OperationSpec {
276        key: OperationKey {
277            operation: Operation::CreateConversation,
278            dialect: Dialect::OpenAi,
279        },
280        transport: OperationTransport::Http {
281            request: &[HttpBodyFormat::Json],
282            response: &[HttpBodyFormat::Json],
283        },
284    },
285    OperationSpec {
286        key: OperationKey {
287            operation: Operation::WebSearch,
288            dialect: Dialect::OpenAi,
289        },
290        transport: OperationTransport::Http {
291            request: &[HttpBodyFormat::Json],
292            response: &[HttpBodyFormat::Json],
293        },
294    },
295    OperationSpec {
296        key: OperationKey {
297            operation: Operation::Rerank,
298            dialect: Dialect::OpenAi,
299        },
300        transport: OperationTransport::Http {
301            request: &[HttpBodyFormat::Json],
302            response: &[HttpBodyFormat::Json],
303        },
304    },
305    OperationSpec {
306        key: OperationKey {
307            operation: Operation::CreateEmbedding,
308            dialect: Dialect::OpenAi,
309        },
310        transport: OperationTransport::Http {
311            request: &[HttpBodyFormat::Json],
312            response: &[HttpBodyFormat::Json],
313        },
314    },
315    OperationSpec {
316        key: OperationKey {
317            operation: Operation::CreateEmbedding,
318            dialect: Dialect::Gemini,
319        },
320        transport: OperationTransport::Http {
321            request: &[HttpBodyFormat::Json],
322            response: &[HttpBodyFormat::Json],
323        },
324    },
325    OperationSpec {
326        key: OperationKey {
327            operation: Operation::BatchCreateEmbedding,
328            dialect: Dialect::Gemini,
329        },
330        transport: OperationTransport::Http {
331            request: &[HttpBodyFormat::Json],
332            response: &[HttpBodyFormat::Json],
333        },
334    },
335    OperationSpec {
336        key: OperationKey {
337            operation: Operation::CreateImage,
338            dialect: Dialect::OpenAi,
339        },
340        transport: OperationTransport::Http {
341            request: &[HttpBodyFormat::Json],
342            response: &[
343                HttpBodyFormat::Json,
344                HttpBodyFormat::JsonStream(StreamFraming::Sse),
345            ],
346        },
347    },
348    OperationSpec {
349        key: OperationKey {
350            operation: Operation::EditImage,
351            dialect: Dialect::OpenAi,
352        },
353        transport: OperationTransport::Http {
354            request: &[HttpBodyFormat::Json, HttpBodyFormat::Multipart],
355            response: &[
356                HttpBodyFormat::Json,
357                HttpBodyFormat::JsonStream(StreamFraming::Sse),
358            ],
359        },
360    },
361    OperationSpec {
362        key: OperationKey {
363            operation: Operation::CreateSpeech,
364            dialect: Dialect::OpenAi,
365        },
366        transport: OperationTransport::Http {
367            request: &[HttpBodyFormat::Json],
368            response: &[
369                HttpBodyFormat::Binary,
370                HttpBodyFormat::JsonStream(StreamFraming::Sse),
371            ],
372        },
373    },
374    OperationSpec {
375        key: OperationKey {
376            operation: Operation::CreateTranscription,
377            dialect: Dialect::OpenAi,
378        },
379        transport: OperationTransport::Http {
380            request: &[HttpBodyFormat::Multipart],
381            response: &[
382                HttpBodyFormat::Json,
383                HttpBodyFormat::Text,
384                HttpBodyFormat::JsonStream(StreamFraming::Sse),
385            ],
386        },
387    },
388    OperationSpec {
389        key: OperationKey {
390            operation: Operation::CreateTranslation,
391            dialect: Dialect::OpenAi,
392        },
393        transport: OperationTransport::Http {
394            request: &[HttpBodyFormat::Multipart],
395            response: &[HttpBodyFormat::Json, HttpBodyFormat::Text],
396        },
397    },
398    OperationSpec {
399        key: OperationKey {
400            operation: Operation::CreateFile,
401            dialect: Dialect::OpenAi,
402        },
403        transport: OperationTransport::Http {
404            request: &[HttpBodyFormat::Multipart],
405            response: &[HttpBodyFormat::Json],
406        },
407    },
408    OperationSpec {
409        key: OperationKey {
410            operation: Operation::CreateFile,
411            dialect: Dialect::Claude,
412        },
413        transport: OperationTransport::Http {
414            request: &[HttpBodyFormat::Multipart],
415            response: &[HttpBodyFormat::Json],
416        },
417    },
418    OperationSpec {
419        key: OperationKey {
420            operation: Operation::CreateFile,
421            dialect: Dialect::Gemini,
422        },
423        transport: OperationTransport::Http {
424            request: &[
425                HttpBodyFormat::Multipart,
426                HttpBodyFormat::Json,
427                HttpBodyFormat::Binary,
428            ],
429            response: &[HttpBodyFormat::Json, HttpBodyFormat::Empty],
430        },
431    },
432    OperationSpec {
433        key: OperationKey {
434            operation: Operation::ListFiles,
435            dialect: Dialect::OpenAi,
436        },
437        transport: OperationTransport::Http {
438            request: &[HttpBodyFormat::Empty],
439            response: &[HttpBodyFormat::Json],
440        },
441    },
442    OperationSpec {
443        key: OperationKey {
444            operation: Operation::ListFiles,
445            dialect: Dialect::Claude,
446        },
447        transport: OperationTransport::Http {
448            request: &[HttpBodyFormat::Empty],
449            response: &[HttpBodyFormat::Json],
450        },
451    },
452    OperationSpec {
453        key: OperationKey {
454            operation: Operation::ListFiles,
455            dialect: Dialect::Gemini,
456        },
457        transport: OperationTransport::Http {
458            request: &[HttpBodyFormat::Empty],
459            response: &[HttpBodyFormat::Json],
460        },
461    },
462    OperationSpec {
463        key: OperationKey {
464            operation: Operation::RetrieveFile,
465            dialect: Dialect::OpenAi,
466        },
467        transport: OperationTransport::Http {
468            request: &[HttpBodyFormat::Empty],
469            response: &[HttpBodyFormat::Json],
470        },
471    },
472    OperationSpec {
473        key: OperationKey {
474            operation: Operation::RetrieveFile,
475            dialect: Dialect::Claude,
476        },
477        transport: OperationTransport::Http {
478            request: &[HttpBodyFormat::Empty],
479            response: &[HttpBodyFormat::Json],
480        },
481    },
482    OperationSpec {
483        key: OperationKey {
484            operation: Operation::RetrieveFile,
485            dialect: Dialect::Gemini,
486        },
487        transport: OperationTransport::Http {
488            request: &[HttpBodyFormat::Empty],
489            response: &[HttpBodyFormat::Json],
490        },
491    },
492    OperationSpec {
493        key: OperationKey {
494            operation: Operation::RetrieveFileContent,
495            dialect: Dialect::OpenAi,
496        },
497        transport: OperationTransport::Http {
498            request: &[HttpBodyFormat::Empty],
499            response: &[HttpBodyFormat::Binary],
500        },
501    },
502    OperationSpec {
503        key: OperationKey {
504            operation: Operation::RetrieveFileContent,
505            dialect: Dialect::Claude,
506        },
507        transport: OperationTransport::Http {
508            request: &[HttpBodyFormat::Empty],
509            response: &[HttpBodyFormat::Binary],
510        },
511    },
512    OperationSpec {
513        key: OperationKey {
514            operation: Operation::RetrieveFileContent,
515            dialect: Dialect::Gemini,
516        },
517        transport: OperationTransport::Http {
518            request: &[HttpBodyFormat::Empty],
519            response: &[HttpBodyFormat::Binary],
520        },
521    },
522    OperationSpec {
523        key: OperationKey {
524            operation: Operation::DeleteFile,
525            dialect: Dialect::OpenAi,
526        },
527        transport: OperationTransport::Http {
528            request: &[HttpBodyFormat::Empty],
529            response: &[HttpBodyFormat::Json],
530        },
531    },
532    OperationSpec {
533        key: OperationKey {
534            operation: Operation::DeleteFile,
535            dialect: Dialect::Claude,
536        },
537        transport: OperationTransport::Http {
538            request: &[HttpBodyFormat::Empty],
539            response: &[HttpBodyFormat::Json],
540        },
541    },
542    OperationSpec {
543        key: OperationKey {
544            operation: Operation::DeleteFile,
545            dialect: Dialect::Gemini,
546        },
547        transport: OperationTransport::Http {
548            request: &[HttpBodyFormat::Empty],
549            response: &[HttpBodyFormat::Json],
550        },
551    },
552    OperationSpec {
553        key: OperationKey {
554            operation: Operation::CreateVideo,
555            dialect: Dialect::OpenAi,
556        },
557        transport: OperationTransport::Http {
558            request: &[HttpBodyFormat::Json, HttpBodyFormat::Multipart],
559            response: &[HttpBodyFormat::Json],
560        },
561    },
562    OperationSpec {
563        key: OperationKey {
564            operation: Operation::RetrieveVideo,
565            dialect: Dialect::OpenAi,
566        },
567        transport: OperationTransport::Http {
568            request: &[HttpBodyFormat::Empty],
569            response: &[HttpBodyFormat::Json],
570        },
571    },
572    OperationSpec {
573        key: OperationKey {
574            operation: Operation::ListVideos,
575            dialect: Dialect::OpenAi,
576        },
577        transport: OperationTransport::Http {
578            request: &[HttpBodyFormat::Empty],
579            response: &[HttpBodyFormat::Json],
580        },
581    },
582    OperationSpec {
583        key: OperationKey {
584            operation: Operation::DeleteVideo,
585            dialect: Dialect::OpenAi,
586        },
587        transport: OperationTransport::Http {
588            request: &[HttpBodyFormat::Empty],
589            response: &[HttpBodyFormat::Json],
590        },
591    },
592    OperationSpec {
593        key: OperationKey {
594            operation: Operation::DownloadVideoContent,
595            dialect: Dialect::OpenAi,
596        },
597        transport: OperationTransport::Http {
598            request: &[HttpBodyFormat::Empty],
599            response: &[HttpBodyFormat::Binary],
600        },
601    },
602    OperationSpec {
603        key: OperationKey {
604            operation: Operation::CreateRealtimeCall,
605            dialect: Dialect::OpenAi,
606        },
607        transport: OperationTransport::Http {
608            request: &[HttpBodyFormat::Multipart],
609            response: &[HttpBodyFormat::Text],
610        },
611    },
612    OperationSpec {
613        key: OperationKey {
614            operation: Operation::GenerateContent,
615            dialect: Dialect::OpenAiResponsesWebSocket,
616        },
617        transport: OperationTransport::WebSocket,
618    },
619    OperationSpec {
620        key: OperationKey {
621            operation: Operation::StreamGenerateContent,
622            dialect: Dialect::OpenAiResponsesWebSocket,
623        },
624        transport: OperationTransport::WebSocket,
625    },
626    OperationSpec {
627        key: OperationKey {
628            operation: Operation::ConnectRealtime,
629            dialect: Dialect::OpenAi,
630        },
631        transport: OperationTransport::WebSocket,
632    },
633    OperationSpec {
634        key: OperationKey {
635            operation: Operation::ConnectRealtime,
636            dialect: Dialect::Gemini,
637        },
638        transport: OperationTransport::WebSocket,
639    },
640];