Japanese Text Labels, by Conor Luddy

Many external services that use the Google cloud require an API Key to work. But what is an API Key and how can you get one? This is what I’m going to explain you right now.

In this article we’ll see how to obtain an API Key to be able to use Google Cloud Translate, but the process is the same if we want to obtain an API Key for another Google Cloud service, such as Google Maps.

Lets start by the beginning… An API Key is nothing more than a string that we use as a license key for a particular service. In our example, a Google API Key will allow us to access any of Google’s cloud services from an external application. Without this key we can not make authenticated calls to Google Cloud services from a third-party application, and therefore the application that requires this key will not work.

Now that we understand what an API Key is, let’s see how to get one for Google Translate.

How to Create a New Account in Google Cloud Console

The first thing you need is an account in Google Cloud Console and a payment method in it. To do this, follow these steps:

  • Access the Google Cloud Console and log in or, if you do not have an account yet, sign up.
  • Open the left side menu of the console and select Billing.
  • Click on the button New billing account. Keep in mind that if this is not your first billing account, you must first open the list of billing accounts. To do this, click on the name of your existing billing account near the top of the page and then click on Manage billing accounts.
  • Enter the name of the billing account and your billing information. The options you’ll see depend on the country of your billing address.
  • Click Submit and enable billing.
Main screen of Google Cloud Console.
Main screen of Google Cloud Console.

By default, the person creating the billing account is a billing administrator for the account. Once you have the account created and the billing information ready, you can continue with the following steps to obtain the API Key.

How to Create a New Project in Google Cloud

Go to the bar in the top of the window and in the drop-down you can see your created projects as well as the option to create a new one by clicking on the New Project button:

Project selection and creation screen in Google Cloud.
Project selection and creation screen in Google Cloud.

Now give the new project a name and create it by clicking on the corresponding button, as you can see in the following screenshot:

Creation view of a new project in Google Cloud.
Creation view of a new project in Google Cloud.

At this point you should already have the project created and selected, so let’s move on.

Activate the Google Translate API

Before you can use a Google API in your project, you have to activate it. Go to the side menu and select the APIs & Services option:

Google Cloud APIs and services menu.
Google Cloud APIs and services menu.

Now you will see a screen with statistics about the APIs that you have activated. If you created the project from scratch by following the steps above, you won’t have any data yet, as you can see:

Dashboard of Google Cloud APIs and services.
Dashboard of Google Cloud APIs and services.

Click on the upper button Enable APIs and services to continue with the activation process of the API. This takes us to a search box where we have to look for the API we’re interested in. In this case, we want to use the Google Translate API. Type translate in the search box and click on the result Cloud Translate API:

API search view for later activation in our Google Cloud project.
API search view for later activation in our Google Cloud project.

This brings us to a screen with the description of the Cloud Translation API. Click on the Enable button to activate the API in our project:

Before you can start using the Google Translate API in our project, you have to activate it in Google Cloud.
Before you can start using the Google Translate API in our project, you have to activate it in Google Cloud.

We already have the Google Cloud Translation API activated. We’re almost there…

Create a new API Key for Google Translate

After activating the API, let’s see how to generate a new Key API to be able to use this service. We have to go to the side menu again and select the Credentials option:

Google Cloud Translate credential management menu.
Google Cloud Translate credentials management menu.

On this screen we see a button with a drop-down and the text Create credentials. Don’t click on the button! Instead, open the drop-down by clicking on the arrow to the right of the button and select the API Key option.

You must select the type of Key API credential to create a new key for the Google Translate API.
You must select the API Key credential to create a new key for the Google Translate API.

This creates the new Key API. You can copy it if you want, although you can access it later:

Google Cloud provides us with a new Key API to use Google Translate with our third-party applications.
Google Cloud provides us with a new Key API to use Google Translate with our third-party applications.

How to Restrict Our API Key to Protect and Limit Its Use

To control the cost of Google Cloud by using the Google Cloud Translation API (or Google Translate, which is the same), we can do two things: restrict where you can use the API Key that we just created or limit the allowed quota to use the service itself.

In the screenshot above, if you click on the Restrict Key button you will go to the API Key restriction screen that follows:

We can restrict from which web domain we can use the Key API that we just generated to avoid misuse of it in case of loss.
We can restrict from which web domain we can use the API Key that we just generated.

There you can select to restrict the API Key by HTTP referrers, which means that you can only make calls to the Google Cloud Translate API using the API Key from certain domain names.

You must add the valid domain names in the text box that appears when selecting the HTTP referrers option. In our case, we have added here our domain name https://neliosoftware.com/*.

On the other hand, go to the menu API’s & ServicesDashboardCloud Translation APIQuotas and there you will find a box called Characters. There you can modify the quota limits of the Google Cloud Translation API and reduce them, if necessary.

The price for Google Cloud Translation API at the time of writing this post is 20 USD per million translated characters, so make your numbers.

Google Cloud allows us to limit the use we make of the APIs in order to control the maximum consumption we want to end up paying.
Google Cloud allows us to limit the use of the APIs to control the maximum cost we want to end up paying.

And that’s all! You already have your API Key ready to be used with the application you want. The process is a bit cumbersome at first, but following the steps you’ll get the API Key without problems. Try it and let me know if you need further assistance!

Featured image by Conor Luddy on Unsplash.

6 responses to “How To Generate an API Key For Google Translate”

  1. broof Avatar
    broof

    i’m sorry, i want to give you a 5 rating but I clicked the first star and it immediately gave you a 1 rating. i tried to do it a second time but it only allows 1 rating per user. i want to change the rating but do not know how. This is an excellent post!!!! and helped me out a lot!!!!

    1. Antonio Villegas Avatar

      Don’t worry! We managed to change your vote 🙂

  2. me Avatar
    me

    thank you, it is useful

  3. ss Avatar
    ss

    Very useful, thanks! Seemed overwhelming at times before finding this guide.

  4. Melcu Susan Avatar
    Melcu Susan

    hello. how much does this API key cost? And, if I want to use this API key for translate, what exactly will help me this API key for translation?

    1. Antonio Villegas Avatar

      Hi Melcu. The API key is free, but you pay for the cost of translating a number of strings. The point is that you need the API to use the translation service. Check the Google Cloud site to know exactly the pricing.

Leave a Reply

Your email address will not be published. Required fields are marked *

I have read and agree to the Nelio Software Privacy Policy

Your personal data will be located on SiteGround and will be treated by Nelio Software with the sole purpose of publishing this comment here. The legitimation is carried out through your express consent. Contact us to access, rectify, limit, or delete your data.