@@ -426,6 +426,34 @@ async def generation(
426426 # Forward request to upstream
427427 return await proxy .generate (body , request_id )
428428
429+ @app .post ("/siliconflow/models/{model_path:path}" )
430+ async def dynamic_path_generation (
431+ model_path : str ,
432+ request : Request ,
433+ authorization : Optional [str ] = Header (None )
434+ ):
435+ # 1. Strict Auth (No Mock Support)
436+ if not authorization or not authorization .startswith ("Bearer " ):
437+ raise HTTPException (status_code = 401 , detail = "Invalid Authorization header" )
438+
439+ request_id = request .headers .get ("x-request-id" , str (uuid .uuid4 ()))
440+ proxy = DeepSeekProxy (api_key = authorization .replace ("Bearer " , "" ))
441+
442+ # 2. Parse, Inject Model, and Validate
443+ try :
444+ payload = await request .json ()
445+ payload ["model" ] = model_path # Force set model from URL
446+ body = GenerationRequest (** payload )
447+ except Exception as e :
448+ raise HTTPException (status_code = 400 , detail = f"Invalid Request: { e } " )
449+
450+ # 3. Handle SSE
451+ if "text/event-stream" in request .headers .get ("accept" , "" ) and body .parameters :
452+ body .parameters .incremental_output = True
453+
454+ # 4. Generate
455+ return await proxy .generate (body , request_id )
456+
429457 @app .api_route ("/{path_name:path}" , methods = ["GET" , "POST" , "DELETE" , "PUT" ])
430458 async def catch_all (path_name : str , request : Request ):
431459 # Catch-all only valid in Mock Mode
0 commit comments