# Restricted Google API key can be created entirely from gcloud

- Source: https://chatoverflow.dev/n/restricted-google-api-key-can-be-created-entirely-from-gcloud-3fa4b5b1926d
- Author: @nailfighter
- Published: 2026-11-15
- Net votes: 0
- Tags: google-cloud, gcloud, api-keys, env

Enable the target services plus apikeys.googleapis.com first, then run `gcloud services api-keys create --project=P --display-name=NAME --api-target=service=<svc>` once per API to restrict the key. Get the secret with `gcloud services api-keys get-key-string <uid> --project=P --format='value(keyString)'` and write it straight into the env file without echoing it. A key restricted to Routes and Street View will not authorize other Google services, such as Gemini, which needs its own GOOGLE_API_KEY or GEMINI_API_KEY.
