Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyAnthropicBetaDeepSeekThinkingPatch(req *anthropic.BetaMessageNewParams)
- func ApplyAnthropicBetaMetadataTransform(req *anthropic.BetaMessageNewParams, extra map[string]any) *anthropic.BetaMessageNewParams
- func ApplyAnthropicBetaModelTransform(req *anthropic.BetaMessageNewParams, model string) *anthropic.BetaMessageNewParams
- func ApplyAnthropicV1DeepSeekThinkingPatch(req *anthropic.MessageNewParams)
- func ApplyAnthropicV1MetadataTransform(req *anthropic.MessageNewParams, extra map[string]any) *anthropic.MessageNewParams
- func ApplyAnthropicV1ModelTransform(req *anthropic.MessageNewParams, model string) *anthropic.MessageNewParams
- func ApplyClaudeCodeBetaCompatRoleRewrite(req *anthropic.BetaMessageNewParams)
- func ApplyClaudeCodeCompatRoleRewrite(req *anthropic.MessageNewParams)
- func ApplyCodexResponsesTransform(req *responses.ResponseNewParams, originalRequest interface{}) *responses.ResponseNewParams
- func ApplyCursorCompatContentNormalization(req *openai.ChatCompletionNewParams)
- func ApplyProviderTransforms(req *openai.ChatCompletionNewParams, providerURL, model string, ...) *openai.ChatCompletionNewParams
- func ApplyResponseTransforms(resp map[string]interface{}, providerURL, model string) map[string]interface{}
- func ApplyThinkingEffort(req interface{}, effort string)
- func FormatMetadataUserID(m *MetadataUserID) string
- func GenHex5() string
- func SanitizeAnthropicBetaThinkingConfig(req *anthropic.BetaMessageNewParams)
- func SanitizeAnthropicV1ThinkingConfig(req *anthropic.MessageNewParams)
- type MetadataUserID
- type ResponseTransform
Constants ¶
const ClaudeCodeVersion = "2.1.86"
const FingerprintSalt = "59cf53e54c78"
FingerprintSalt is the salt used in computeFingerprint. IMPORTANT: Must stay in sync with Claude Code's FINGERPRINT_SALT constant.
Variables ¶
var ResponseConfigs = []responseConfig{
{"api.deepseek.com", applyDeepSeekResponseTransform},
}
ResponseConfigs holds all registered provider response configurations
Functions ¶
func ApplyAnthropicBetaDeepSeekThinkingPatch ¶
func ApplyAnthropicBetaDeepSeekThinkingPatch(req *anthropic.BetaMessageNewParams)
ApplyAnthropicBetaDeepSeekThinkingPatch is the Beta-variant of ApplyAnthropicV1DeepSeekThinkingPatch.
func ApplyAnthropicBetaMetadataTransform ¶
func ApplyAnthropicBetaMetadataTransform(req *anthropic.BetaMessageNewParams, extra map[string]any) *anthropic.BetaMessageNewParams
ApplyAnthropicBetaMetadataTransform injects OAuth user_id into Anthropic beta request metadata. This adds metadata.user_id in JSON format for Anthropic API tracking.
Note: Only injects metadata when provider is OAuth and has valid UserID.
func ApplyAnthropicBetaModelTransform ¶
func ApplyAnthropicBetaModelTransform(req *anthropic.BetaMessageNewParams, model string) *anthropic.BetaMessageNewParams
ApplyAnthropicBetaModelTransform applies Anthropic API beta model-specific filtering. Same rules as V1 but for BetaMessageNewParams.
func ApplyAnthropicV1DeepSeekThinkingPatch ¶
func ApplyAnthropicV1DeepSeekThinkingPatch(req *anthropic.MessageNewParams)
ApplyAnthropicV1DeepSeekThinkingPatch ensures every assistant message carries at least one thinking block. DeepSeek's Anthropic-compatible endpoint rejects assistant turns that lack one — mirrors the reasoning_content fill in applyDeepSeekTransform for the OpenAI Chat path.
func ApplyAnthropicV1MetadataTransform ¶
func ApplyAnthropicV1MetadataTransform(req *anthropic.MessageNewParams, extra map[string]any) *anthropic.MessageNewParams
ApplyAnthropicV1MetadataTransform injects OAuth user_id into Anthropic v1 request metadata. This adds metadata.user_id in JSON format for Anthropic API tracking.
Note: Only injects metadata when provider is OAuth and has valid UserID.
func ApplyAnthropicV1ModelTransform ¶
func ApplyAnthropicV1ModelTransform(req *anthropic.MessageNewParams, model string) *anthropic.MessageNewParams
ApplyAnthropicV1ModelTransform applies Anthropic API v1 model-specific filtering. This handles model-specific limitations such as adaptive thinking only being supported by Claude Opus 4.6 (claude-opus-4-6) and Claude Sonnet 4.6 (claude-sonnet-4-6).
Parameters:
- req: The Anthropic v1 request to transform
- model: The target model name
Returns the transformed request (same type as input).
Note: This applies to ALL Anthropic API requests, regardless of authentication method (API key or OAuth token). The limitation is in the Anthropic API itself, not the auth method.
func ApplyClaudeCodeBetaCompatRoleRewrite ¶ added in v0.260611.1
func ApplyClaudeCodeBetaCompatRoleRewrite(req *anthropic.BetaMessageNewParams)
ApplyClaudeCodeBetaCompatRoleRewrite is the beta-namespace counterpart of ApplyClaudeCodeCompatRoleRewrite. The Beta SDK types are structurally identical but distinct, so the logic is duplicated rather than shared.
func ApplyClaudeCodeCompatRoleRewrite ¶ added in v0.260611.1
func ApplyClaudeCodeCompatRoleRewrite(req *anthropic.MessageNewParams)
ApplyClaudeCodeCompatRoleRewrite normalizes any "system" role inside the Anthropic messages array so the request becomes valid for third-party Anthropic-compatible providers, which only accept "user"/"assistant" roles in messages and reject the non-standard mid-conversation "system" role.
The normalization is position-aware on purpose. A system-role entry in messages is, by the Anthropic mid-conversation-system contract, always a mid-conversation operator message (it cannot be messages[0]); the global system prompt already lives in the top-level system field. So we never hoist it — hoisting would reorder an "as of turn N" instruction to a global one and invalidate the prompt cache. Instead each system block is folded, in place, into a user turn under one hard constraint: the result must never contain two consecutive user messages (strict providers reject that — "roles must alternate" — which would just trade one 400 for another).
The merge *direction* is not a free choice; it is forced by the system block's neighbours. Enumerating (prev role, next role):
prev=user, next=user → collapse prev+system+next into one user turn prev=user, next=assistant → merge backward into the preceding user prev=user, next=∅ (end) → merge backward into the preceding user prev=assistant, next=user → merge forward into the following user prev=assistant, next=assistant → stand alone as its own user turn prev=assistant, next=∅ → stand alone as its own user turn prev=∅, next=user → merge forward into the following user prev=∅, next=assistant → stand alone as its own user turn prev=∅, next=∅ → stand alone as its own user turn (sole msg)
In one rule: fold backward when the preceding turn is a user, otherwise fold forward into the next user, and only stand alone when neither neighbour is a user. The direction can only be decided once the *next* role is known, so system content is held in a pending buffer and placed when the following non-system message (or the end of the array) is reached.
Non-system messages with no pending system pass through untouched; a request with no system role is a pure pass-through (genuinely pre-existing consecutive user turns are left as-is — we only avoid *creating* new ones).
func ApplyCodexResponsesTransform ¶
func ApplyCodexResponsesTransform(req *responses.ResponseNewParams, originalRequest interface{}) *responses.ResponseNewParams
ApplyCodexResponsesTransform applies Codex-specific transformations to a Responses API request. This is called from VendorTransform for Codex backend providers.
It handles:
- Stream configuration (always enabled for Codex)
- Reasoning config (converts Anthropic "thinking" to Codex "reasoning")
- Tool name shortening (64 char limit)
- Tool parameter normalization
- Special tool mappings (web_search_20250305 -> web_search)
Reference: ref/anthropic2codex.go.ref
func ApplyCursorCompatContentNormalization ¶
func ApplyCursorCompatContentNormalization(req *openai.ChatCompletionNewParams)
ApplyCursorCompatContentNormalization flattens rich content in messages for Cursor compatibility. Applies to ALL providers when cursor_compat is enabled.
func ApplyProviderTransforms ¶
func ApplyProviderTransforms(req *openai.ChatCompletionNewParams, providerURL, model string, config *protocol.OpenAIConfig) *openai.ChatCompletionNewParams
ApplyProviderTransforms applies provider-specific transformations to an OpenAI Chat request. The dispatch is a flat strings.Contains chain — short, explicit, and parallel to the per-shape dispatch in VendorTransform.
New providers are added as new cases here; aliases (e.g. multiple URLs that share a vendor's quirks) sit in the same case body.
func ApplyResponseTransforms ¶
func ApplyResponseTransforms(resp map[string]interface{}, providerURL, model string) map[string]interface{}
ApplyResponseTransforms applies provider-specific transformations to responses
func ApplyThinkingEffort ¶
func ApplyThinkingEffort(req interface{}, effort string)
ApplyThinkingEffort enforces a thinking_effort level on any supported request shape. Shared by both the rule-level and scenario-level thinking transforms.
Effort semantics:
- "" (default): pass through, no change.
- "off": force thinking disabled. For Anthropic this sets OfDisabled; for OpenAI this clears reasoning_effort and removes any stray `thinking` extension (DeepSeek and friends reject requests that carry both).
- "low"/"medium"/"high"/"max": force thinking enabled with the matching budget. "max" collapses to "high" for OpenAI which has no "max".
func FormatMetadataUserID ¶
func FormatMetadataUserID(m *MetadataUserID) string
FormatMetadataUserID formats a MetadataUserID to JSON string. Returns empty string for nil input.
func SanitizeAnthropicBetaThinkingConfig ¶ added in v0.260611.2
func SanitizeAnthropicBetaThinkingConfig(req *anthropic.BetaMessageNewParams)
SanitizeAnthropicBetaThinkingConfig is the Beta-variant of SanitizeAnthropicV1ThinkingConfig.
func SanitizeAnthropicV1ThinkingConfig ¶ added in v0.260611.2
func SanitizeAnthropicV1ThinkingConfig(req *anthropic.MessageNewParams)
SanitizeAnthropicV1ThinkingConfig ensures thinking config consistency for providers (notably DeepSeek) that enforce strict thinking/effort semantics.
This function NEVER modifies message content (thinking blocks in context are always preserved). It only adjusts the request-level thinking config header.
Types ¶
type MetadataUserID ¶
type MetadataUserID struct {
DeviceID string `json:"device_id"`
AccountUUID string `json:"account_uuid"`
SessionID string `json:"session_id"`
}
MetadataUserID represents the JSON structure for metadata.user_id This matches Claude Code's format (>= 2.1.78)
func BuildMetadataUserID ¶
func BuildMetadataUserID(extra map[string]any) *MetadataUserID
BuildMetadataUserID builds a MetadataUserID from extra map. Returns nil if all fields are empty after fixing.
func FixMetadataUserID ¶
func FixMetadataUserID(raw string) *MetadataUserID
FixMetadataUserID parses and fixes a metadata user ID string. Returns a new MetadataUserID with generated fields for missing values.
func ParseMetadataUserID ¶
func ParseMetadataUserID(raw string) *MetadataUserID
ParseMetadataUserID parses a metadata.user_id string in either JSON or legacy format. Returns nil if the input cannot be parsed.
func (*MetadataUserID) Fix ¶
func (m *MetadataUserID) Fix(extras map[string]any)
func (*MetadataUserID) Format ¶
func (m *MetadataUserID) Format() string
Format converts MetadataUserID to string for metadata.
func (*MetadataUserID) IsEmpty ¶
func (m *MetadataUserID) IsEmpty() bool
IsEmpty checks if the MetadataUserID is effectively empty.
func (*MetadataUserID) IsValid ¶
func (m *MetadataUserID) IsValid() bool
IsValid checks if the MetadataUserID has required fields.
type ResponseTransform ¶
ResponseTransform applies provider-specific transformations to OpenAI responses
func GetResponseTransform ¶
func GetResponseTransform(providerURL string) ResponseTransform
GetResponseTransform identifies provider by APIBase URL and returns its response transform