fix: google api sync request (#6292)

* fix: google api sync request

* remove unused function
This commit is contained in:
cthomas
2025-11-20 11:00:54 -08:00
committed by Caren Thomas
parent 32e4caf0d2
commit 1c358c863e
2 changed files with 7 additions and 4 deletions

View File

@@ -49,11 +49,14 @@ def get_gemini_endpoint_and_headers(
return url, headers
def google_ai_check_valid_api_key(api_key: str):
async def google_ai_check_valid_api_key_async(api_key: str):
"""
Async version to check if Google AI API key is valid without blocking the event loop.
"""
client = genai.Client(api_key=api_key)
# use the count token endpoint for a cheap model - as of 5/7/2025 this is slightly faster than fetching the list of models
try:
client.models.count_tokens(
await client.aio.models.count_tokens(
model=GOOGLE_MODEL_FOR_API_KEY_CHECK,
contents="",
)

View File

@@ -21,10 +21,10 @@ class GoogleAIProvider(Provider):
base_url: str = "https://generativelanguage.googleapis.com"
async def check_api_key(self):
from letta.llm_api.google_ai_client import google_ai_check_valid_api_key
from letta.llm_api.google_ai_client import google_ai_check_valid_api_key_async
api_key = self.get_api_key_secret().get_plaintext()
google_ai_check_valid_api_key(api_key)
await google_ai_check_valid_api_key_async(api_key)
async def list_llm_models_async(self):
from letta.llm_api.google_ai_client import google_ai_get_model_list_async