Coverage for .venv/lib/python3.13/site-packages/litellm/proxy/common_utils/admin_ui_utils.py: 17%

18 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-10 12:01 +0000

1from typing import Final 

2 

3 

4def show_missing_vars_in_env(): 

5 from fastapi.responses import HTMLResponse 

6 

7 from litellm.proxy.proxy_server import master_key, prisma_client 

8 

9 if prisma_client is None and master_key is None: 

10 return HTMLResponse( 

11 content=missing_keys_form(missing_key_names="DATABASE_URL, LITELLM_MASTER_KEY"), 

12 status_code=200, 

13 ) 

14 if prisma_client is None: 

15 return HTMLResponse(content=missing_keys_form(missing_key_names="DATABASE_URL"), status_code=200) 

16 

17 if master_key is None: 

18 return HTMLResponse( 

19 content=missing_keys_form(missing_key_names="LITELLM_MASTER_KEY"), 

20 status_code=200, 

21 ) 

22 return None 

23 

24 

25def missing_keys_form(missing_key_names: str): 

26 missing_keys_html_form: Final = """ 

27 <!DOCTYPE html> 

28 <html lang="en"> 

29 <head> 

30 <meta charset="UTF-8"> 

31 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

32 <style> 

33 body {{ 

34 font-family: Arial, sans-serif; 

35 background-color: #f4f4f9; 

36 color: #333; 

37 margin: 20px; 

38 line-height: 1.6; 

39 }} 

40 .container {{ 

41 max-width: 800px; 

42 margin: auto; 

43 padding: 20px; 

44 background: #fff; 

45 border: 1px solid #ddd; 

46 border-radius: 5px; 

47 box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); 

48 }} 

49 h1 {{ 

50 font-size: 24px; 

51 margin-bottom: 20px; 

52 }} 

53 pre {{ 

54 background: #f8f8f8; 

55 padding: 1px; 

56 border: 1px solid #ccc; 

57 border-radius: 4px; 

58 overflow-x: auto; 

59 font-size: 14px; 

60 }} 

61 .env-var {{ 

62 font-weight: normal; 

63 }} 

64 .comment {{ 

65 font-weight: normal; 

66 color: #777; 

67 }} 

68 </style> 

69 <title>Environment Setup Instructions</title> 

70 </head> 

71 <body> 

72 <div class="container"> 

73 <h1>Environment Setup Instructions</h1> 

74 <p>Please add the following variables to your environment variables:</p> 

75 <pre> 

76 <span class="comment"># Generate one with: echo "LITELLM_MASTER_KEY=sk-$(openssl rand -hex 32)"</span> 

77 <span class="env-var">LITELLM_MASTER_KEY=""</span> <span class="comment"># Your master key for the proxy server. Can use this to send /chat/completion requests etc</span> 

78 <span class="env-var">LITELLM_SALT_KEY="sk-XXXXXXXX"</span> <span class="comment"># Can NOT CHANGE THIS ONCE SET - It is used to encrypt/decrypt credentials stored in DB. If value of 'LITELLM_SALT_KEY' changes your models cannot be retrieved from DB</span> 

79 <span class="env-var">DATABASE_URL="postgres://..."</span> <span class="comment"># Need a postgres database? (Check out Supabase, Neon, etc)</span> 

80 <span class="comment">## OPTIONAL ##</span> 

81 <span class="env-var">PORT=4000</span> <span class="comment"># DO THIS FOR RENDER/RAILWAY</span> 

82 <span class="env-var">STORE_MODEL_IN_DB="True"</span> <span class="comment"># Allow storing models in db</span> 

83 </pre> 

84 <h1>Missing Environment Variables</h1> 

85 <p>{missing_keys}</p> 

86 </div> 

87 

88 <div class="container"> 

89 <h1>Need Help? Support</h1> 

90 <p>Discord: <a href="https://discord.com/invite/wuPM9dRgDw" target="_blank">https://discord.com/invite/wuPM9dRgDw</a></p> 

91 <p>Docs: <a href="https://docs.litellm.ai/docs/" target="_blank">https://docs.litellm.ai/docs/</a></p> 

92 </div> 

93 </body> 

94 </html> 

95 """ 

96 return missing_keys_html_form.format(missing_keys=missing_key_names) 

97 

98 

99def admin_ui_disabled(): 

100 from fastapi.responses import HTMLResponse 

101 

102 ui_disabled_html: Final = """ 

103 <!DOCTYPE html> 

104 <html lang="en"> 

105 <head> 

106 <meta charset="UTF-8"> 

107 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 

108 <style> 

109 body {{ 

110 font-family: Arial, sans-serif; 

111 background-color: #f4f4f9; 

112 color: #333; 

113 margin: 20px; 

114 line-height: 1.6; 

115 }} 

116 .container {{ 

117 max-width: 800px; 

118 margin: auto; 

119 padding: 20px; 

120 background: #fff; 

121 border: 1px solid #ddd; 

122 border-radius: 5px; 

123 box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); 

124 }} 

125 h1 {{ 

126 font-size: 24px; 

127 margin-bottom: 20px; 

128 }} 

129 pre {{ 

130 background: #f8f8f8; 

131 padding: 1px; 

132 border: 1px solid #ccc; 

133 border-radius: 4px; 

134 overflow-x: auto; 

135 font-size: 14px; 

136 }} 

137 .env-var {{ 

138 font-weight: normal; 

139 }} 

140 .comment {{ 

141 font-weight: normal; 

142 color: #777; 

143 }} 

144 </style> 

145 <title>Admin UI Disabled</title> 

146 </head> 

147 <body> 

148 <div class="container"> 

149 <h1>Admin UI is Disabled</h1> 

150 <p>The Admin UI has been disabled by the administrator. To re-enable it, please update the following environment variable:</p> 

151 <pre> 

152 <span class="env-var">DISABLE_ADMIN_UI="False"</span> <span class="comment"># Set this to "False" to enable the Admin UI.</span> 

153 </pre> 

154 <p>After making this change, restart the application for it to take effect.</p> 

155 </div> 

156 

157 <div class="container"> 

158 <h1>Need Help? Support</h1> 

159 <p>Discord: <a href="https://discord.com/invite/wuPM9dRgDw" target="_blank">https://discord.com/invite/wuPM9dRgDw</a></p> 

160 <p>Docs: <a href="https://docs.litellm.ai/docs/" target="_blank">https://docs.litellm.ai/docs/</a></p> 

161 </div> 

162 </body> 

163 </html> 

164 """ 

165 

166 return HTMLResponse( 

167 content=ui_disabled_html, 

168 status_code=200, 

169 )