{"modulePath":"github.com/MAX-API-Next/MAX-API","version":"v1.0.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package types\n\n## Constants\n\n```go\nconst (\n\tRelayFormatOpenAI                    RelayFormat = \"openai\"\n\tRelayFormatClaude                                = \"claude\"\n\tRelayFormatGemini                                = \"gemini\"\n\tRelayFormatOpenAIResponses                       = \"openai_responses\"\n\tRelayFormatOpenAIResponsesCompaction             = \"openai_responses_compaction\"\n\tRelayFormatOpenAIAlphaSearch                     = \"openai_alpha_search\"\n\tRelayFormatOpenAIAudio                           = \"openai_audio\"\n\tRelayFormatOpenAIImage                           = \"openai_image\"\n\tRelayFormatOpenAIRealtime                        = \"openai_realtime\"\n\tRelayFormatRerank                                = \"rerank\"\n\tRelayFormatEmbedding                             = \"embedding\"\n\n\tRelayFormatTask    = \"task\"\n\tRelayFormatMjProxy = \"mj_proxy\"\n)\n```\n\n## Functions\n\n```go\nfunc IsChannelError(err *MaxAPIError) bool\n```\n\n```go\nfunc IsRecordErrorLog(e *MaxAPIError) bool\n```\n\n```go\nfunc IsSkipRetryError(err *MaxAPIError) bool\n```\n\n```go\nfunc LoadFromJsonString[K comparable, V any](m *RWMap[K, V], jsonStr string) error\n```\n\n```go\nfunc LoadFromJsonStringWithCallback[K comparable, V any](m *RWMap[K, V], jsonStr string, onSuccess func()) error\n```\nLoadFromJsonStringWithCallback loads a JSON string into the RWMap and calls the callback on success.\n\n## Types\n\n```go\ntype Base64Source struct {\n\tBase64Data string\n\tMimeType   string\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewBase64FileSource(base64Data string, mimeType string) *Base64Source\n```\n\n```go\nfunc (b *Base64Source) ClearCache()\n```\n\n```go\nfunc (b *Base64Source) ClearRawData()\n```\n\n```go\nfunc (b *Base64Source) GetCache() *CachedFileData\n```\n\n```go\nfunc (b *Base64Source) GetIdentifier() string\n```\n\n```go\nfunc (b *Base64Source) GetRawData() string\n```\n\n```go\nfunc (b *Base64Source) HasCache() bool\n```\n\n```go\nfunc (b *Base64Source) IsRegistered() bool\n```\n\n```go\nfunc (b *Base64Source) IsURL() bool\n```\n\n```go\nfunc (b *Base64Source) Mu() *sync.Mutex\n```\n\n```go\nfunc (b *Base64Source) SetCache(data *CachedFileData)\n```\n\n```go\nfunc (b *Base64Source) SetRegistered(registered bool)\n```\n\n```go\ntype CachedFileData struct {\n\tMimeType    string        // MIME 类型\n\tSize        int64         // 文件大小（字节）\n\tDiskSize    int64         // 磁盘缓存实际占用大小（字节，通常是 base64 长度）\n\tImageConfig *image.Config // 图片配置（如果是图片）\n\tImageFormat string        // 图片格式（如果是图片）\n\n\tOnClose func(size int64)\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewDiskCachedData(diskPath string, mimeType string, size int64) *CachedFileData\n```\n\n```go\nfunc NewMemoryCachedData(base64Data string, mimeType string, size int64) *CachedFileData\n```\n\n```go\nfunc (c *CachedFileData) Close() error\n```\n\n```go\nfunc (c *CachedFileData) GetBase64Data() (string, error)\n```\n\n```go\nfunc (c *CachedFileData) IsDisk() bool\n```\n\n```go\nfunc (c *CachedFileData) SetBase64Data(data string)\n```\n\n```go\ntype ChannelError struct {\n\tChannelId   int    `json:\"channel_id\"`\n\tChannelType int    `json:\"channel_type\"`\n\tChannelName string `json:\"channel_name\"`\n\tIsMultiKey  bool   `json:\"is_multi_key\"`\n\tAutoBan     bool   `json:\"auto_ban\"`\n\tUsingKey    string `json:\"using_key\"`\n}\n```\n\n```go\nfunc NewChannelError(channelId int, channelType int, channelName string, isMultiKey bool, usingKey string, autoBan bool) *ChannelError\n```\n\n```go\ntype ClaudeError struct {\n\tType    string `json:\"type,omitempty\"`\n\tMessage string `json:\"message,omitempty\"`\n}\n```\n\n```go\ntype ErrorCode string\n```\n\n```go\nconst (\n\tErrorCodeInvalidRequest         ErrorCode = \"invalid_request\"\n\tErrorCodeSensitiveWordsDetected ErrorCode = \"sensitive_words_detected\"\n\tErrorCodeViolationFeeGrokCSAM   ErrorCode = \"violation_fee.grok.csam\"\n\n\t// upstream API error\n\tErrorCodeCountTokenFailed   ErrorCode = \"count_token_failed\"\n\tErrorCodeModelPriceError    ErrorCode = \"model_price_error\"\n\tErrorCodeInvalidApiType     ErrorCode = \"invalid_api_type\"\n\tErrorCodeJsonMarshalFailed  ErrorCode = \"json_marshal_failed\"\n\tErrorCodeDoRequestFailed    ErrorCode = \"do_request_failed\"\n\tErrorCodeGetChannelFailed   ErrorCode = \"get_channel_failed\"\n\tErrorCodeGenRelayInfoFailed ErrorCode = \"gen_relay_info_failed\"\n\n\t// channel error\n\tErrorCodeChannelNoAvailableKey        ErrorCode = \"channel:no_available_key\"\n\tErrorCodeChannelParamOverrideInvalid  ErrorCode = \"channel:param_override_invalid\"\n\tErrorCodeChannelHeaderOverrideInvalid ErrorCode = \"channel:header_override_invalid\"\n\tErrorCodeChannelModelMappedError      ErrorCode = \"channel:model_mapped_error\"\n\tErrorCodeChannelAwsClientError        ErrorCode = \"channel:aws_client_error\"\n\tErrorCodeChannelInvalidKey            ErrorCode = \"channel:invalid_key\"\n\tErrorCodeChannelResponseTimeExceeded  ErrorCode = \"channel:response_time_exceeded\"\n\n\t// client request error\n\tErrorCodeReadRequestBodyFailed ErrorCode = \"read_request_body_failed\"\n\tErrorCodeConvertRequestFailed  ErrorCode = \"convert_request_failed\"\n\tErrorCodeAccessDenied          ErrorCode = \"access_denied\"\n\n\t// request error\n\tErrorCodeBadRequestBody ErrorCode = \"bad_request_body\"\n\n\t// response error\n\tErrorCodeReadResponseBodyFailed ErrorCode = \"read_response_body_failed\"\n\tErrorCodeBadResponseStatusCode  ErrorCode = \"bad_response_status_code\"\n\tErrorCodeBadResponse            ErrorCode = \"bad_response\"\n\tErrorCodeBadResponseBody        ErrorCode = \"bad_response_body\"\n\tErrorCodeEmptyResponse          ErrorCode = \"empty_response\"\n\tErrorCodeEmptyCompletion        ErrorCode = \"empty_completion\"\n\tErrorCodeAwsInvokeError         ErrorCode = \"aws_invoke_error\"\n\tErrorCodeModelNotFound          ErrorCode = \"model_not_found\"\n\tErrorCodePromptBlocked          ErrorCode = \"prompt_blocked\"\n\n\t// sql error\n\tErrorCodeQueryDataError  ErrorCode = \"query_data_error\"\n\tErrorCodeUpdateDataError ErrorCode = \"update_data_error\"\n\n\t// quota error\n\tErrorCodeInsufficientUserQuota      ErrorCode = \"insufficient_user_quota\"\n\tErrorCodePreConsumeTokenQuotaFailed ErrorCode = \"pre_consume_token_quota_failed\"\n)\n```\n\n```go\ntype ErrorType string\n```\n\n```go\nconst (\n\tErrorTypeMaxAPIError     ErrorType = \"max_api_error\"\n\tErrorTypeOpenAIError     ErrorType = \"openai_error\"\n\tErrorTypeClaudeError     ErrorType = \"claude_error\"\n\tErrorTypeMidjourneyError ErrorType = \"midjourney_error\"\n\tErrorTypeGeminiError     ErrorType = \"gemini_error\"\n\tErrorTypeRerankError     ErrorType = \"rerank_error\"\n\tErrorTypeUpstreamError   ErrorType = \"upstream_error\"\n)\n```\n\n```go\ntype FileMeta struct {\n\tFileType\n\tSource FileSource // 统一的文件来源（URL 或 base64）\n\tDetail string     // 图片细节级别（low/high/auto）\n}\n```\n\n```go\nfunc NewFileMeta(fileType FileType, source FileSource) *FileMeta\n```\nNewFileMeta 创建新的 FileMeta\n\n```go\nfunc NewImageFileMeta(source FileSource, detail string) *FileMeta\n```\nNewImageFileMeta 创建图片类型的 FileMeta\n\n```go\nfunc (f *FileMeta) GetIdentifier() string\n```\nGetIdentifier 获取文件标识符（用于日志）\n\n```go\nfunc (f *FileMeta) GetRawData() string\n```\nGetRawData 获取原始数据（兼容旧代码） Deprecated: 请使用 Source.GetRawData()\n\n```go\nfunc (f *FileMeta) IsURL() bool\n```\nIsURL 判断是否是 URL 来源\n\n```go\ntype FileSource interface {\n\tIsURL() bool\n\tGetIdentifier() string\n\tGetRawData() string\n\tClearRawData()\n\n\tSetCache(data *CachedFileData)\n\tGetCache() *CachedFileData\n\tHasCache() bool\n\tClearCache()\n\n\tIsRegistered() bool\n\tSetRegistered(registered bool)\n\tMu() *sync.Mutex\n}\n```\nFileSource 统一的文件来源抽象接口 支持 URL 和 base64 两种来源，提供懒加载和缓存机制\n\n```go\nfunc NewFileSourceFromData(data string, mimeType string) FileSource\n```\n\n```go\ntype FileType string\n```\n\n```go\nconst (\n\tFileTypeImage FileType = \"image\" // Image file type\n\tFileTypeAudio FileType = \"audio\" // Audio file type\n\tFileTypeVideo FileType = \"video\" // Video file type\n\tFileTypeFile  FileType = \"file\"  // Generic file type\n)\n```\n\n```go\ntype GroupRatioInfo struct {\n\tGroupRatio        float64\n\tGroupSpecialRatio float64\n\tHasSpecialRatio   bool\n}\n```\n\n```go\ntype LocalFileData struct {\n\tMimeType   string\n\tBase64Data string\n\tUrl        string\n\tSize       int64\n}\n```\n\n```go\ntype MaxAPIError struct {\n\tErr        error\n\tRelayError any\n\n\tStatusCode int\n\tMetadata   json.RawMessage\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc InitOpenAIError(errorCode ErrorCode, statusCode int, ops ...MaxAPIErrorOptions) *MaxAPIError\n```\n\n```go\nfunc NewError(err error, errorCode ErrorCode, ops ...MaxAPIErrorOptions) *MaxAPIError\n```\n\n```go\nfunc NewErrorWithStatusCode(err error, errorCode ErrorCode, statusCode int, ops ...MaxAPIErrorOptions) *MaxAPIError\n```\n\n```go\nfunc NewOpenAIError(err error, errorCode ErrorCode, statusCode int, ops ...MaxAPIErrorOptions) *MaxAPIError\n```\n\n```go\nfunc WithClaudeError(claudeError ClaudeError, statusCode int, ops ...MaxAPIErrorOptions) *MaxAPIError\n```\n\n```go\nfunc WithOpenAIError(openAIError OpenAIError, statusCode int, ops ...MaxAPIErrorOptions) *MaxAPIError\n```\n\n```go\nfunc (e *MaxAPIError) Error() string\n```\n\n```go\nfunc (e *MaxAPIError) ErrorWithStatusCode() string\n```\n\n```go\nfunc (e *MaxAPIError) GetErrorCode() ErrorCode\n```\n\n```go\nfunc (e *MaxAPIError) GetErrorType() ErrorType\n```\n\n```go\nfunc (e *MaxAPIError) MaskSensitiveError() string\n```\n\n```go\nfunc (e *MaxAPIError) MaskSensitiveErrorWithStatusCode() string\n```\n\n```go\nfunc (e *MaxAPIError) SetMessage(message string)\n```\n\n```go\nfunc (e *MaxAPIError) ToClaudeError() ClaudeError\n```\n\n```go\nfunc (e *MaxAPIError) ToOpenAIError() OpenAIError\n```\n\n```go\nfunc (e *MaxAPIError) Unwrap() error\n```\nUnwrap enables errors.Is / errors.As to work with MaxAPIError by exposing the underlying error.\n\n```go\ntype MaxAPIErrorOptions func(*MaxAPIError)\n```\n\n```go\nfunc ErrOptionWithHideErrMsg(replaceStr string) MaxAPIErrorOptions\n```\n\n```go\nfunc ErrOptionWithNoRecordErrorLog() MaxAPIErrorOptions\n```\n\n```go\nfunc ErrOptionWithSkipRetry() MaxAPIErrorOptions\n```\n\n```go\nfunc ErrOptionWithStatusCode(statusCode int) MaxAPIErrorOptions\n```\n\n```go\ntype OpenAIError struct {\n\tMessage  string          `json:\"message\"`\n\tType     string          `json:\"type\"`\n\tParam    string          `json:\"param\"`\n\tCode     any             `json:\"code\"`\n\tMetadata json.RawMessage `json:\"metadata,omitempty\"`\n}\n```\n\n```go\ntype PriceData struct {\n\tFreeModel            bool\n\tModelPrice           float64\n\tModelRatio           float64\n\tCompletionRatio      float64\n\tCacheRatio           float64\n\tCacheCreationRatio   float64\n\tCacheCreation5mRatio float64\n\tCacheCreation1hRatio float64\n\tImageRatio           float64\n\tAudioRatio           float64\n\tAudioCompletionRatio float64\n\tOtherRatios          map[string]float64\n\tUsePrice             bool\n\tQuota                int // 按次计费的最终额度（MJ / Task）\n\tQuotaToPreConsume    int // 按量计费的预消耗额度\n\tGroupRatioInfo       GroupRatioInfo\n}\n```\n\n```go\nfunc (p *PriceData) AddOtherRatio(key string, ratio float64)\n```\n\n```go\nfunc (p *PriceData) ToSetting() string\n```\n\n```go\ntype RWMap[K comparable, V any] struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewRWMap[K comparable, V any]() *RWMap[K, V]\n```\n\n```go\nfunc (m *RWMap[K, V]) AddAll(other map[K]V)\n```\n\n```go\nfunc (m *RWMap[K, V]) Clear()\n```\n\n```go\nfunc (m *RWMap[K, V]) Get(key K) (V, bool)\n```\n\n```go\nfunc (m *RWMap[K, V]) Len() int\n```\n\n```go\nfunc (m *RWMap[K, V]) MarshalJSON() ([]byte, error)\n```\n\n```go\nfunc (m *RWMap[K, V]) MarshalJSONString() string\n```\nMarshalJSONString returns the JSON string representation of the RWMap.\n\n```go\nfunc (m *RWMap[K, V]) ReadAll() map[K]V\n```\nReadAll returns a copy of the entire map.\n\n```go\nfunc (m *RWMap[K, V]) Set(key K, value V)\n```\n\n```go\nfunc (m *RWMap[K, V]) UnmarshalJSON(b []byte) error\n```\n\n```go\ntype RelayFormat string\n```\n\n```go\ntype RequestMeta struct {\n\tOriginalModelName string `json:\"original_model_name\"`\n\tUserUsingGroup    string `json:\"user_using_group\"`\n\tPromptTokens      int    `json:\"prompt_tokens\"`\n\tPreConsumedQuota  int    `json:\"pre_consumed_quota\"`\n}\n```\n\n```go\ntype Set[T comparable] struct {\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewSet[T comparable]() *Set[T]\n```\nNewSet 创建并返回一个新的 Set\n\n```go\nfunc (s *Set[T]) Add(item T)\n```\n\n```go\nfunc (s *Set[T]) Contains(item T) bool\n```\nContains 检查 Set 是否包含某个元素\n\n```go\nfunc (s *Set[T]) Items() []T\n```\nItems 返回 Set 中所有元素组成的切片 注意：由于 map 的无序性，返回的切片元素顺序是随机的\n\n```go\nfunc (s *Set[T]) Len() int\n```\nLen 返回 Set 中元素的数量\n\n```go\nfunc (s *Set[T]) Remove(item T)\n```\nRemove 从 Set 中移除一个元素\n\n```go\ntype TaskBillingInput struct {\n\tModel         string             `json:\"model,omitempty\"`\n\tUpstreamModel string             `json:\"upstream_model,omitempty\"`\n\tAction        string             `json:\"action,omitempty\"`\n\tPlatform      string             `json:\"platform,omitempty\"`\n\tFields        map[string]string  `json:\"fields,omitempty\"`\n\tNumbers       map[string]float64 `json:\"numbers,omitempty\"`\n}\n```\n\n```go\nfunc (i *TaskBillingInput) SetField(key, value string)\n```\n\n```go\nfunc (i *TaskBillingInput) SetNumber(key string, value float64)\n```\n\n```go\ntype TaskBillingResult struct {\n\tRuleKey        string                 `json:\"rule_key,omitempty\"`\n\tRowID          string                 `json:\"row_id,omitempty\"`\n\tUnit           string                 `json:\"unit,omitempty\"`\n\tQuantity       float64                `json:\"quantity,omitempty\"`\n\tUnitPrice      float64                `json:\"unit_price,omitempty\"`\n\tTotalPrice     float64                `json:\"total_price,omitempty\"`\n\tQuota          int                    `json:\"quota,omitempty\"`\n\tFields         map[string]string      `json:\"fields,omitempty\"`\n\tMatched        map[string]string      `json:\"matched,omitempty\"`\n\tTrace          []TaskBillingTraceItem `json:\"trace,omitempty\"`\n\tPerCallBilling bool                   `json:\"per_call_billing,omitempty\"`\n}\n```\n\n```go\ntype TaskBillingTraceItem struct {\n\tName  string  `json:\"name\"`\n\tValue string  `json:\"value,omitempty\"`\n\tUnit  string  `json:\"unit,omitempty\"`\n\tPrice float64 `json:\"price,omitempty\"`\n}\n```\n\n```go\ntype TokenCountMeta struct {\n\tTokenType     TokenType   `json:\"token_type,omitempty\"`     // Type of tokens used in the request\n\tCombineText   string      `json:\"combine_text,omitempty\"`   // Combined text from all messages\n\tToolsCount    int         `json:\"tools_count,omitempty\"`    // Number of tools used\n\tNameCount     int         `json:\"name_count,omitempty\"`     // Number of names in the request\n\tMessagesCount int         `json:\"messages_count,omitempty\"` // Number of messages in the request\n\tFiles         []*FileMeta `json:\"files,omitempty\"`          // List of files, each with type and content\n\tMaxTokens     int         `json:\"max_tokens,omitempty\"`     // Maximum tokens allowed in the request\n\n\tImagePriceRatio float64 `json:\"image_ratio,omitempty\"` // Ratio for image size, if applicable\n\n}\n```\n\n```go\ntype TokenType string\n```\n\n```go\nconst (\n\tTokenTypeTextNumber TokenType = \"text_number\" // Text or number tokens\n\tTokenTypeTokenizer  TokenType = \"tokenizer\"   // Tokenizer tokens\n\tTokenTypeImage      TokenType = \"image\"       // Image tokens\n)\n```\n\n```go\ntype URLSource struct {\n\tURL string\n\t// contains filtered or unexported fields\n}\n```\n\n```go\nfunc NewURLFileSource(url string) *URLSource\n```\n\n```go\nfunc (b *URLSource) ClearCache()\n```\n\n```go\nfunc (u *URLSource) ClearRawData()\n```\n\n```go\nfunc (b *URLSource) GetCache() *CachedFileData\n```\n\n```go\nfunc (u *URLSource) GetIdentifier() string\n```\n\n```go\nfunc (u *URLSource) GetRawData() string\n```\n\n```go\nfunc (b *URLSource) HasCache() bool\n```\n\n```go\nfunc (b *URLSource) IsRegistered() bool\n```\n\n```go\nfunc (u *URLSource) IsURL() bool\n```\n\n```go\nfunc (b *URLSource) Mu() *sync.Mutex\n```\n\n```go\nfunc (b *URLSource) SetCache(data *CachedFileData)\n```\n\n```go\nfunc (b *URLSource) SetRegistered(registered bool)\n```\n\n","path":"github.com/MAX-API-Next/MAX-API/types","name":"types","synopsis":"","isRedistributable":true}
