Private GenAI chat with Librechat.ai - Part 3
Let’s continue our journey of building a private GenAI chat with Librechat.ai. Part 2 of the series is here.
This post explains how to set up an API access to Google Search and YouTube. You will learn how to:
- Create your Custom Search Engine and get its ID
- This is the necessary step. This ID is used to identify your search engine when you make requests to the Google Search API. And you can also configure your search engine to your liking.
- Create a new project in Google Cloud Console
- Enable API access to Custom Search and YouTube Data API
- Create API Keys and put restrictions on them
Prerequisites
- You need to have a Google account. If you don’t have one, you can create it here.
- You need to have a Google Cloud account. If you don’t have one, you can create it here.
- Use this video tutorial from Google Cloud Tech channel.
My video tutorial
I created this video tutorial where I demonstrate all steps.
Note: You can use one API key for both Custom Search and YouTube Data API. But for security reasons, I recommend creating separate API keys for each service.
Creating Custom Search Engine
To create a custom search engine:
- Open the Custom Search Engine page and click on the “Add” button.
- In the appeared form you need to provide a name for your search engine. And in the “What to search?” field select “Search the entire web”.
- Then confirm that you are not a robot and click on the “Create” button.
- When the search engine is created, you will see a page with the search engine ID. This ID is used to identify your search engine when you make requests to the Google Search API.
- Copy and save this ID, you will need it later.
Later you can use configure your search engine by getting to it from the Programmable Search Engine Control Panel. I will not provide you all details of the configuration, but custom search engine allows you to set up:
- Search region and restrict results to a specific region.
- Limit search results to specific sites or domains.
- Exclude certain sites or domains from the search results.
- Configure number of results per page, their sorting preference and other options.
- Add other users to your search engine and give them access to it.
Enable API access in the Google Cloud Console
If you already have a project in Google Cloud, you can keep using it and just enable access to Custom Search and YouTube Data APIs. But I would recommend creating a new project, specific for Librechat installation. This way you can easier manage your access, API keys, permissions and budget.
Creating a new project and enabling APIs
- Open the Google Cloud Console and create a new project.
- Go the created project and on the “Quick access” panel click on the “APIs and services” link.
- On the top of the “APIs and services” page click on the “Enable APIs and services” button.
- In the appeared page search for “Custom Search API” and click on it. On the next page click on the “Enable” button.
- Repeat the same steps for “YouTube Data API v3”.
About API quotas
In the Google Cloud Console for each API you can see the quotas and limits. For personal use by one or two users, the free tier is enough. But you can always increase the quota if you need it.
Here are default limits for the APIs:
-
Custom Search API:
- 10 000 queries per day for free.
- 100 queries per minute per user for free.
-
YouTube Data API:
- 10 000 queries per day for free.
- 180 000 queries per minute per user.
I don’t change Custom Search API limits but I tune down the YouTube Data API quota. My Librechat.ai instance serves max 4 users, hence I set 100 queries per minute per user (because my API key is used by all users of my Librechat instance) and 1000 queries per day. It is more than enough for an active use.
Creating API keys
After both APIs are enabled, you can create API keys for them. Click on the “Credentials” link in the left menu.
You can use one API key for both APIs, but I would recommend creating separate API keys for each service. With this you will separate concerns and if one key is compromised, it can be revoked without affecting the other service.
Creating the API key for Custom Search API:
- Click on the “Create credentials” button and select “API key”.
- After the key is created, you will see a pop-up with the key. Copy and save it, you will need it later.
- Put a note that this key is for Custom Search API.
- Go to the “Edit API key” page and set the following parameters:
- Rename the key to something meaningful, e.g. “Librechat Custom Search API Key”.
- If you host your Librechat.ai instance on a server with static public IP address, then set the Application restrictions to “IP addresses” and add your server’s IP address.
- API restrictions: select “Restrict key” and select “Custom Search API” from the list.
- Click on the “Save” button.
Creating the API key for YouTube Data API
- Click on the “Create credentials” button and select “API key”.
- After the key is created, you will see a pop-up with the key. Copy and save it, you will need it later.
- Put a note that this key is for YouTube Data API.
Steps 3-4 is the same as for Custom Search API key, but give it different name, e.g. “Librechat YouTube Data API Key” and select “YouTube Data API v3” in the API restrictions.
Conclusion
Congratulations! You have successfully created API keys for both Custom Search and YouTube Data APIs. Together with the Amazon Access Keys and Bedrock permissions you created in the previous part of this series, you are now ready to go to the installation of Librechat.ai.
To be continued
In the next part of this series, I will show you how to install Librechat.ai on your server and how to configure it. Go to the next part.