(docs) add doc string for check_valid_api_key

This commit is contained in:
ishaan-jaff 2023-10-30 14:02:30 -07:00
parent 545c34e862
commit 4a32272bfd

View file

@ -2508,10 +2508,17 @@ def valid_model(model):
except:
raise InvalidRequestError(message="", model=model, llm_provider="")
# check valid api key
def check_valid_key(model: str, api_key: str):
# returns True if key is valid for the model
# returns False if key is invalid for the model
"""
Checks if a given API key is valid for a specific model by making a litellm.completion call with max_tokens=10
Args:
model (str): The name of the model to check the API key against.
api_key (str): The API key to be checked.
Returns:
bool: True if the API key is valid for the model, False otherwise.
"""
messages = [{"role": "user", "content": "Hey, how's it going?"}]
try:
litellm.completion(model=model, messages=messages, api_key=api_key, max_tokens=10)