mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
feat - setting up auth on pass through endpoint
This commit is contained in:
parent
1c9dce8020
commit
3dc6430fef
1 changed files with 22 additions and 2 deletions
|
@ -3,12 +3,21 @@ import traceback
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import APIRouter, FastAPI, HTTPException, Request, Response, status
|
from fastapi import (
|
||||||
|
APIRouter,
|
||||||
|
Depends,
|
||||||
|
FastAPI,
|
||||||
|
HTTPException,
|
||||||
|
Request,
|
||||||
|
Response,
|
||||||
|
status,
|
||||||
|
)
|
||||||
from fastapi.responses import StreamingResponse
|
from fastapi.responses import StreamingResponse
|
||||||
|
|
||||||
import litellm
|
import litellm
|
||||||
from litellm._logging import verbose_proxy_logger
|
from litellm._logging import verbose_proxy_logger
|
||||||
from litellm.proxy._types import ProxyException
|
from litellm.proxy._types import ProxyException
|
||||||
|
from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
|
||||||
|
|
||||||
async_client = httpx.AsyncClient()
|
async_client = httpx.AsyncClient()
|
||||||
|
|
||||||
|
@ -129,7 +138,8 @@ def create_pass_through_route(endpoint, target, custom_headers=None):
|
||||||
async def initialize_pass_through_endpoints(pass_through_endpoints: list):
|
async def initialize_pass_through_endpoints(pass_through_endpoints: list):
|
||||||
|
|
||||||
verbose_proxy_logger.debug("initializing pass through endpoints")
|
verbose_proxy_logger.debug("initializing pass through endpoints")
|
||||||
from litellm.proxy.proxy_server import app
|
from litellm.proxy._types import CommonProxyErrors, LiteLLMRoutes
|
||||||
|
from litellm.proxy.proxy_server import app, premium_user
|
||||||
|
|
||||||
for endpoint in pass_through_endpoints:
|
for endpoint in pass_through_endpoints:
|
||||||
_target = endpoint.get("target", None)
|
_target = endpoint.get("target", None)
|
||||||
|
@ -138,6 +148,15 @@ async def initialize_pass_through_endpoints(pass_through_endpoints: list):
|
||||||
_custom_headers = await set_env_variables_in_header(
|
_custom_headers = await set_env_variables_in_header(
|
||||||
custom_headers=_custom_headers
|
custom_headers=_custom_headers
|
||||||
)
|
)
|
||||||
|
_auth = endpoint.get("auth", None)
|
||||||
|
_dependencies = None
|
||||||
|
if _auth is not None and str(_auth).lower() == "true":
|
||||||
|
if premium_user is not True:
|
||||||
|
raise ValueError(
|
||||||
|
f"Error Setting Authentication on Pass Through Endpoint: {CommonProxyErrors.not_premium_user}"
|
||||||
|
)
|
||||||
|
_dependencies = [Depends(user_api_key_auth)]
|
||||||
|
LiteLLMRoutes.openai_routes.value.append(_path)
|
||||||
|
|
||||||
if _target is None:
|
if _target is None:
|
||||||
continue
|
continue
|
||||||
|
@ -148,6 +167,7 @@ async def initialize_pass_through_endpoints(pass_through_endpoints: list):
|
||||||
path=_path,
|
path=_path,
|
||||||
endpoint=create_pass_through_route(_path, _target, _custom_headers),
|
endpoint=create_pass_through_route(_path, _target, _custom_headers),
|
||||||
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
|
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
|
||||||
|
dependencies=_dependencies,
|
||||||
)
|
)
|
||||||
|
|
||||||
verbose_proxy_logger.debug("Added new pass through endpoint: %s", _path)
|
verbose_proxy_logger.debug("Added new pass through endpoint: %s", _path)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue