@@ -195,45 +195,70 @@ async def list_models(fastapi_request: Request, api_key: str = Depends(get_api_k
195195 # Add base models and their variations
196196 for original_model_id in sorted (list (all_model_ids )):
197197 current_display_prefix = ""
198- # Only add PAY_PREFIX if the model is not already an EXPRESS model (which has its own prefix)
199- if not original_model_id .startswith ("[EXPRESS]" ) and \
200- has_sa_creds and not has_express_key and EXPERIMENTAL_MARKER not in original_model_id :
198+ # 检查是否为[EXPRESS]模型,保留原始前缀
199+ is_express_model = original_model_id .startswith ("[EXPRESS]" )
200+ base_model_without_prefix = original_model_id
201+
202+ # 如果是EXPRESS模型,移除前缀用于后续处理,但在显示时会保留
203+ if is_express_model :
204+ # 从原始ID中提取不带[EXPRESS]前缀的模型名
205+ base_model_without_prefix = original_model_id [len ("[EXPRESS] " ):]
206+ vertex_log ('info' , f"处理EXPRESS模型: { original_model_id } , 基础名称: { base_model_without_prefix } " )
207+
208+ # 只有非EXPRESS模型才考虑添加PAY_PREFIX
209+ if not is_express_model and has_sa_creds and EXPERIMENTAL_MARKER not in original_model_id :
210+ # 只要有SA凭证就应该显示PAY前缀,不管是否有Express Key
201211 current_display_prefix = PAY_PREFIX
212+ vertex_log ('info' , f"为非EXPRESS模型添加PAY前缀: { current_display_prefix } { original_model_id } " )
202213
203- base_display_id = f"{ current_display_prefix } { original_model_id } "
214+ # 构建显示ID,如果是EXPRESS模型,确保保留[EXPRESS]前缀
215+ base_display_id = original_model_id if is_express_model else f"{ current_display_prefix } { original_model_id } "
204216
217+ vertex_log ('info' , f"添加模型到列表: { base_display_id } " )
205218 dynamic_models_data .append ({
206219 "id" : base_display_id , "object" : "model" , "created" : current_time , "owned_by" : "google" ,
207- "permission" : [], "root" : original_model_id , "parent" : None
220+ "permission" : [], "root" : base_model_without_prefix , "parent" : None
208221 })
209222
210223 # Conditionally add common variations (standard suffixes)
211- if not original_model_id .startswith ("gemini-2.0" ): # Suffix rules based on original_model_id
224+ if not base_model_without_prefix .startswith ("gemini-2.0" ): # Suffix rules based on original_model_id
212225 standard_suffixes = ["-search" , "-encrypt" , "-encrypt-full" , "-auto" ]
213226 for suffix in standard_suffixes :
214- # Suffix is applied to the original model ID part
215- suffixed_model_part = f"{ original_model_id } { suffix } "
216- # Then the whole thing is prefixed
217- final_suffixed_display_id = f"{ current_display_prefix } { suffixed_model_part } "
227+ # Suffix is applied to the original model ID part (without EXPRESS prefix)
228+ suffixed_model_part = f"{ base_model_without_prefix } { suffix } "
229+ # Then the whole thing is prefixed - retain EXPRESS prefix if it was there
230+ final_suffixed_display_id = ""
231+ if is_express_model :
232+ final_suffixed_display_id = f"[EXPRESS] { suffixed_model_part } "
233+ else :
234+ # 非EXPRESS模型的后缀版本也需要正确显示PAY前缀
235+ final_suffixed_display_id = f"{ current_display_prefix } { suffixed_model_part } "
218236
219237 # Check if this suffixed ID is already in all_model_ids (unlikely with prefix) or already added
220238 if final_suffixed_display_id not in all_model_ids and not any (m ['id' ] == final_suffixed_display_id for m in dynamic_models_data ):
239+ vertex_log ('info' , f"添加后缀模型到列表: { final_suffixed_display_id } " )
221240 dynamic_models_data .append ({
222241 "id" : final_suffixed_display_id , "object" : "model" , "created" : current_time , "owned_by" : "google" ,
223- "permission" : [], "root" : original_model_id , "parent" : None
242+ "permission" : [], "root" : base_model_without_prefix , "parent" : None
224243 })
225244
226245 # Apply special suffixes for models starting with "gemini-2.5-flash"
227- if original_model_id .startswith ("gemini-2.5-flash" ): # Suffix rules based on original_model_id
246+ if base_model_without_prefix .startswith ("gemini-2.5-flash" ): # Suffix rules based on original_model_id
228247 special_flash_suffixes = ["-nothinking" , "-max" ]
229248 for special_suffix in special_flash_suffixes :
230- suffixed_model_part = f"{ original_model_id } { special_suffix } "
231- final_special_suffixed_display_id = f"{ current_display_prefix } { suffixed_model_part } "
249+ suffixed_model_part = f"{ base_model_without_prefix } { special_suffix } "
250+ # Retain EXPRESS prefix if original model had it
251+ if is_express_model :
252+ final_special_suffixed_display_id = f"[EXPRESS] { suffixed_model_part } "
253+ else :
254+ # 非EXPRESS模型的特殊后缀版本也需要正确显示PAY前缀
255+ final_special_suffixed_display_id = f"{ current_display_prefix } { suffixed_model_part } "
232256
233257 if final_special_suffixed_display_id not in all_model_ids and not any (m ['id' ] == final_special_suffixed_display_id for m in dynamic_models_data ):
258+ vertex_log ('info' , f"添加特殊后缀模型到列表: { final_special_suffixed_display_id } " )
234259 dynamic_models_data .append ({
235260 "id" : final_special_suffixed_display_id , "object" : "model" , "created" : current_time , "owned_by" : "google" ,
236- "permission" : [], "root" : original_model_id , "parent" : None
261+ "permission" : [], "root" : base_model_without_prefix , "parent" : None
237262 })
238263
239264 # Ensure uniqueness again after adding suffixes
@@ -250,6 +275,7 @@ async def list_models(fastapi_request: Request, api_key: str = Depends(get_api_k
250275 if EXPERIMENTAL_MARKER in base_model_id_for_openai :
251276 display_model_id = f"{ base_model_id_for_openai } { OPENAI_DIRECT_SUFFIX } "
252277 else :
278+ # OpenAI直接模式下也应该保持PAY前缀
253279 display_model_id = f"{ PAY_PREFIX } { base_model_id_for_openai } { OPENAI_DIRECT_SUFFIX } "
254280
255281 # Check if already added (e.g. if remote config somehow already listed it or added as a base model)
0 commit comments