Documentation
¶
Index ¶
Constants ¶
const ( APITypeOpenAI = iota APITypeAnthropic APITypePaLM APITypeBaidu APITypeZhipu APITypeAli APITypeXunfei APITypeAIProxyLibrary APITypeTencent APITypeGemini APITypeZhipuV4 APITypeOllama APITypePerplexity APITypeAws APITypeCohere APITypeDify APITypeJina APITypeCloudflare APITypeSiliconFlow APITypeVertexAi APITypeMistral APITypeDeepSeek APITypeMokaAI APITypeVolcEngine APITypeBaiduV2 APITypeOpenRouter APITypeXinference APITypeXai APITypeCoze APITypeJimeng APITypeMoonshot APITypeSubmodel APITypeMiniMax APITypeReplicate APITypeCodex APITypeAdvancedCustom APITypeDummy // this one is only for count, do not add any channel after this )
const ( UserGroupKeyFmt = "user_group:%d" UserQuotaKeyFmt = "user_quota:%d" UserEnabledKeyFmt = "user_enabled:%d" UserUsernameKeyFmt = "user_name:%d" )
Cache keys
const ( TokenFiledRemainQuota = "RemainQuota" TokenFieldGroup = "Group" )
const ( ChannelTypeUnknown = 0 ChannelTypeOpenAI = 1 ChannelTypeMidjourney = 2 ChannelTypeAzure = 3 ChannelTypeOllama = 4 ChannelTypeMidjourneyPlus = 5 ChannelTypeOpenAIMax = 6 ChannelTypeOhMyGPT = 7 ChannelTypeCustom = 8 ChannelTypeAILS = 9 ChannelTypeAIProxy = 10 ChannelTypePaLM = 11 ChannelTypeAPI2GPT = 12 ChannelTypeAIGC2D = 13 ChannelTypeAnthropic = 14 ChannelTypeBaidu = 15 ChannelTypeZhipu = 16 ChannelTypeAli = 17 ChannelTypeXunfei = 18 ChannelType360 = 19 ChannelTypeOpenRouter = 20 ChannelTypeAIProxyLibrary = 21 ChannelTypeFastGPT = 22 ChannelTypeTencent = 23 ChannelTypeGemini = 24 ChannelTypeMoonshot = 25 ChannelTypeZhipu_v4 = 26 ChannelTypePerplexity = 27 ChannelTypeLingYiWanWu = 31 ChannelTypeAws = 33 ChannelTypeCohere = 34 ChannelTypeMiniMax = 35 ChannelTypeSunoAPI = 36 ChannelTypeDify = 37 ChannelTypeJina = 38 ChannelCloudflare = 39 ChannelTypeSiliconFlow = 40 ChannelTypeVertexAi = 41 ChannelTypeMistral = 42 ChannelTypeDeepSeek = 43 ChannelTypeMokaAI = 44 ChannelTypeVolcEngine = 45 ChannelTypeBaiduV2 = 46 ChannelTypeXinference = 47 ChannelTypeXai = 48 ChannelTypeCoze = 49 ChannelTypeKling = 50 ChannelTypeJimeng = 51 ChannelTypeVidu = 52 ChannelTypeSubmodel = 53 ChannelTypeDoubaoVideo = 54 ChannelTypeSora = 55 ChannelTypeReplicate = 56 ChannelTypeCodex = 57 ChannelTypeAdvancedCustom = 58 ChannelTypeDummy // this one is only for count, do not add any channel after this )
const ( DefaultStreamingTimeout = 300 DefaultMaxFileDownloadMB = 64 DefaultStreamScannerMaxBufferMB = 128 DefaultMaxRequestBodyMB = 128 DefaultAnonymousRequestBodyLimitKB = 512 DefaultAzureDefaultAPIVersion = "2025-04-01-preview" DefaultNotifyLimitCount = 2 DefaultNotificationLimitDurationMinute = 10 DefaultTaskQueryLimit = 1000 DefaultTaskTimeoutMinutes = 1440 DefaultDifyDebug = true DefaultForceStreamOption = true DefaultCountToken = true DefaultGetMediaToken = true DefaultGetMediaTokenNotStream = false DefaultUpdateTask = true DefaultGenerateDefaultToken = false DefaultErrorLogEnabled = false )
const ( MjErrorUnknown = 5 MjRequestError = 4 )
const ( MjActionImagine = "IMAGINE" MjActionDescribe = "DESCRIBE" MjActionBlend = "BLEND" MjActionUpscale = "UPSCALE" MjActionVariation = "VARIATION" MjActionReRoll = "REROLL" MjActionInPaint = "INPAINT" MjActionModal = "MODAL" MjActionZoom = "ZOOM" MjActionCustomZoom = "CUSTOM_ZOOM" MjActionShorten = "SHORTEN" MjActionHighVariation = "HIGH_VARIATION" MjActionLowVariation = "LOW_VARIATION" MjActionPan = "PAN" MjActionSwapFace = "SWAP_FACE" MjActionUpload = "UPLOAD" MjActionVideo = "VIDEO" MjActionEdits = "EDITS" )
const ( SunoActionMusic = "MUSIC" SunoActionLyrics = "LYRICS" TaskActionGenerate = "generate" TaskActionTextGenerate = "textGenerate" TaskActionFirstTailGenerate = "firstTailGenerate" TaskActionReferenceGenerate = "referenceGenerate" TaskActionRemix = "remixGenerate" TaskActionKlingOmniVideo = "klingOmniVideo" )
Variables ¶
var ( FinishReasonStop = "stop" FinishReasonToolCalls = "tool_calls" FinishReasonLength = "length" FinishReasonFunctionCall = "function_call" FinishReasonContentFilter = "content_filter" )
var AnonymousRequestBodyLimitKB = DefaultAnonymousRequestBodyLimitKB
var AzureDefaultAPIVersion = DefaultAzureDefaultAPIVersion
var ChannelBaseURLs = []string{
"",
"https://api.openai.com",
"https://oa.api2d.net",
"",
"http://localhost:11434",
"https://api.openai-sb.com",
"https://api.openaimax.com",
"https://api.ohmygpt.com",
"",
"https://api.caipacity.com",
"https://api.aiproxy.io",
"",
"https://api.api2gpt.com",
"https://api.aigc2d.com",
"https://api.anthropic.com",
"https://aip.baidubce.com",
"https://open.bigmodel.cn",
"https://dashscope.aliyuncs.com",
"",
"https://api.360.cn",
"https://openrouter.ai/api",
"https://api.aiproxy.io",
"https://fastgpt.run/api/openapi",
"https://hunyuan.tencentcloudapi.com",
"https://generativelanguage.googleapis.com",
"https://api.moonshot.cn",
"https://open.bigmodel.cn",
"https://api.perplexity.ai",
"",
"",
"",
"https://api.lingyiwanwu.com",
"",
"",
"https://api.cohere.ai",
"https://api.minimax.chat",
"",
"https://api.dify.ai",
"https://api.jina.ai",
"https://api.cloudflare.com",
"https://api.siliconflow.cn",
"",
"https://api.mistral.ai",
"https://api.deepseek.com",
"https://api.moka.ai",
"https://ark.cn-beijing.volces.com",
"https://qianfan.baidubce.com",
"",
"https://api.x.ai",
"https://api.coze.cn",
"https://api.klingai.com",
"https://visual.volcengineapi.com",
"https://api.vidu.cn",
"https://llm.submodel.ai",
"https://ark.cn-beijing.volces.com",
"https://api.openai.com",
"https://api.replicate.com",
"https://chatgpt.com",
"",
}
var ChannelSpecialBases = map[string]ChannelSpecialBase{
"glm-coding-plan": {
ClaudeBaseURL: "https://open.bigmodel.cn/api/anthropic",
OpenAIBaseURL: "https://open.bigmodel.cn/api/coding/paas/v4",
},
"glm-coding-plan-international": {
ClaudeBaseURL: "https://api.z.ai/api/anthropic",
OpenAIBaseURL: "https://api.z.ai/api/coding/paas/v4",
},
"kimi-coding-plan": {
ClaudeBaseURL: "https://api.kimi.com/coding",
OpenAIBaseURL: "https://api.kimi.com/coding/v1",
},
"doubao-coding-plan": {
ClaudeBaseURL: "https://ark.cn-beijing.volces.com/api/coding",
OpenAIBaseURL: "https://ark.cn-beijing.volces.com/api/coding/v3",
},
}
var ChannelTypeNames = map[int]string{ ChannelTypeUnknown: "Unknown", ChannelTypeOpenAI: "OpenAI", ChannelTypeMidjourney: "Midjourney", ChannelTypeAzure: "Azure", ChannelTypeOllama: "Ollama", ChannelTypeMidjourneyPlus: "MidjourneyPlus", ChannelTypeOpenAIMax: "OpenAIMax", ChannelTypeOhMyGPT: "OhMyGPT", ChannelTypeCustom: "Custom", ChannelTypeAILS: "AILS", ChannelTypeAIProxy: "AIProxy", ChannelTypePaLM: "PaLM", ChannelTypeAPI2GPT: "API2GPT", ChannelTypeAIGC2D: "AIGC2D", ChannelTypeAnthropic: "Anthropic", ChannelTypeBaidu: "Baidu", ChannelTypeZhipu: "Zhipu", ChannelTypeAli: "Ali", ChannelTypeXunfei: "Xunfei", ChannelType360: "360", ChannelTypeOpenRouter: "OpenRouter", ChannelTypeAIProxyLibrary: "AIProxyLibrary", ChannelTypeFastGPT: "FastGPT", ChannelTypeTencent: "Tencent", ChannelTypeGemini: "Gemini", ChannelTypeMoonshot: "Moonshot", ChannelTypeZhipu_v4: "ZhipuV4", ChannelTypePerplexity: "Perplexity", ChannelTypeLingYiWanWu: "LingYiWanWu", ChannelTypeAws: "AWS", ChannelTypeCohere: "Cohere", ChannelTypeMiniMax: "MiniMax", ChannelTypeSunoAPI: "SunoAPI", ChannelTypeDify: "Dify", ChannelTypeJina: "Jina", ChannelCloudflare: "Cloudflare", ChannelTypeSiliconFlow: "SiliconFlow", ChannelTypeVertexAi: "VertexAI", ChannelTypeMistral: "Mistral", ChannelTypeDeepSeek: "DeepSeek", ChannelTypeMokaAI: "MokaAI", ChannelTypeVolcEngine: "VolcEngine", ChannelTypeBaiduV2: "BaiduV2", ChannelTypeXinference: "Xinference", ChannelTypeXai: "xAI", ChannelTypeCoze: "Coze", ChannelTypeKling: "Kling", ChannelTypeJimeng: "Jimeng", ChannelTypeVidu: "Vidu", ChannelTypeSubmodel: "Submodel", ChannelTypeDoubaoVideo: "DoubaoVideo", ChannelTypeSora: "Sora", ChannelTypeReplicate: "Replicate", ChannelTypeCodex: "Codex", ChannelTypeAdvancedCustom: "Advanced Custom", }
var CountToken = DefaultCountToken
var DefaultWaffoPayMethods = []WaffoPayMethod{
{Name: "Card", Icon: "/pay-card.png", PayMethodType: "CREDITCARD,DEBITCARD", PayMethodName: ""},
{Name: "Apple Pay", Icon: "/pay-apple.png", PayMethodType: "APPLEPAY", PayMethodName: "APPLEPAY"},
{Name: "Google Pay", Icon: "/pay-google.png", PayMethodType: "GOOGLEPAY", PayMethodName: "GOOGLEPAY"},
}
DefaultWaffoPayMethods is the default list of supported payment methods.
var DifyDebug = DefaultDifyDebug
var ErrorLogEnabled = DefaultErrorLogEnabled
var ForceStreamOption = DefaultForceStreamOption
var GenerateDefaultToken = DefaultGenerateDefaultToken
var GetMediaToken = DefaultGetMediaToken
var GetMediaTokenNotStream = DefaultGetMediaTokenNotStream
var MaxFileDownloadMB = DefaultMaxFileDownloadMB
var MaxRequestBodyMB = DefaultMaxRequestBodyMB
var MidjourneyModel2Action = map[string]string{ "mj_imagine": MjActionImagine, "mj_describe": MjActionDescribe, "mj_blend": MjActionBlend, "mj_upscale": MjActionUpscale, "mj_variation": MjActionVariation, "mj_reroll": MjActionReRoll, "mj_modal": MjActionModal, "mj_inpaint": MjActionInPaint, "mj_zoom": MjActionZoom, "mj_custom_zoom": MjActionCustomZoom, "mj_shorten": MjActionShorten, "mj_high_variation": MjActionHighVariation, "mj_low_variation": MjActionLowVariation, "mj_pan": MjActionPan, "swap_face": MjActionSwapFace, "mj_upload": MjActionUpload, "mj_video": MjActionVideo, "mj_edits": MjActionEdits, }
var NotificationLimitDurationMinute = DefaultNotificationLimitDurationMinute
var NotifyLimitCount = DefaultNotifyLimitCount
var Setup = false
var StreamScannerMaxBufferMB = DefaultStreamScannerMaxBufferMB
var StreamingTimeout = DefaultStreamingTimeout
var SunoModel2Action = map[string]string{ "suno_music": SunoActionMusic, "suno_lyrics": SunoActionLyrics, }
var TaskPricePatches []string
temporary variable for sora patch, will be removed in future
var TaskQueryLimit = DefaultTaskQueryLimit
var TaskTimeoutMinutes = DefaultTaskTimeoutMinutes
var TrustedRedirectDomains []string
TrustedRedirectDomains is a list of trusted domains for redirect URL validation. Domains support subdomain matching (e.g., "example.com" matches "sub.example.com").
var UpdateTask = DefaultUpdateTask
Functions ¶
func GetChannelTypeName ¶
Types ¶
type ChannelSpecialBase ¶
type ContextKey ¶
type ContextKey string
const ( ContextKeyTokenCountMeta ContextKey = "token_count_meta" ContextKeyPromptTokens ContextKey = "prompt_tokens" ContextKeyEstimatedTokens ContextKey = "estimated_tokens" ContextKeyOriginalModel ContextKey = "original_model" ContextKeyRequestStartTime ContextKey = "request_start_time" /* token related keys */ ContextKeyTokenUnlimited ContextKey = "token_unlimited_quota" ContextKeyTokenKey ContextKey = "token_key" ContextKeyTokenId ContextKey = "token_id" ContextKeyTokenGroup ContextKey = "token_group" ContextKeyTokenSpecificChannelId ContextKey = "specific_channel_id" ContextKeyTokenModelLimitEnabled ContextKey = "token_model_limit_enabled" ContextKeyTokenModelLimit ContextKey = "token_model_limit" ContextKeyTokenCrossGroupRetry ContextKey = "token_cross_group_retry" ContextKeyTokenRoutingPolicy ContextKey = "token_routing_policy" ContextKeyTokenRoutePlan ContextKey = "token_route_plan" /* channel related keys */ ContextKeyChannelId ContextKey = "channel_id" ContextKeyChannelName ContextKey = "channel_name" ContextKeyChannelCreateTime ContextKey = "channel_create_time" ContextKeyChannelBaseUrl ContextKey = "base_url" ContextKeyChannelType ContextKey = "channel_type" ContextKeyChannelSetting ContextKey = "channel_setting" ContextKeyChannelOtherSetting ContextKey = "channel_other_setting" ContextKeyChannelParamOverride ContextKey = "param_override" ContextKeyChannelHeaderOverride ContextKey = "header_override" ContextKeyChannelOrganization ContextKey = "channel_organization" ContextKeyChannelAutoBan ContextKey = "auto_ban" ContextKeyChannelModelMapping ContextKey = "model_mapping" ContextKeyChannelStatusCodeMapping ContextKey = "status_code_mapping" ContextKeyChannelIsMultiKey ContextKey = "channel_is_multi_key" ContextKeyChannelMultiKeyIndex ContextKey = "channel_multi_key_index" ContextKeyChannelKey ContextKey = "channel_key" ContextKeyAutoGroup ContextKey = "auto_group" ContextKeyAutoGroupIndex ContextKey = "auto_group_index" ContextKeyAutoGroupRetryIndex ContextKey = "auto_group_retry_index" /* user related keys */ ContextKeyUserId ContextKey = "id" ContextKeyUserSetting ContextKey = "user_setting" ContextKeyUserQuota ContextKey = "user_quota" ContextKeyUserStatus ContextKey = "user_status" ContextKeyUserEmail ContextKey = "user_email" ContextKeyUserGroup ContextKey = "user_group" ContextKeyUsingGroup ContextKey = "group" ContextKeyUserName ContextKey = "username" ContextKeyLocalCountTokens ContextKey = "local_count_tokens" ContextKeySystemPromptOverride ContextKey = "system_prompt_override" ContextKeyEmptyCompletionInfo ContextKey = "empty_completion_info" // ContextKeyFileSourcesToCleanup stores file sources that need cleanup when request ends ContextKeyFileSourcesToCleanup ContextKey = "file_sources_to_cleanup" // ContextKeyAdminRejectReason stores an admin-only reject/block reason extracted from upstream responses. // It is not returned to end users, but can be persisted into consume/error logs for debugging. ContextKeyAdminRejectReason ContextKey = "admin_reject_reason" // ContextKeyLanguage stores the user's language preference for i18n ContextKeyLanguage ContextKey = "language" ContextKeyIsStream ContextKey = "is_stream" // ContextKeyAuditLogged marks that the current request has already recorded // a structured audit log in the handler. AdminAuth/RootAuth use it to skip // fallback audit logging and avoid duplicate entries. ContextKeyAuditLogged ContextKey = "audit_logged" // ContextKeyAuditWrapped marks that the response writer is already wrapped // for fallback admin audit logging. Nested AdminAuth/RootAuth middleware // must not install a second wrapper for the same request. ContextKeyAuditWrapped ContextKey = "audit_wrapped" )
type EndpointType ¶
type EndpointType string
const ( EndpointTypeOpenAI EndpointType = "openai" EndpointTypeOpenAIResponse EndpointType = "openai-response" EndpointTypeOpenAIResponseCompact EndpointType = "openai-response-compact" EndpointTypeOpenAIAlphaSearch EndpointType = "openai-alpha-search" EndpointTypeAnthropic EndpointType = "anthropic" EndpointTypeGemini EndpointType = "gemini" EndpointTypeJinaRerank EndpointType = "jina-rerank" EndpointTypeImageGeneration EndpointType = "image-generation" EndpointTypeEmbeddings EndpointType = "embeddings" EndpointTypeOpenAIVideo EndpointType = "openai-video" )
type MultiKeyMode ¶
type MultiKeyMode string
const ( MultiKeyModeRandom MultiKeyMode = "random" // 随机 MultiKeyModePolling MultiKeyMode = "polling" // 轮询 )
type TaskPlatform ¶
type TaskPlatform string
const ( TaskPlatformSuno TaskPlatform = "suno" TaskPlatformMidjourney = "mj" )
type WaffoPayMethod ¶
type WaffoPayMethod struct {
Name string `json:"name"` // Frontend display name
Icon string `json:"icon"` // Frontend icon identifier: credit-card, apple, google
PayMethodType string `json:"payMethodType"` // Waffo API PayMethodType, can be comma-separated
PayMethodName string `json:"payMethodName"` // Waffo API PayMethodName, empty means auto-select by Waffo checkout
}
WaffoPayMethod defines the display and API parameter mapping for Waffo payment methods.