Authenticate to Cloud Translation

This document describes how to authenticate to Cloud Translation programmatically. How you authenticate to Cloud Translation depends on the interface you use to access the API and the environment where your code is running.

For more information about Google Cloud authentication, see the Authentication methods.

API access

Cloud Translation supports programmatic access. You can access the API in the following ways:

Client libraries

The Cloud Translation - Advanced client libraries provide high-level language support for authenticating to Cloud Translation programmatically. To authenticate calls to Google Cloud APIs, client libraries support Application Default Credentials (ADC); the libraries look for credentials in a set of defined locations and use those credentials to authenticate requests to the API. With ADC, you can make credentials available to your application in a variety of environments, such as local development or production, without needing to modify your application code.

REST

You can authenticate to the Cloud Translation API by using your gcloud CLI credentials or by using Application Default Credentials. For more information about authentication for REST requests, see Authenticate for using REST.

API keys

API keys provide a way to associate an API call with a project, which is used for billing and quota purposes, without determining the identity of the caller. API keys can be used only with API methods that support API keys.

Cloud Translation supports API keys for the following API methods:

  • All methods for the Cloud Translation - Basic API (v2) support API keys, such as translate and detect. The Cloud Translation - Advanced API (v3) does not support API keys.

For general information about using API keys, see Authenticate using API keys.

User credentials and ADC for Cloud Translation

One way to provide credentials to ADC is to use the gcloud CLI to insert your user credentials into a credential file. This file is placed on your local file system where ADC can find it; ADC then uses the provided user credentials to authenticate requests. This method is often used for local development.

If you use this method, you might encounter an authentication error when you try to authenticate to Cloud Translation. For more information about this error and how to address it, see User credentials not working.

Set up authentication for Cloud Translation

How you set up authentication depends on the environment where your code is running.

The following options for setting up authentication are the most commonly used. For more options and information about authentication, see Authentication methods.

Before you complete these instructions, you must complete the basic setup for Cloud Translation, as described in Set up Cloud Translation.

For a local development environment

You can set up credentials for a local development environment in the following ways:

Client libraries or third-party tools

Set up Application Default Credentials (ADC) in your local environment:

  1. Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

    gcloud init

    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  2. If you're using a local shell, then create local authentication credentials for your user account:

    gcloud auth application-default login

    You don't need to do this if you're using Cloud Shell.