@@ -101,6 +101,50 @@ def _load_replacement_rules_from_env(
101101 return []
102102
103103
104+ def _apply_gemini_backend (
105+ config_backends : dict [str , Any ],
106+ env : Mapping [str , str ],
107+ gemini_key : str ,
108+ resolution : ParameterResolution | None ,
109+ ) -> None :
110+ if logger .isEnabledFor (logging .INFO ):
111+ _ , gemini_key_source = get_env_value_with_windows_persistent_fallback (
112+ "GEMINI_API_KEY" , environ = env
113+ )
114+ logger .info (
115+ "Gemini key diagnostics [from_env_part3]: env_type=%s source=%s" ,
116+ type (env ).__name__ ,
117+ gemini_key_source ,
118+ )
119+
120+ config_backends ["gemini" ] = config_backends .get ("gemini" , {})
121+ config_backends ["gemini" ]["api_key" ] = gemini_key
122+ config_backends ["gemini" ]["api_url" ] = _get_env_value (
123+ env ,
124+ "GEMINI_API_BASE_URL" ,
125+ "https://generativelanguage.googleapis.com" ,
126+ path = "backends.gemini.api_url" ,
127+ resolution = resolution ,
128+ )
129+ gemini_timeout = _get_env_value (
130+ env ,
131+ "GEMINI_TIMEOUT" ,
132+ None ,
133+ path = "backends.gemini.timeout" ,
134+ resolution = resolution ,
135+ transform = lambda value : _to_int (value , 0 ),
136+ )
137+ if gemini_timeout :
138+ config_backends ["gemini" ]["timeout" ] = gemini_timeout
139+ if resolution is not None :
140+ resolution .record (
141+ "backends.gemini.api_key" ,
142+ config_backends ["gemini" ]["api_key" ],
143+ ParameterSource .ENVIRONMENT ,
144+ origin = "GEMINI_API_KEY" ,
145+ )
146+
147+
104148def apply_config_part3 (
105149 config : dict [str , Any ],
106150 env : Mapping [str , str ],
@@ -137,43 +181,11 @@ def apply_config_part3(
137181 origin = "OPENROUTER_API_KEY" ,
138182 )
139183
140- gemini_key , gemini_key_source = get_env_value_with_windows_persistent_fallback (
184+ gemini_key , _gemini_key_source = get_env_value_with_windows_persistent_fallback (
141185 "GEMINI_API_KEY" , environ = env
142186 )
143187 if gemini_key and not _has_numbered_env_variants (env , "GEMINI_API_KEY" ):
144- if logger .isEnabledFor (logging .INFO ):
145- logger .info (
146- "Gemini key diagnostics [from_env_part3]: env_type=%s source=%s" ,
147- type (env ).__name__ ,
148- gemini_key_source ,
149- )
150-
151- config_backends ["gemini" ] = config_backends .get ("gemini" , {})
152- config_backends ["gemini" ]["api_key" ] = gemini_key
153- config_backends ["gemini" ]["api_url" ] = _get_env_value (
154- env ,
155- "GEMINI_API_BASE_URL" ,
156- "https://generativelanguage.googleapis.com" ,
157- path = "backends.gemini.api_url" ,
158- resolution = resolution ,
159- )
160- gemini_timeout = _get_env_value (
161- env ,
162- "GEMINI_TIMEOUT" ,
163- None ,
164- path = "backends.gemini.timeout" ,
165- resolution = resolution ,
166- transform = lambda value : _to_int (value , 0 ),
167- )
168- if gemini_timeout :
169- config_backends ["gemini" ]["timeout" ] = gemini_timeout
170- if resolution is not None :
171- resolution .record (
172- "backends.gemini.api_key" ,
173- config_backends ["gemini" ]["api_key" ],
174- ParameterSource .ENVIRONMENT ,
175- origin = "GEMINI_API_KEY" ,
176- )
188+ _apply_gemini_backend (config_backends , env , gemini_key , resolution )
177189
178190 if env .get ("ANTHROPIC_API_KEY" ):
179191 config_backends ["anthropic" ] = config_backends .get ("anthropic" , {})
0 commit comments