{"id":23801,"library":"google-cloud-api-keys","title":"Google Cloud API Keys","description":"Client library for the Google Cloud API Keys API, version 0.8.0. Allows you to manage and consume API keys for Google Cloud services. Part of the Google Cloud Python client libraries. Release cadence is irregular, typically monthly or as needed.","status":"active","version":"0.8.0","language":"python","source_language":"en","source_url":"https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-api-keys","tags":["google-cloud","api-keys","gcp"],"install":[{"cmd":"pip install google-cloud-api-keys","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"The module is `api_keys_v2` (underscore), not `apikeys` or `api_keys`.","symbol":"ApiKeysClient","correct":"from google.cloud import api_keys_v2\nclient = api_keys_v2.ApiKeysClient()"},{"note":"The model class is `Key` and lives in the `api_keys_v2` module.","symbol":"Key","correct":"from google.cloud.api_keys_v2 import Key"}],"quickstart":{"code":"import os\nfrom google.cloud import api_keys_v2\nfrom google.cloud.api_keys_v2 import Key, OperationMetadata\nfrom google.cloud.api_keys_v2.services.api_keys.transports import ApiKeysGrpcTransport\n\ndef quickstart():\n    client = api_keys_v2.ApiKeysClient()\n    parent = f\"projects/{os.environ.get('GOOGLE_CLOUD_PROJECT', 'my-project')}/locations/global\"\n    # List API keys\n    request = api_keys_v2.ListKeysRequest(parent=parent)\n    page_result = client.list_keys(request=request)\n    for response in page_result:\n        print(f\"Key: {response.name}\")\n\nif __name__ == \"__main__\":\n    quickstart()","lang":"python","description":"Basic usage: list all API keys for a GCP project. Requires a service account key or ADC set up."},"warnings":[{"fix":"Use `from google.cloud import api_keys_v2`.","message":"The import path is `google.cloud.api_keys_v2`, not `google.cloud.apikeys` or `google.cloud.api_keys`. The underscore between `api` and `keys` is part of the module name.","severity":"gotcha","affected_versions":"all"},{"fix":"Provide credentials via `google.auth.default()` or use a service account key file with `os.environ['GOOGLE_APPLICATION_CREDENTIALS']`.","message":"The client constructor expects a `credentials` argument if you aren't using Application Default Credentials (ADC). Many users assume it auto-discovers, but if ADC is not set, you must pass `credentials` explicitly.","severity":"gotcha","affected_versions":"all"},{"fix":"Always include `locations/global` in the parent path.","message":"The `parent` path for keys is `projects/{project}/locations/global`. Forgetting `locations/global` causes a 404 error.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Replace `from google.cloud import api_keys` with `from google.cloud import api_keys_v2`.","cause":"Wrong import path. The correct module is `api_keys_v2`.","error":"ModuleNotFoundError: No module named 'google.cloud.api_keys'"},{"fix":"Set parent to `projects/{project}/locations/global`.","cause":"The parent path for listing keys must include `locations/global`.","error":"google.api_core.exceptions.NotFound: 404 The resource 'projects/{project}/keys' was not found"},{"fix":"Use `from google.cloud import api_keys_v2` then `client = api_keys_v2.ApiKeysClient()`.","cause":"Importing the module but not the client class.","error":"AttributeError: module 'google.cloud.api_keys_v2' has no attribute 'ApiKeysClient'"},{"fix":"Upgrade to latest version: `pip install --upgrade google-cloud-api-keys`.","cause":"Using an older version where transport parameter was not supported.","error":"TypeError: __init__() got an unexpected keyword argument 'transport'","affected_versions":"<0.8.0"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}