MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / applyAPIKeyModelAlias

Method applyAPIKeyModelAlias

sdk/cliproxy/auth/conductor.go:3044–3090  ·  view source on GitHub ↗
(auth *Auth, requestedModel string)

Source from the content-addressed store, hash-verified

3042}
3043
3044func (m *Manager) applyAPIKeyModelAlias(auth *Auth, requestedModel string) string {
3045 if m == nil || auth == nil {
3046 return requestedModel
3047 }
3048
3049 if auth.AuthKind() != AuthKindAPIKey {
3050 return requestedModel
3051 }
3052
3053 requestedModel = strings.TrimSpace(requestedModel)
3054 if requestedModel == "" {
3055 return requestedModel
3056 }
3057
3058 // Fast path: lookup per-auth mapping table (keyed by auth.ID).
3059 if resolved := m.lookupAPIKeyUpstreamModel(auth.ID, requestedModel); resolved != "" {
3060 return resolved
3061 }
3062
3063 // Slow path: scan config for the matching credential entry and resolve alias.
3064 // This acts as a safety net if mappings are stale or auth.ID is missing.
3065 cfg, _ := m.runtimeConfig.Load().(*internalconfig.Config)
3066 if cfg == nil {
3067 cfg = &internalconfig.Config{}
3068 }
3069
3070 provider := strings.ToLower(strings.TrimSpace(auth.Provider))
3071 upstreamModel := ""
3072 switch provider {
3073 case "gemini":
3074 upstreamModel = resolveUpstreamModelForGeminiAPIKey(cfg, auth, requestedModel)
3075 case "claude":
3076 upstreamModel = resolveUpstreamModelForClaudeAPIKey(cfg, auth, requestedModel)
3077 case "codex":
3078 upstreamModel = resolveUpstreamModelForCodexAPIKey(cfg, auth, requestedModel)
3079 case "vertex":
3080 upstreamModel = resolveUpstreamModelForVertexAPIKey(cfg, auth, requestedModel)
3081 default:
3082 upstreamModel = resolveUpstreamModelForOpenAICompatAPIKey(cfg, auth, requestedModel)
3083 }
3084
3085 // Return upstream model if found, otherwise return requested model.
3086 if upstreamModel != "" {
3087 return upstreamModel
3088 }
3089 return requestedModel
3090}
3091
3092// APIKeyConfigEntry is a generic interface for API key configurations.
3093type APIKeyConfigEntry interface {

Tested by 1