Updates the provided hash with the API Key header.
Theapply!method modifies the provided hash in place, adding thex-goog-api-keyheader with the API Key value.
The API Key is hashed before being logged for security purposes.
NB: this method typically would be called throughupdater_proc.
Some older clients call it directly though, so it has to be public.
Parameters
a_hash(Hash) — The hash to which the API Key header should be added.
This is typically a hash representing the request headers. This hash
will be modified in place.
_opts(Hash) — Additional options (currently not used). Included
for consistency with theBaseClientinterface.
Returns
(Hash) — The modified hash (the same hash passed as thea_hashargument).
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# googleauth - Class Google::Auth::APIKeyCredentials (v1.15.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.15.0 (latest)](/ruby/docs/reference/googleauth/latest/Google-Auth-APIKeyCredentials)\n- [1.14.0](/ruby/docs/reference/googleauth/1.14.0/Google-Auth-APIKeyCredentials)\n- [1.13.1](/ruby/docs/reference/googleauth/1.13.1/Google-Auth-APIKeyCredentials)\n- [1.12.2](/ruby/docs/reference/googleauth/1.12.2/Google-Auth-APIKeyCredentials) \nReference documentation and code samples for the googleauth class Google::Auth::APIKeyCredentials.\n\nImplementation of Google API Key authentication.\n\n\nAPI Keys are text strings. They don't have an associated JSON file.\n\nThe end-user is managing their API Keys directly, not via\nan authentication library.\n\n\u003cbr /\u003e\n\nAPI Keys provide project information for an API request.\nAPI Keys don't reference an IAM principal, they do not expire,\nand cannot be refreshed. \n\nInherits\n--------\n\n- Object \n\nIncludes\n--------\n\n- [Google::Auth::BaseClient](./Google-Auth-BaseClient)\n\nMethods\n-------\n\n### .from_env\n\n def self.from_env(_scope = nil, options = {}) -\u003e Google::Auth::APIKeyCredentials, nil\n\nCreates an APIKeyCredentials from the environment.\nChecks the ENV\\['GOOGLE_API_KEY'\\] variable. \n**Parameters**\n\n- **_scope** (String) --- The scope to use for OAuth. Not used by API key auth.\n- **options** (Hash) --- The options to pass to the credentials instance \n**Returns**\n\n- ([Google::Auth::APIKeyCredentials](./Google-Auth-APIKeyCredentials), nil) --- Credentials if the API key environment variable is present, nil otherwise\n\n### .make_creds\n\n def self.make_creds(options = {}) -\u003e Google::Auth::APIKeyCredentials\n\nCreate the APIKeyCredentials. \n**Parameter**\n\n- **options** (Hash) --- The credentials options \n**Returns**\n\n- ([Google::Auth::APIKeyCredentials](./Google-Auth-APIKeyCredentials))\n\n### #api_key\n\n def api_key() -\u003e String\n\n**Returns**\n\n- (String) --- The API key\n\n### #apply!\n\n def apply!(a_hash, _opts = {}) -\u003e Hash\n\nUpdates the provided hash with the API Key header.\n\n\nThe `apply!` method modifies the provided hash in place, adding the\n`x-goog-api-key` header with the API Key value.\n\nThe API Key is hashed before being logged for security purposes.\n\n\u003cbr /\u003e\n\nNB: this method typically would be called through `updater_proc`.\nSome older clients call it directly though, so it has to be public. \n**Parameters**\n\n- **a_hash** (Hash) --- The hash to which the API Key header should be added. This is typically a hash representing the request headers. This hash will be modified in place.\n- **_opts** (Hash) --- Additional options (currently not used). Included for consistency with the `BaseClient` interface. \n**Returns**\n\n- (Hash) --- The modified hash (the same hash passed as the `a_hash` argument).\n\n### #duplicate\n\n def duplicate(options = {}) -\u003e Google::Auth::APIKeyCredentials\n\nCreates a duplicate of these credentials. \n**Parameter**\n\n- **options** (Hash) --- Additional options for configuring the credentials \n**Returns**\n\n- ([Google::Auth::APIKeyCredentials](./Google-Auth-APIKeyCredentials))\n\n### #expires_within?\n\n def expires_within?(_seconds) -\u003e Boolean\n\nDetermines if the credentials object has expired.\nSince API keys don't expire, this always returns false. \n**Parameter**\n\n- **_seconds** (Fixnum) --- The optional timeout in seconds since the last refresh \n**Returns**\n\n- (Boolean) --- True if the token has expired, false otherwise.\n\n### #initialize\n\n def initialize(options = {}) -\u003e APIKeyCredentials\n\nInitialize the APIKeyCredentials. \n**Parameter**\n\n- **options** (Hash) --- The credentials options \n**Returns**\n\n- ([APIKeyCredentials](./Google-Auth-APIKeyCredentials)) --- a new instance of APIKeyCredentials \n**Raises**\n\n- (ArgumentError) --- If the API key is nil or empty\n\n### #universe_domain\n\n def universe_domain() -\u003e String\n\n**Returns**\n\n- (String) --- The universe domain of the universe this API key is for\n\n### #universe_domain=\n\n def universe_domain=(value) -\u003e String\n\n**Parameter**\n\n- **value** (String) --- The universe domain of the universe this API key is for \n**Returns**\n\n- (String) --- The universe domain of the universe this API key is for"]]