endpointspec

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package endpointspec defines the EndpointSpec which is to bundle the translator, tracing and most importantly request and response types for different API endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatCompletionsEndpointSpec

type ChatCompletionsEndpointSpec struct{}

ChatCompletionsEndpointSpec implements EndpointSpec for /v1/chat/completions.

func (ChatCompletionsEndpointSpec) GetTranslator

func (ChatCompletionsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIChatCompletionTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (ChatCompletionsEndpointSpec) ParseBody

func (ChatCompletionsEndpointSpec) ParseBody(
	body []byte,
	costConfigured bool,
) (internalapi.OriginalModel, *openai.ChatCompletionRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (ChatCompletionsEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (ChatCompletionsEndpointSpec) RedactSensitiveInfoFromRequest(req *openai.ChatCompletionRequest) (redactedReq *openai.ChatCompletionRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type CompletionsEndpointSpec

type CompletionsEndpointSpec struct{}

CompletionsEndpointSpec implements EndpointSpec for /v1/completions.

func (CompletionsEndpointSpec) GetTranslator

func (CompletionsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAICompletionTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (CompletionsEndpointSpec) ParseBody

func (CompletionsEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.CompletionRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (CompletionsEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (CompletionsEndpointSpec) RedactSensitiveInfoFromRequest(req *openai.CompletionRequest) (redactedReq *openai.CompletionRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type EmbeddingsEndpointSpec

type EmbeddingsEndpointSpec struct{}

EmbeddingsEndpointSpec implements EndpointSpec for /v1/embeddings.

func (EmbeddingsEndpointSpec) GetTranslator

func (EmbeddingsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIEmbeddingTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (EmbeddingsEndpointSpec) ParseBody

func (EmbeddingsEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.EmbeddingRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (EmbeddingsEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (EmbeddingsEndpointSpec) RedactSensitiveInfoFromRequest(req *openai.EmbeddingRequest) (redactedReq *openai.EmbeddingRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type ImageGenerationEndpointSpec

type ImageGenerationEndpointSpec struct{}

ImageGenerationEndpointSpec implements EndpointSpec for /v1/images/generations.

func (ImageGenerationEndpointSpec) GetTranslator

func (ImageGenerationEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIImageGenerationTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (ImageGenerationEndpointSpec) ParseBody

func (ImageGenerationEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.ImageGenerationRequest, bool, []byte, error)

func (ImageGenerationEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (ImageGenerationEndpointSpec) RedactSensitiveInfoFromRequest(req *openai.ImageGenerationRequest) (redactedReq *openai.ImageGenerationRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type MessagesEndpointSpec

type MessagesEndpointSpec struct{}

MessagesEndpointSpec implements EndpointSpec for /v1/messages.

func (MessagesEndpointSpec) GetTranslator

func (MessagesEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.AnthropicMessagesTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (MessagesEndpointSpec) ParseBody

func (MessagesEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *anthropic.MessagesRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (MessagesEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (MessagesEndpointSpec) RedactSensitiveInfoFromRequest(req *anthropic.MessagesRequest) (redactedReq *anthropic.MessagesRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type RerankEndpointSpec

type RerankEndpointSpec struct{}

RerankEndpointSpec implements EndpointSpec for /v2/rerank.

func (RerankEndpointSpec) GetTranslator

func (RerankEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.CohereRerankTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (RerankEndpointSpec) ParseBody

func (RerankEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *cohereschema.RerankV2Request, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (RerankEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (RerankEndpointSpec) RedactSensitiveInfoFromRequest(req *cohereschema.RerankV2Request) (redactedReq *cohereschema.RerankV2Request, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type ResponsesEndpointSpec

type ResponsesEndpointSpec struct{}

ResponsesEndpointSpec implements EndpointSpec for /v1/responses.

func (ResponsesEndpointSpec) GetTranslator

func (ResponsesEndpointSpec) GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.OpenAIResponsesTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (ResponsesEndpointSpec) ParseBody

func (ResponsesEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.ResponseRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (ResponsesEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (ResponsesEndpointSpec) RedactSensitiveInfoFromRequest(req *openai.ResponseRequest) (redactedReq *openai.ResponseRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

type Spec

type Spec[ReqT, RespT, RespChunkT any] interface {
	// ParseBody parses the request body and returns the original model,
	// the parsed request, whether the request is streaming, any mutated body,
	// and an error if parsing fails.
	//
	// Parameters:
	// * body: The raw request body as a byte slice.
	// * costConfigured: A boolean indicating if cost metrics are configured.
	//
	// Returns:
	// * originalModel: The original model specified in the request.
	// * req: The parsed request of type ReqT.
	// * stream: A boolean indicating if the request is for streaming responses.
	// * mutatedBody: The possibly mutated request body as a byte slice. Or nil if no mutation is needed.
	// * err: An error if parsing fails.
	ParseBody(body []byte, costConfigured bool) (originalModel internalapi.OriginalModel, req *ReqT, stream bool, mutatedBody []byte, err error)
	// GetTranslator selects the appropriate translator based on the output API schema
	// and an optional model name override.
	//
	// Parameters:
	// * out: The output API schema for which the translator is needed.
	// * modelNameOverride: An optional model name to override the one specified in the request.
	//
	// Returns:
	// * translator: The selected translator of type Translator[ReqT, RespT, RespChunkT].
	// * err: An error if translator selection fails.
	GetTranslator(schema filterapi.VersionedAPISchema, modelNameOverride string) (translator.Translator[ReqT, tracingapi.Span[RespT, RespChunkT]], error)
	// RedactSensitiveInfoFromRequest creates a redacted copy of the request for safe debug logging.
	// Sensitive content (messages, images, audio, tool parameters, etc.) is replaced with placeholders
	// containing length and hash information to aid in debugging cache hits/misses and correlation.
	//
	// The returned request preserves the structure but removes actual sensitive data, making it
	// safe to include in logs. It should NOT be used for actual AI provider requests.
	//
	// Parameters:
	// * req: The original request to redact.
	//
	// Returns:
	// * redactedReq: A copy with sensitive fields replaced by [REDACTED LENGTH=n HASH=xxxx] placeholders.
	// * err: An error if redaction fails (implementation-specific).
	RedactSensitiveInfoFromRequest(req *ReqT) (redactedReq *ReqT, err error)
}

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 custom logic for parsing and translation.

type SpeechEndpointSpec added in v0.6.0

type SpeechEndpointSpec struct{}

SpeechEndpointSpec implements EndpointSpec for /v1/audio/speech.

func (SpeechEndpointSpec) GetTranslator added in v0.6.0

func (SpeechEndpointSpec) GetTranslator(
	schema filterapi.VersionedAPISchema,
	modelNameOverride string,
) (translator.OpenAISpeechTranslator, error)

GetTranslator implements [EndpointSpec.GetTranslator].

func (SpeechEndpointSpec) ParseBody added in v0.6.0

func (SpeechEndpointSpec) ParseBody(
	body []byte,
	_ bool,
) (internalapi.OriginalModel, *openai.SpeechRequest, bool, []byte, error)

ParseBody implements [EndpointSpec.ParseBody].

func (SpeechEndpointSpec) RedactSensitiveInfoFromRequest added in v0.6.0

func (SpeechEndpointSpec) RedactSensitiveInfoFromRequest(req *openai.SpeechRequest) (redactedReq *openai.SpeechRequest, err error)

RedactSensitiveInfoFromRequest implements [EndpointSpec.RedactSensitiveInfoFromRequest].

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL