mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
(docs) add doc string for check_valid_api_key
This commit is contained in:
parent
545c34e862
commit
4a32272bfd
1 changed files with 10 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue