mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 03:34:10 +00:00
fix check_if_token_is_service_account
This commit is contained in:
parent
b0fa934fe3
commit
f8ce30763e
4 changed files with 57 additions and 63 deletions
|
@ -4453,6 +4453,42 @@
|
||||||
"source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models",
|
"source": "https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models#foundation_models",
|
||||||
"supports_tool_choice": true
|
"supports_tool_choice": true
|
||||||
},
|
},
|
||||||
|
"gemini-2.5-pro-exp-03-25": {
|
||||||
|
"max_tokens": 65536,
|
||||||
|
"max_input_tokens": 1048576,
|
||||||
|
"max_output_tokens": 65536,
|
||||||
|
"max_images_per_prompt": 3000,
|
||||||
|
"max_videos_per_prompt": 10,
|
||||||
|
"max_video_length": 1,
|
||||||
|
"max_audio_length_hours": 8.4,
|
||||||
|
"max_audio_per_prompt": 1,
|
||||||
|
"max_pdf_size_mb": 30,
|
||||||
|
"input_cost_per_image": 0,
|
||||||
|
"input_cost_per_video_per_second": 0,
|
||||||
|
"input_cost_per_audio_per_second": 0,
|
||||||
|
"input_cost_per_token": 0,
|
||||||
|
"input_cost_per_character": 0,
|
||||||
|
"input_cost_per_token_above_128k_tokens": 0,
|
||||||
|
"input_cost_per_character_above_128k_tokens": 0,
|
||||||
|
"input_cost_per_image_above_128k_tokens": 0,
|
||||||
|
"input_cost_per_video_per_second_above_128k_tokens": 0,
|
||||||
|
"input_cost_per_audio_per_second_above_128k_tokens": 0,
|
||||||
|
"output_cost_per_token": 0,
|
||||||
|
"output_cost_per_character": 0,
|
||||||
|
"output_cost_per_token_above_128k_tokens": 0,
|
||||||
|
"output_cost_per_character_above_128k_tokens": 0,
|
||||||
|
"litellm_provider": "vertex_ai-language-models",
|
||||||
|
"mode": "chat",
|
||||||
|
"supports_system_messages": true,
|
||||||
|
"supports_function_calling": true,
|
||||||
|
"supports_vision": true,
|
||||||
|
"supports_audio_input": true,
|
||||||
|
"supports_video_input": true,
|
||||||
|
"supports_pdf_input": true,
|
||||||
|
"supports_response_schema": true,
|
||||||
|
"supports_tool_choice": true,
|
||||||
|
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing"
|
||||||
|
},
|
||||||
"gemini-2.0-pro-exp-02-05": {
|
"gemini-2.0-pro-exp-02-05": {
|
||||||
"max_tokens": 8192,
|
"max_tokens": 8192,
|
||||||
"max_input_tokens": 2097152,
|
"max_input_tokens": 2097152,
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
"""
|
|
||||||
Checks for LiteLLM service account keys
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
from litellm.proxy._types import ProxyErrorTypes, ProxyException, UserAPIKeyAuth
|
|
||||||
|
|
||||||
|
|
||||||
def check_if_token_is_service_account(valid_token: UserAPIKeyAuth) -> bool:
|
|
||||||
"""
|
|
||||||
Checks if the token is a service account
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: True if token is a service account
|
|
||||||
|
|
||||||
"""
|
|
||||||
if valid_token.metadata:
|
|
||||||
if "service_account_id" in valid_token.metadata:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def service_account_checks(
|
|
||||||
valid_token: UserAPIKeyAuth, request_data: dict
|
|
||||||
) -> bool:
|
|
||||||
"""
|
|
||||||
If a virtual key is a service account, checks it's a valid service account
|
|
||||||
|
|
||||||
A token is a service account if it has a service_account_id in its metadata
|
|
||||||
|
|
||||||
Service Account Specific Checks:
|
|
||||||
- Check if required_params is set
|
|
||||||
"""
|
|
||||||
|
|
||||||
if check_if_token_is_service_account(valid_token) is not True:
|
|
||||||
return True
|
|
||||||
|
|
||||||
from litellm.proxy.proxy_server import general_settings
|
|
||||||
|
|
||||||
if "service_account_settings" in general_settings:
|
|
||||||
service_account_settings = general_settings["service_account_settings"]
|
|
||||||
if "enforced_params" in service_account_settings:
|
|
||||||
_enforced_params = service_account_settings["enforced_params"]
|
|
||||||
for param in _enforced_params:
|
|
||||||
if param not in request_data:
|
|
||||||
raise ProxyException(
|
|
||||||
type=ProxyErrorTypes.bad_request_error.value,
|
|
||||||
code=400,
|
|
||||||
param=param,
|
|
||||||
message=f"BadRequest please pass param={param} in request body. This is a required param for service account",
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
|
|
@ -747,7 +747,10 @@ def _get_enforced_params(
|
||||||
enforced_params: Optional[list] = None
|
enforced_params: Optional[list] = None
|
||||||
if general_settings is not None:
|
if general_settings is not None:
|
||||||
enforced_params = general_settings.get("enforced_params")
|
enforced_params = general_settings.get("enforced_params")
|
||||||
if "service_account_settings" in general_settings:
|
if (
|
||||||
|
"service_account_settings" in general_settings
|
||||||
|
and check_if_token_is_service_account(user_api_key_dict) is True
|
||||||
|
):
|
||||||
service_account_settings = general_settings["service_account_settings"]
|
service_account_settings = general_settings["service_account_settings"]
|
||||||
if "enforced_params" in service_account_settings:
|
if "enforced_params" in service_account_settings:
|
||||||
if enforced_params is None:
|
if enforced_params is None:
|
||||||
|
@ -760,6 +763,20 @@ def _get_enforced_params(
|
||||||
return enforced_params
|
return enforced_params
|
||||||
|
|
||||||
|
|
||||||
|
def check_if_token_is_service_account(valid_token: UserAPIKeyAuth) -> bool:
|
||||||
|
"""
|
||||||
|
Checks if the token is a service account
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: True if token is a service account
|
||||||
|
|
||||||
|
"""
|
||||||
|
if valid_token.metadata:
|
||||||
|
if "service_account_id" in valid_token.metadata:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _enforced_params_check(
|
def _enforced_params_check(
|
||||||
request_body: dict,
|
request_body: dict,
|
||||||
general_settings: Optional[dict],
|
general_settings: Optional[dict],
|
||||||
|
|
|
@ -4,12 +4,6 @@ model_list:
|
||||||
model: openai/gpt-4o
|
model: openai/gpt-4o
|
||||||
api_key: sk-xxxxxxx
|
api_key: sk-xxxxxxx
|
||||||
|
|
||||||
mcp_servers:
|
general_settings:
|
||||||
{
|
service_account_settings:
|
||||||
"zapier_mcp": {
|
enforced_params: ["user"] # this means the "user" param is enforced for all requests made through any service account keys
|
||||||
"url": "https://actions.zapier.com/mcp/sk-akxxxxx/sse"
|
|
||||||
},
|
|
||||||
"fetch": {
|
|
||||||
"url": "http://localhost:8000/sse"
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue