Documentation
¶
Index ¶
- Constants
- func ApplyUpstreamBodyMetadata(req *http.Request, body io.Reader)
- func DoApiRequest(a Adaptor, c *gin.Context, info *common.RelayInfo, requestBody io.Reader) (*http.Response, error)
- func DoFormRequest(a Adaptor, c *gin.Context, info *common.RelayInfo, requestBody io.Reader) (*http.Response, error)
- func DoRequest(c *gin.Context, req *http.Request, info *common.RelayInfo) (*http.Response, error)
- func DoTaskApiRequest(a TaskAdaptor, c *gin.Context, info *common.RelayInfo, requestBody io.Reader) (*http.Response, error)
- func DoWssRequest(a Adaptor, c *gin.Context, info *common.RelayInfo, requestBody io.Reader) (*websocket.Conn, error)
- func IsHeaderPassthroughRuleKey(key string) bool
- func IsValidTaskSubmitToken(value string, limit int, allowEmpty bool) bool
- func ResolveHeaderOverride(info *common.RelayInfo, c *gin.Context) (map[string]string, error)
- func SetupApiRequestHeader(info *common.RelayInfo, c *gin.Context, req *http.Header)
- type Adaptor
- type LegacyTaskSubmitResponse
- type OpenAIVideoConverter
- type TaskAdaptor
- type TaskSubmitDisposition
- type TaskSubmitParseInput
- type TaskSubmitParseResult
- type TaskSubmitProblem
- type TaskSubmitResponseParser
Constants ¶
const ( TaskSubmitAccepted TaskSubmitDisposition = "accepted" TaskSubmitRejected TaskSubmitDisposition = "rejected" TaskSubmitUnknown TaskSubmitDisposition = "unknown" TaskSubmitProviderOperationIDMaxLength = 191 TaskSubmitUpstreamRequestIDMaxLength = 128 TaskSubmitOutcomeCodeMaxLength = 64 TaskSubmitProblemMessageMaxLength = 512 TaskSubmitContentTypeMaxLength = 128 MaxTaskSubmitResponseBytes = 1 << 20 )
Variables ¶
This section is empty.
Functions ¶
func ApplyUpstreamBodyMetadata ¶
ApplyUpstreamBodyMetadata restores metadata that net/http cannot infer from a ReplayableBody. Callers must pass the original body because NewRequest hides its dynamic type behind req.Body's io.ReadCloser wrapper.
func DoApiRequest ¶
func DoFormRequest ¶
func DoTaskApiRequest ¶
func DoWssRequest ¶
func IsValidTaskSubmitToken ¶
IsValidTaskSubmitToken reports whether a value is safe to persist as a bounded identifier. Tokens cannot contain whitespace, control characters, or invisible Unicode formatting characters.
func ResolveHeaderOverride ¶
Types ¶
type Adaptor ¶
type Adaptor interface {
// Init IsStream bool
Init(info *relaycommon.RelayInfo)
GetRequestURL(info *relaycommon.RelayInfo) (string, error)
SetupRequestHeader(c *gin.Context, req *http.Header, info *relaycommon.RelayInfo) error
ConvertOpenAIRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeneralOpenAIRequest) (any, error)
ConvertRerankRequest(c *gin.Context, relayMode int, request dto.RerankRequest) (any, error)
ConvertEmbeddingRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.EmbeddingRequest) (any, error)
ConvertAudioRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.AudioRequest) (io.Reader, error)
ConvertImageRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.ImageRequest) (any, error)
ConvertOpenAIResponsesRequest(c *gin.Context, info *relaycommon.RelayInfo, request dto.OpenAIResponsesRequest) (any, error)
DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (any, error)
DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (usage any, err *types.NewAPIError)
GetModelList() []string
GetChannelName() string
ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.ClaudeRequest) (any, error)
ConvertGeminiRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeminiChatRequest) (any, error)
}
type LegacyTaskSubmitResponse ¶
LegacyTaskSubmitResponse preserves the existing client response without giving a parser access to a writable HTTP boundary.
type OpenAIVideoConverter ¶
type TaskAdaptor ¶
type TaskAdaptor interface {
Init(info *relaycommon.RelayInfo)
ValidateRequestAndSetAction(c *gin.Context, info *relaycommon.RelayInfo) *taskdto.TaskError
// EstimateBilling returns OtherRatios for pre-charge based on user request.
// Called after ValidateRequestAndSetAction, before price calculation.
// Adaptors should extract duration, resolution, etc. from the parsed request
// and return them as ratio multipliers (e.g. {"seconds": 5, "size": 1.666}).
// Return nil to use the base model price without extra ratios.
EstimateBilling(c *gin.Context, info *relaycommon.RelayInfo) map[string]float64
// AdjustBillingOnSubmit returns adjusted OtherRatios from the upstream
// submit response. Called after a successful DoResponse.
// If the upstream returned actual parameters that differ from the estimate
// (e.g. actual seconds), return updated ratios so the caller can recalculate
// the quota and settle the delta with the pre-charge.
// Return nil if no adjustment is needed.
AdjustBillingOnSubmit(info *relaycommon.RelayInfo, taskData []byte) map[string]float64
// AdjustBillingOnComplete returns the actual quota when a task reaches a
// terminal state (success/failure) during polling.
// Called by the polling loop after ParseTaskResult.
// Return a positive value to trigger delta settlement (supplement / refund).
// Return 0 to keep the pre-charged amount unchanged.
AdjustBillingOnComplete(task *model.Task, taskResult *relaycommon.TaskInfo) int
BuildRequestURL(info *relaycommon.RelayInfo) (string, error)
BuildRequestHeader(c *gin.Context, req *http.Request, info *relaycommon.RelayInfo) error
BuildRequestBody(c *gin.Context, info *relaycommon.RelayInfo) (io.Reader, error)
DoRequest(c *gin.Context, info *relaycommon.RelayInfo, requestBody io.Reader) (*http.Response, error)
DoResponse(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo) (taskID string, taskData []byte, err *taskdto.TaskError)
GetModelList() []string
GetChannelName() string
FetchTask(baseUrl, key string, body map[string]any, proxy string) (*http.Response, error)
ParseTaskResult(respBody []byte) (*relaycommon.TaskInfo, error)
}
type TaskSubmitDisposition ¶
type TaskSubmitDisposition string
type TaskSubmitParseInput ¶
type TaskSubmitParseInput struct {
HTTPStatus int
Body []byte
UpstreamRequestID string
PublicTaskID string
// OriginPublicTaskID is an already-authorized local task identifier for a
// derived request (for example, a video remix). Parsers must never replace
// it with an upstream source identifier in a client-visible response.
OriginPublicTaskID string
OriginModelName string
ClientModelName string
SubmittedAtUnix int64
}
TaskSubmitParseInput contains only immutable values needed to interpret one upstream response. Time is supplied by the caller to keep parsers deterministic and free of process-global dependencies.
type TaskSubmitParseResult ¶
type TaskSubmitParseResult struct {
Disposition TaskSubmitDisposition
ProviderOperationID string
LegacyPollingID string
UpstreamRequestID string
TaskData []byte
LegacyResponse *LegacyTaskSubmitResponse
Problem *TaskSubmitProblem
}
TaskSubmitParseResult is the complete, side-effect-free interpretation of a single upstream submission response.
func (TaskSubmitParseResult) Validate ¶
func (result TaskSubmitParseResult) Validate() error
type TaskSubmitProblem ¶
TaskSubmitProblem is deliberately safe for client-facing legacy errors. It must contain a bounded diagnostic, never the raw upstream response body.
type TaskSubmitResponseParser ¶
type TaskSubmitResponseParser interface {
ParseTaskSubmitResponse(input TaskSubmitParseInput) TaskSubmitParseResult
}
TaskSubmitResponseParser is the side-effect-free response boundary used by durable task submissions. Implementations must not write an HTTP response or mutate persistence/billing state. It is intentionally separate from TaskAdaptor while providers migrate away from the legacy DoResponse method.
Directories
¶
| Path | Synopsis |
|---|---|
|
task
|
|
|
Package tokenhub contains the provider-neutral configuration contract for TokenHub-compatible gateways.
|
Package tokenhub contains the provider-neutral configuration contract for TokenHub-compatible gateways. |