1515
1616from .models import ProxyConfig , LangfuseTracesResponse , TracesParams , ChatParams , ChatRequestHook , TracesRequestHook
1717from .auth import AuthProvider , NoAuthProvider
18- from .litellm import handle_chat_completion , proxy_to_litellm
18+ from .litellm import handle_chat_completion
1919from .langfuse import fetch_langfuse_traces , pointwise_fetch_langfuse_trace
2020
2121# Configure logging before any other imports (so all modules inherit this config)
@@ -35,10 +35,6 @@ def build_proxy_config(
3535 preprocess_traces_request : Optional [TracesRequestHook ] = None ,
3636) -> ProxyConfig :
3737 """Load environment and secrets, and build ProxyConfig"""
38- # Env
39- litellm_url = os .getenv ("LITELLM_URL" )
40- if not litellm_url :
41- raise ValueError ("LITELLM_URL environment variable must be set" )
4238 request_timeout = float (os .getenv ("REQUEST_TIMEOUT" , "300.0" ))
4339 langfuse_host = os .getenv ("LANGFUSE_HOST" , "https://cloud.langfuse.com" )
4440
@@ -66,7 +62,6 @@ def build_proxy_config(
6662 raise ValueError (f"Invalid format in secrets file { secrets_path .name } : { e } " )
6763
6864 return ProxyConfig (
69- litellm_url = litellm_url ,
7065 request_timeout = request_timeout ,
7166 langfuse_host = langfuse_host ,
7267 langfuse_keys = langfuse_keys ,
@@ -113,6 +108,16 @@ async def lifespan(app: FastAPI):
113108 app .state .config = build_proxy_config (preprocess_chat_request , preprocess_traces_request )
114109 app .state .redis = init_redis ()
115110
111+ config = app .state .config
112+ default_keys = config .langfuse_keys [config .default_project_id ]
113+ os .environ ["LANGFUSE_PUBLIC_KEY" ] = default_keys ["public_key" ]
114+ os .environ ["LANGFUSE_SECRET_KEY" ] = default_keys ["secret_key" ]
115+ os .environ .setdefault ("LANGFUSE_HOST" , config .langfuse_host )
116+
117+ import litellm
118+
119+ litellm .callbacks = ["langfuse_otel" ]
120+
116121 try :
117122 yield
118123 finally :
@@ -297,13 +302,4 @@ async def pointwise_get_langfuse_trace(
297302 async def health ():
298303 return {"status" : "healthy" , "service" : "metadata-proxy" }
299304
300- # Catch-all
301- @app .api_route ("/{path:path}" , methods = ["GET" , "POST" , "PUT" , "DELETE" , "PATCH" ])
302- async def catch_all_proxy (
303- path : str ,
304- request : Request ,
305- config : ProxyConfig = Depends (get_config ),
306- ):
307- return await proxy_to_litellm (config , path , request )
308-
309305 return app
0 commit comments