MCPcopy
hub / github.com/envoyproxy/ai-gateway / Spec

Interface Spec

internal/endpointspec/endpointspec.go:44–95  ·  view source on GitHub ↗

Spec defines methods for parsing request bodies and selecting translators for different API endpoints. Type Parameters: * ReqT: The request type. * RespT: The response type. * RespChunkT: The chunk type for streaming responses. This must be implemented by specific endpoint handlers to provide cust

Source from the content-addressed store, hash-verified

42 // This must be implemented by specific endpoint handlers to provide
43 // custom logic for parsing and translation.
44 Spec[ReqT, RespT, RespChunkT any] interface {
45 // ParseBody parses the request body and returns the original model,
46 // the parsed request, whether the request is streaming, any mutated body,
47 // and an error if parsing fails.
48 //
49 // Parameters:
50 // * body: The raw request body as a byte slice.
51 // * costConfigured: A boolean indicating if cost metrics are configured.
52 //
53 // Returns:
54 // * originalModel: The original model specified in the request.
55 // * req: The parsed request of type ReqT.
56 // * stream: A boolean indicating if the request is for streaming responses.
57 // * mutatedBody: The possibly mutated request body as a byte slice. Or nil if no mutation is needed.
58 // * err: An error if parsing fails.
59 ParseBody(body []byte, costConfigured bool) (originalModel internalapi.OriginalModel, req *ReqT, stream bool, mutatedBody []byte, err error)
60 // GetTranslator selects the appropriate translator based on the output API schema
61 // and an optional model name override.
62 //
63 // Parameters:
64 // * out: The output API schema for which the translator is needed.
65 // * modelNameOverride: An optional model name to override the one specified in the request.
66 //
67 // Returns:
68 // * translator: The selected translator of type Translator[ReqT, RespT, RespChunkT].
69 // * err: An error if translator selection fails.
70 GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.Translator[ReqT, tracingapi.Span[RespT, RespChunkT]], error)
71 // RedactSensitiveInfoFromRequest creates a redacted copy of the request for safe debug logging.
72 // Sensitive content (messages, images, audio, tool parameters, etc.) is replaced with placeholders
73 // containing length and hash information to aid in debugging cache hits/misses and correlation.
74 //
75 // The returned request preserves the structure but removes actual sensitive data, making it
76 // safe to include in logs. It should NOT be used for actual AI provider requests.
77 //
78 // Parameters:
79 // * req: The original request to redact.
80 //
81 // Returns:
82 // * redactedReq: A copy with sensitive fields replaced by [REDACTED LENGTH=n HASH=xxxx] placeholders.
83 // * err: An error if redaction fails (implementation-specific).
84 RedactSensitiveInfoFromRequest(req *ReqT) (redactedReq *ReqT, err error)
85 // ParseMultipartBody parses a multipart/form-data request body.
86 // Endpoints that don't support multipart should return an error.
87 //
88 // Parameters:
89 // * body: The raw multipart request body.
90 // * contentType: The Content-Type header value (includes boundary parameter).
91 // * costConfigured: A boolean indicating if cost metrics are configured.
92 //
93 // Returns the same tuple as ParseBody.
94 ParseMultipartBody(body []byte, contentType string, costConfigured bool) (originalModel internalapi.OriginalModel, req *ReqT, stream bool, mutatedBody []byte, err error)
95 }
96 // ChatCompletionsEndpointSpec implements EndpointSpec for /v1/chat/completions.
97 ChatCompletionsEndpointSpec struct{}
98 // CompletionsEndpointSpec implements EndpointSpec for /v1/completions.

Callers 5

ProcessRequestBodyMethod · 0.65
SetBackendMethod · 0.65
ProcessRequestBodyMethod · 0.65
ProcessRequestBodyMethod · 0.65

Implementers 10

ChatCompletionsEndpointSpecinternal/endpointspec/endpointspec.go
CompletionsEndpointSpecinternal/endpointspec/endpointspec.go
EmbeddingsEndpointSpecinternal/endpointspec/endpointspec.go
ImageGenerationEndpointSpecinternal/endpointspec/endpointspec.go
ResponsesEndpointSpecinternal/endpointspec/endpointspec.go
MessagesEndpointSpecinternal/endpointspec/endpointspec.go
RerankEndpointSpecinternal/endpointspec/endpointspec.go
SpeechEndpointSpecinternal/endpointspec/endpointspec.go
TranscriptionEndpointSpecinternal/endpointspec/endpointspec.go
TranslationEndpointSpecinternal/endpointspec/endpointspec.go

Calls

no outgoing calls

Tested by

no test coverage detected