k_ug
k_ug

Reputation: 43

How can I check Google Gemini API key is valid or not

I want to make a image recognition system that uses Google Gemini. The system recognize an image by using 2 methods, that are rule based logic and logic with Gemini.

Therefore I'd check if Gemini API key is correct and if that is incorrect then use only rule based logic.

I'm searching for the way of validate Gemini API key, one simple way is just send request with given API key. But this way takes so much time. And even though API failed, it is difficult to distinguish the error is caused by incorrect API key or not.

So are there any good way to check Gemini API key?

Environment: OS:Ubuntu language: Python3.11

Upvotes: 0

Views: 1834

Answers (1)

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117176

The best way to check if it works is to use it. If it doesn't work it will fail just catch the exception.

So make your call and if it fails you know you cant use it.

Upvotes: 3

Related Questions