mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 11:14:04 +00:00
[Feature]: Proxy: Support API-Key
This commit is contained in:
parent
205ade22e5
commit
8de7074614
1 changed files with 12 additions and 1 deletions
|
@ -368,6 +368,11 @@ from typing import Dict
|
||||||
api_key_header = APIKeyHeader(
|
api_key_header = APIKeyHeader(
|
||||||
name="Authorization", auto_error=False, description="Bearer token"
|
name="Authorization", auto_error=False, description="Bearer token"
|
||||||
)
|
)
|
||||||
|
azure_api_key_header = APIKeyHeader(
|
||||||
|
name="API-Key",
|
||||||
|
auto_error=False,
|
||||||
|
description="Some older versions of the openai Python package will send an API-Key header with just the API key ",
|
||||||
|
)
|
||||||
user_api_base = None
|
user_api_base = None
|
||||||
user_model = None
|
user_model = None
|
||||||
user_debug = False
|
user_debug = False
|
||||||
|
@ -508,13 +513,19 @@ async def check_request_disconnection(request: Request, llm_api_call_task):
|
||||||
|
|
||||||
|
|
||||||
async def user_api_key_auth(
|
async def user_api_key_auth(
|
||||||
request: Request, api_key: str = fastapi.Security(api_key_header)
|
request: Request,
|
||||||
|
api_key: str = fastapi.Security(api_key_header),
|
||||||
|
azure_api_key_header: str = fastapi.Security(azure_api_key_header),
|
||||||
) -> UserAPIKeyAuth:
|
) -> UserAPIKeyAuth:
|
||||||
global master_key, prisma_client, llm_model_list, user_custom_auth, custom_db_client, general_settings, proxy_logging_obj
|
global master_key, prisma_client, llm_model_list, user_custom_auth, custom_db_client, general_settings, proxy_logging_obj
|
||||||
try:
|
try:
|
||||||
if isinstance(api_key, str):
|
if isinstance(api_key, str):
|
||||||
passed_in_key = api_key
|
passed_in_key = api_key
|
||||||
api_key = _get_bearer_token(api_key=api_key)
|
api_key = _get_bearer_token(api_key=api_key)
|
||||||
|
|
||||||
|
elif isinstance(azure_api_key_header, str):
|
||||||
|
api_key = azure_api_key_header
|
||||||
|
|
||||||
parent_otel_span: Optional[Span] = None
|
parent_otel_span: Optional[Span] = None
|
||||||
if open_telemetry_logger is not None:
|
if open_telemetry_logger is not None:
|
||||||
parent_otel_span = open_telemetry_logger.tracer.start_span(
|
parent_otel_span = open_telemetry_logger.tracer.start_span(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue