Check api key doesn't do anything
It seems is_api_key_valid returns True whenever anything (truthy) is passed in. Is this the intended behaviour? I would have guessed this function queries the server to check that the key is valid.
https://github.com/cohere-ai/cohere-python/blob/29e118e390dbe116b7d0c6ff734de80f742c1dd1/cohere/utils.py#L44-L51
Hi @seabo, this function checks the API key:
https://github.com/cohere-ai/cohere-python/blob/16454c56d646f7eebfc927257c7cf3a25678dd3a/cohere/client.py#L640
Ps: I agree the name is_api_key_valid could be better.
Hi @jairojair - thanks. So are you saying that the purpose of Client.check_api_key is simply to locally test for the presence of any string? Because this function returns True for any arbitrary string you pass as the API key.
Is there a way to test that the key being used is actually valid (i.e. authorised) on the server?
If you run:
import cohere
co = cohere.Client()
prediction = co.generate(prompt='co:here')
You will be receiving this exception:
line 47, in is_api_key_valid
raise CohereError(
cohere.error.CohereError: No API key provided. Provide the API key in the client initialization or the CO_API_KEY environment variable.
if you run:
import cohere
co = cohere.Client('YOUR_API_KEY')
prediction = co.generate(prompt='co:here')
You will be receive this exception:
line 640, in _check_response
raise CohereAPIError(
cohere.error.CohereAPIError: invalid api token
Indeed, you are correct. Validate keys exclusively on the server side are crucial for enhanced security and data integrity. Maybe in the future, we could use the is_api_key_valid function to validate the format and key size, which is a good approach.