Set up Gemini API Keys for Discourse AI

How to Set Up Gemini API Keys for Discourse AI

Introduction

This topic covers how to set up your Google Gemini API key with an existing Google Cloud account project. Gemini is not a free service, and therefore, you will need to ensure you have billing configured in your Google Cloud admin.

There is some important information with links in the Gemini Developer studio key generating page about this:

Ok, let’s get started!

:point_up: NOTE: Admin level access to Google Cloud and your Discourse forum are required.


Step 1: Setting up a Google Cloud Project

Setting up a Gemini API key properly requires you to have admin access to your Google Cloud account, and to create a billing project there you can use for your Gemini API key usage.

You may create your key in the Gemini Studio and connect to your Google Cloud, but it is somewhat easier to do it all from the Google Cloud console so you don’t have to go back and forth.

Go to Google Cloud admin for API for your organization, and make sure you are in the parent organization (you can see it in the field at top next to the Google Cloud logo).

You will have to create a project for your Gemini key if you haven’t got one already that you want to use (note the link to select or create a new project is at top left of page).

For a new project, complete the create new project page (make sure your organization is selected in the appropriate drop-down field).

The image shows a computer screen displaying a dialogue box with a prompt for new project creation.  (Captioned by AI)

For managing billing for your project, you will need to set up a billing account for the project in Google Cloud billing, assuming you have billing configured for your organization. You (or your billing account manager) should be able to do this later after the key is created. Note that there are quotas on projects and billing projects depending on your organization’s Google Cloud account. To enable billing on your project, go to the Billing tab in the Google Cloud navigation menu and link a billing account (see the “Manage Billing Accounts” link) and enable billing for the project from the billing projects page.


Step 2: Create a Gemini API Key

:warning: IMPORTANT! Remember to use your API keys securely. Please carefully read Keep your API key secure and Best practices for securely using API keys before proceeding.

Now you are ready to create an API key in the project. Go to the credentials for that project, click the “+ create credentials” link at the top, and select “API key” from the drop-down options.

A new API key will be created for you. Copy and secure it in a safe place like a password vault application. Do not share keys. This is the key you will need to enter into your Discourse AI settings.

The key should now be listed in your API keys. Click on it to edit the API key

Give the key an appropriate name, and then go down to the API Restrictions section and select “Restrict key”, then choose “Generative Language API”.

Save your updated key. Click the “Show key” link for your new key and copy it.


Step 3: Configure Gemini in Discourse AI Settings

Now go to your Discourse instance and paste your API key into your Discourse AI settings in Admin > Plugins > AI > LLMs for whichever Gemini LLM you wish to use:


Step 4: Tracking Gemini API Key Usage

You can track your Gemini API key usage from your Google Cloud dashboard in billing under “Manage Billing Account”

And then select your specific project from the billing project list, and it will bring up the billing report where you can specify the project(s) and various other details you want to use to track your API key projects (you can track other Google API keys attached to your Google Cloud account here as well, for example, if you have Google Custom Search API and Programmable Search Engine configured).


Links

Last edited by @Lilly 2024-08-08T08:14:48Z

Check documentPerform check on document:
2 Likes