forked from tavily-ai/crawl2rag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
36 lines (25 loc) · 816 Bytes
/
utils.py
File metadata and controls
36 lines (25 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
from requests.exceptions import RequestException
TAVILY_API_ENDPOINT = "https://api.tavily.com"
def check_api_key(api_key: str) -> bool:
"""
Check if the API key is authorized for the given use case
Args:
api_key: The API key to check
Returns:
bool: True if authorized
"""
try:
payload = {"api_key": api_key, "use_case": "chat"}
response = requests.post(
f"{TAVILY_API_ENDPOINT}/authorize-use-case", json=payload
)
response.raise_for_status()
result = response.json()
if not result.get("success"):
raise requests.exceptions.HTTPError("Authorization failed")
return True
except requests.exceptions.HTTPError:
raise
except RequestException:
raise