KKIMS on-site docs
Google services

Cloud Translation API key

Create, restrict and test the Google Cloud Translation API key, set a budget, and save it on the CMS Translation screen, for UAT and production.

The CMS machine-translates English pages into Kannada and Hindi with Cloud Translation, Basic edition (v2), authenticated with an API key an Admin pastes into the CMS. This page creates that key, locks it down, tests it, and saves it.

#How the code uses the key

#What is called, and from where

Fact Value (from the code)
Edition Basic, v2. Advanced (v3) does not accept API keys, which is why v2 is used
Endpoint https://translation.googleapis.com/language/translate/v2
Calls GET .../v2/languages?key=... and POST .../v2?key=... with JSON {"q": [...], "source": "en", "target": "<lang>", "format": "html"}
Who calls it The CMS pod (when an Admin saves the key: the test) and the worker pods (translation jobs). The translation-tick CronJob only queues work
Where the key is kept PostgreSQL table secrets, row google.translation.api-key, sealed with AES-256-GCM under SECRETS_KEY
What the screen shows The key's last four characters, who saved it and when
Who may save it CMS Admin (and Superadmin) only: permission translation.manage

#What happens when Google refuses

The worker sorts each refusal into a kind, and the kind decides what happens:

Kind Google's reason, for example What the CMS does
key keyInvalid, API_KEY_INVALID, accessNotConfigured, SERVICE_DISABLED, API_KEY_SERVICE_BLOCKED, ipRefererBlocked, PERMISSION_DENIED, HTTP 401 Every job stops until a working key is saved. Saving one clears the block
quota dailyLimitExceeded, quotaExceeded, billingNotEnabled, BILLING_DISABLED The whole job stops until the next day or until billing is fixed, then resumes by itself
rate HTTP 429, rateLimitExceeded Slows down
transient HTTP 5xx That page waits and is tried again
language HTTP 400 naming the target language That language stops

#Before you start

  • The Google Cloud project exists, with billing linked and the Cloud Translation API enabled (google/cloud-project).
  • You have API Keys Admin (or Editor/Owner) on the project.
  • You know the public IP addresses the EKS pods leave through (see Find the pods' egress IP addresses).
  • An Admin can sign in to the CMS (deploy/people), for the last step.

#Create the key

#Console: create an API key

Make one key per environment: kims-translation-uat and kims-translation-production.

  1. In the Google Cloud console, select the KIMS project in the project picker.
  2. Open the navigation menu > APIs & Services > Credentials.
  3. Click Create credentials > API key.
  4. If the dialog offers a name, enter kims-translation-uat. If it offers Authenticate API calls through a service account, leave it unticked: the CMS needs a standard key.
  5. If the console asks for a restriction before creating (newer consoles do), choose API restrictions > Restrict key > Cloud Translation API.
  6. Click Create.
  7. The API key created dialog shows the key. Copy it straight into KIMS's password vault. Do not paste it into chat, email, tickets or a file in Git.

You should see the key in the API Keys list on the Credentials page, with a warning icon until it is restricted.

Warning

An API key is a secret. Anyone with it can spend KIMS's money on translation. Never put it in a values file, a Jenkins job, a shell command line or this site.

#Rename the key

  1. On Credentials, click the key's name.
  2. Set Name to kims-translation-uat (or -production).
  3. Click Save.

#Restrict the key

#API restriction: Cloud Translation API only

  1. On Credentials, click the key's name.
  2. Under API restrictions, choose Restrict key.
  3. In the drop-down, tick Cloud Translation API only. Untick everything else.
  4. Click Save.

You should see Cloud Translation API listed under the key's restrictions. A refusal from any other API with this key is then expected.

#Find the pods' egress IP addresses

An IP restriction only helps if it lists the public addresses Google sees, which are those of the VPC's NAT gateways (or KIMS's outbound proxy or firewall). Internal (private) addresses are not supported by Google's IP restriction.

Ask from inside a pod, which also proves the pod can reach the internet:

bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> exec deploy/kims-worker -- node -e "fetch('https://checkip.amazonaws.com').then(r=>r.text()).then(t=>console.log(t.trim()))"
bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> exec deploy/kims-worker -- node -e "fetch('https://checkip.amazonaws.com').then(r=>r.text()).then(t=>console.log(t.trim()))"
powershell
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> exec deploy/kims-worker -- node -e "fetch('https://checkip.amazonaws.com').then(r=>r.text()).then(t=>console.log(t.trim()))"

Expected: one public IPv4 address, for example 13.234.10.20. Run it a few times and on the CMS too (deploy/kims-cms): with several NAT gateways (one per Availability Zone) you will see different addresses. Cross-check with AWS:

bash
aws ec2 describe-nat-gateways --region <AWS_REGION> --filter Name=vpc-id,Values=<VPC_ID> Name=state,Values=available --query "NatGateways[].NatGatewayAddresses[].PublicIp" --output text
bash
aws ec2 describe-nat-gateways --region <AWS_REGION> --filter Name=vpc-id,Values=<VPC_ID> Name=state,Values=available --query "NatGateways[].NatGatewayAddresses[].PublicIp" --output text
powershell
aws ec2 describe-nat-gateways --region <AWS_REGION> --filter Name=vpc-id,Values=<VPC_ID> Name=state,Values=available --query "NatGateways[].NatGatewayAddresses[].PublicIp" --output text

Expected: every NAT gateway's Elastic IP, separated by tabs. The list from the pods must be inside this list (or be KIMS's proxy address). If the command needs the VPC ID, aws/networking has it.

The pods do not exist until the first deploy (deploy/first-deploy). It is fine to create the key with only the API restriction first, then add the IP restriction once the pods are running.

#Application restriction: IP addresses

  1. On Credentials, click the key's name.
  2. Under Application restrictions (on some consoles, Set an application restriction), choose IP addresses.
  3. Click Add, enter one egress address (for example 13.234.10.20, or a range such as 13.234.10.0/28), click Done. Repeat for each address.
  4. Click Save.

Changes can take up to five minutes to apply.

Warning

Once the IP restriction is on, the key works only from KIMS's network. A test from your laptop then fails with HTTP 403. That is expected. Test from your laptop before adding it, or rely on the CMS's own test (it runs in the CMS pod). If KIMS's NAT addresses change (a NAT gateway is recreated), translation stops with a key block: update the restriction.

#Quotas, budget and pricing

#Pricing

Cloud Translation Basic is billed per character sent, including HTML tags and characters that are not translated. At the time of writing, Google lists USD 20 per million characters, with the first 500,000 characters a month covered by a USD 10 monthly credit shared across Basic and Advanced. Always check the live pricing page (Sources).

To estimate: (characters of English text to translate) x (number of languages). Example: 5 million characters of page text into Kannada and Hindi is 10 million characters, roughly USD 190 after the credit. The CMS translates only what changed after the first run.

#Budget and alerts

  1. Open the navigation menu > Billing > Budgets & alerts.
  2. Click Create budget.
  3. Name: KIMS translation. Projects: the KIMS project. Services: Cloud Translation API (or all services). Click Next.
  4. Budget type: Specified amount. Target amount: what KIMS agrees, for example the monthly estimate plus 50 percent. Click Next.
  5. Keep the thresholds at 50, 90 and 100 percent of actual spend. Tick Email alerts to billing admins and users, and add KIMS's monitoring email through a notification channel if they want.
  6. Click Finish.

You should see the budget in the list with its current spend. A budget only alerts; it does not stop spending.

#Cap usage with a quota (optional)

To put a hard ceiling on spend, lower the Translation API's characters-per-day quota:

  1. Open IAM & Admin > Quotas & System Limits.
  2. Filter by Service: Cloud Translation API.
  3. Tick the characters-per-day quota (the exact name differs between console versions), click Edit quotas (or the pencil), enter a new value, and submit.

When the cap is reached, Google refuses with a daily-limit reason, the CMS marks the job quota and resumes it the next day by itself. Set the cap well above a normal day's work, or the first full translation of the site will take several days.

#Test the key from a terminal

Run this before adding the IP restriction, or from a machine whose address is in the restriction. The commands read the key without echoing it and send it in a header, so it does not end up in shell history or in a URL.

#Test: list the languages

bash
read -rs -p "API key: " GKEY; echo
curl -s -H "X-goog-api-key: $GKEY" "https://translation.googleapis.com/language/translate/v2/languages" | head -c 200; echo
bash
read -rs "GKEY?API key: "; echo     # zsh, the macOS default shell
# in bash instead: read -rs -p "API key: " GKEY; echo
curl -s -H "X-goog-api-key: $GKEY" "https://translation.googleapis.com/language/translate/v2/languages" | head -c 200; echo
powershell
$sec  = Read-Host "API key" -AsSecureString
$GKEY = [Runtime.InteropServices.Marshal]::PtrToStringBSTR([Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec))
$r = Invoke-RestMethod -Uri "https://translation.googleapis.com/language/translate/v2/languages" -Headers @{ "X-goog-api-key" = $GKEY }
$r.data.languages.Count

Expected on Linux and macOS: JSON starting { "data": { "languages": [ { "language": "af" }, .... On Windows: a number above 100 (the count of languages).

#Test: translate one word into Hindi

bash
curl -s -X POST -H "X-goog-api-key: $GKEY" -H "Content-Type: application/json" \
  -d '{"q":["Hello"],"source":"en","target":"hi","format":"html"}' \
  "https://translation.googleapis.com/language/translate/v2"; echo
unset GKEY
bash
curl -s -X POST -H "X-goog-api-key: $GKEY" -H "Content-Type: application/json" \
  -d '{"q":["Hello"],"source":"en","target":"hi","format":"html"}' \
  "https://translation.googleapis.com/language/translate/v2"; echo
unset GKEY
powershell
$body = @{ q = @("Hello"); source = "en"; target = "hi"; format = "html" } | ConvertTo-Json
$r = Invoke-RestMethod -Method Post -Uri "https://translation.googleapis.com/language/translate/v2" -Headers @{ "X-goog-api-key" = $GKEY } -ContentType "application/json; charset=utf-8" -Body $body
$r.data.translations[0].translatedText
Remove-Variable GKEY, sec

Expected: {"data":{"translations":[{"translatedText":"नमस्ते"}]}} (formatting may differ), or on Windows the Hindi word on its own line. The Windows console may show it as boxes if its font lacks Devanagari; the answer is still right.

#What a failed test means

Answer Cause Fix
400, API key not valid Key mistyped or deleted Copy it again from Credentials > the key > Show key
403, SERVICE_DISABLED or accessNotConfigured Cloud Translation API not enabled google/cloud-project
403, API_KEY_SERVICE_BLOCKED The key's API restriction does not include Cloud Translation API API restriction
403 naming the IP address or PERMISSION_DENIED from your laptop The IP restriction is working Expected; test from a pod via the CMS instead
403, BILLING_DISABLED or billingNotEnabled No billing account Link a billing account
Hangs, then times out No outbound HTTPS to Google google/outbound-access

#Save the key in the CMS

#Steps on the Translation screen

  1. Sign in to the CMS as an Admin: https://<CMS_HOST>.
  2. Open Translation in the left navigation.
  3. Paste the key into the key field and click the save button.
  4. Wait a few seconds: the CMS calls Google from the CMS pod (the language list, then "Hello" into Hindi) before it stores anything.

You should see the key's last four characters, your email and the time. Nothing else of the key is ever shown again.

#Messages the screen can give

Message Meaning
That does not look like a Google API key. Copy the whole key from Google Cloud. It is not 30 to 60 letters, digits, - or _. Usually a partial copy
Google refused this key. followed by Google's words The key, its restrictions, the API or the IP restriction: Google's words say which
The key could not be checked. followed by the error Usually the pod cannot reach translation.googleapis.com (google/outbound-access)
Only an Admin can manage machine translation. Sign in as an Admin

#Check a translation end to end

  1. Open any short English page in the CMS.
  2. Use its translation controls to machine-translate it into Kannada or Hindi.
  3. Within about five minutes (the translation-tick CronJob runs every five minutes and the worker picks it up), a Kannada or Hindi draft appears for that page.

If nothing happens, read the worker's log:

bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> logs deploy/kims-worker --since=15m | grep -i translat
bash
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> logs deploy/kims-worker --since=15m | grep -i translat
powershell
kubectl --context <KUBE_CONTEXT> -n <NAMESPACE> logs deploy/kims-worker --since=15m | Select-String -Pattern translat

#Rotate or remove the key

#Rotate

  1. Create a new key with the same restrictions (Create the key, Restrict the key).
  2. Save it on the CMS Translation screen. Saving replaces the old one.
  3. Run a small translation to check it.
  4. In the console, Credentials > the old key > Delete.

#Remove

On the Translation screen, remove the key. Translation jobs then stop with a key block until a new key is saved.

#If SECRETS_KEY changed

If the secrets-key in the kims-app Secret was ever replaced, the stored key cannot be decrypted. Save the key again on the Translation screen (deploy/secrets).

#UAT and production

Step UAT Production
Key kims-translation-uat kims-translation-production, a separate key
IP restriction UAT cluster's NAT addresses Production cluster's NAT addresses (the same if both share a VPC)
Saved in UAT CMS, Translation screen Production CMS, Translation screen (it is a different database)
Data bundle The key does not travel in the bundle: it was encrypted with the old environment's SECRETS_KEY Same

#Sources

Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.