Search code examples
google-translategoogle-translation-api

Add IP limitation at Google Translation API


How can I limit the access to the Google Translation API to only a specific IP, the IP of my server? Because someone else is using my API and I hit the limit of requests frequently


Solution

  • The authentication to Translation API can be done with two main methods:

    • Using a service account: the service account key can be downloaded as a JSON file, and only the people who own that file will be able to authorize their requests against your API.
    • Using an API key: it is a simple encrypted string that can be used for authentication when calling certain Google Cloud APIs. When using this method, you should follow the best practices, which include the method you ask for in your question, restricting API key usage by IP address. You can do that following the guide in this documentation page, which consists in:

      1. Go to the Credentials page inside the APIs & Services tab in your Console.

      2. Select the Create credentials drop-down menu and then on API key. Step 2

      3. In the pop up menu that will appear, click on Restrict key. Step 3
      4. Choose the IP addresses option and type the IP address you want to allow. Then save. Step 4 Then you will be able to use that API key as a secure method for accepting requests only from your server.