Nikita Makarov commited on
Commit
72cf384
·
1 Parent(s): c32d840

Improve API key debugging in Modal proxy

Browse files
Files changed (1) hide show
  1. modal_proxy.py +10 -4
modal_proxy.py CHANGED
@@ -27,13 +27,19 @@ def search_youtube(query: str, limit: int = 5) -> Dict[str, Any]:
27
  # YouTube Data API v3 search endpoint
28
  url = "https://www.googleapis.com/youtube/v3/search"
29
  # Get API key from Modal secret
30
- # Modal secrets are available as environment variables with the same name as the secret
 
31
  api_key = os.environ.get("YOUTUBE_API_KEY", "")
32
  if not api_key:
33
- # Try alternative names that Modal might use
34
- api_key = os.environ.get("youtubeapikey", "")
 
 
 
35
  if not api_key:
36
- return {"success": False, "error": f"YouTube API key not found. Available env vars: {list(os.environ.keys())}", "tracks": []}
 
 
37
 
38
  params = {
39
  'part': 'snippet',
 
27
  # YouTube Data API v3 search endpoint
28
  url = "https://www.googleapis.com/youtube/v3/search"
29
  # Get API key from Modal secret
30
+ # In Modal, secrets are injected as environment variables
31
+ # The secret name "youtubeapikey" should make the key available as YOUTUBE_API_KEY
32
  api_key = os.environ.get("YOUTUBE_API_KEY", "")
33
  if not api_key:
34
+ # If not found, try the secret name directly
35
+ secret_data = os.environ.get("youtubeapikey", "")
36
+ if secret_data:
37
+ api_key = secret_data
38
+
39
  if not api_key:
40
+ # Debug: show what environment variables are available
41
+ available_vars = [k for k in os.environ.keys() if 'key' in k.lower() or 'api' in k.lower()]
42
+ return {"success": False, "error": f"YouTube API key not found. Check Modal secret 'youtubeapikey' has YOUTUBE_API_KEY variable. Available key vars: {available_vars}", "tracks": []}
43
 
44
  params = {
45
  'part': 'snippet',