While the client libraries defaults should work for most applications, there are multiple runtime configuration options that applications may need to set. For example, the application may need to override the endpoint used to access the service, or change the retry policies to be more strict (or lenient) than the defaults.
Applications usegoogle::cloud::Optionsto override the defaults. You can think of an instance ofgoogle::cloud::Optionsas a set of overrides, indexed by a C++ type that uniquely identifies the option. There is no need for applications to fill this set with the defaults.
Override Priority
For most libraries overrides can be made at 3 different levels:
Function calls
*Clientobjects
*Connectionobjects
In general, function call overrides take precedence over*Clientoverrides, and these in turn take precedence over any overrides in the*Connectionoverride. However, most options can only be set when the*Connectionobject is created. You need to consult the documentation for an option to determine if they are usable for a specific function call.
Consider this example:
#include "google/cloud/kms/key_management_client.h"
#include "google/cloud/kms/key_management_connection.h"
#include "google/cloud/kms/key_management_options.h"
#include "google/cloud/common_options.h"
using kms = ::google::cloud::kms;
using g = ::google::cloud;
// `parent` must be in the form "projects/<project-id>/locations/<region-id>".
// For example F("projects/my-project/locations/us-central1")
void F(std::string const& parent) {
auto retry = [](int n) { return kms::LimitedErrorCountRetryPolicy(n).clone(); };
auto conn_1 = kms::MakeKeyManagementServiceConnection();
auto conn_2 = kms::MakeKeyManagementServiceConnection(
g::Options{}
.set<g::EndpointOption>("private.googleapis.com")
.set<kms::KeyManagementServiceRetryPolicyOption>(retry(3)));
auto client_1 = kms::KeyManagementServiceClient(conn_1);
auto client_2 = kms::KeyManagementServiceClient(conn_2);
auto client_3 = kms::KeyManagementServiceClient(conn_2, g::Options{}
.set<kms::KeyManagementServiceRetryPolicyOption>(retry(5));
auto rpc_1 = client_1.ListKeyRings(parent);
auto rpc_2 = client_2.ListKeyRings(parent);
auto rpc_3 = client_3.ListKeyRings(parent);
auto rpc_4 = client_3.ListKeyRights(parent,
g::Options{}.set<kms::KeyManagementServiceRetryPolicyOption>(retry(7)));
}
In this case,rpc_4will retry the request up to 7 times, because the value of thekms::RetryPolicyOptionoverrides the values at the connection or client level. Meanwhile,rpc_3will retry the request 5 times, because the value at the*Clientlevel overrides the value at the*Connectionlevel. Likewise,rpc_2will retry the request 3 times, because this is the value in the*Connectionand there are no overrides in the client or function calls. Finally,rpc_1will use the default. For this service the default is to retry for 30 minutes.
Note that only the connection overrides theg::EndpointOption. Overriding this option at the*Clientor function call level would have no effect.
Library-specific Options
All libraries have options that are only meaningful for that library (and ignored by other libraries). In some cases, the option may be specific to a service* (sometimes called "an API"). In the previous example, thekms::KeyManagementServiceRetryPolicyOptionis only applicable tokms::KeyManagementServiceClientandkms::KeyManagementServiceConnection. Other services in the same library (e.g.,kms::EkmServiceClient) will ignore this option. Likewise, other services in different libraries (e.g.pubsub::Publisher) will also ignore the option.
[[["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."],[[["\u003cp\u003eThe client libraries provide default settings that are suitable for most applications, but they also offer various runtime configuration options to customize behavior, such as modifying service endpoints or retry policies.\u003c/p\u003e\n"],["\u003cp\u003eConfiguration overrides can be applied at the function call, \u003ccode\u003e*Client\u003c/code\u003e object, or \u003ccode\u003e*Connection\u003c/code\u003e object level, with function call overrides having the highest precedence, followed by \u003ccode\u003e*Client\u003c/code\u003e and then \u003ccode\u003e*Connection\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egoogle::cloud::Options\u003c/code\u003e class enables users to override default settings by providing a set of overrides, indexed by C++ types that uniquely identify the option, and specific options may only be effective at certain levels.\u003c/p\u003e\n"],["\u003cp\u003eEach library has its own unique set of options that only apply to that library, or potentially even specific services within that library, ensuring that options are relevant to their intended context and are ignored otherwise.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the documentation is 2.37.0-rc, with versions all the way back to 2.10.1 available, providing access to a range of reference materials.\u003c/p\u003e\n"]]],[],null,["# Client Library Configuration (2.11.0)\n\nVersion 2.11.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/group__options)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/group__options)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/group__options)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/group__options)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/group__options)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/group__options)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/group__options)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/group__options)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/group__options)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/group__options)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/group__options)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/group__options)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/group__options)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/group__options)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/group__options)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/group__options)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/group__options)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/group__options)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/group__options)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/group__options)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/group__options)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/group__options)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/group__options)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/group__options)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/group__options)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/group__options)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/group__options)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/group__options)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/group__options)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/group__options)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/group__options)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/group__options)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/group__options) \n\nClient Library Configuration\n============================\n\n### Overview\n\nWhile the client libraries defaults should work for most applications, there are multiple runtime configuration options that applications may need to set. For example, the application may need to override the endpoint used to access the service, or change the retry policies to be more strict (or lenient) than the defaults.\n\nApplications use [`google::cloud::Options`](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1Options) to override the defaults. You can think of an instance of [`google::cloud::Options`](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1Options) as a set of overrides, indexed by a C++ type that uniquely identifies the option. There is no need for applications to fill this set with the defaults.\n\n### Override Priority\n\nFor most libraries overrides can be made at 3 different levels:\n\n- Function calls\n- `*Client` objects\n- `*Connection` objects\n\nIn general, function call overrides take precedence over `*Client` overrides, and these in turn take precedence over any overrides in the `*Connection` override. However, most options can only be set when the `*Connection` object is created. You need to consult the documentation for an option to determine if they are usable for a specific function call.\n\nConsider this example: \n\n #include \"google/cloud/kms/key_management_client.h\"\n #include \"google/cloud/kms/key_management_connection.h\"\n #include \"google/cloud/kms/key_management_options.h\"\n #include \"google/cloud/common_options.h\"\n\n using kms = ::google::cloud::kms;\n using g = ::google::cloud;\n\n // `parent` must be in the form \"projects/\u003cproject-id\u003e/locations/\u003cregion-id\u003e\".\n // For example F(\"projects/my-project/locations/us-central1\")\n void F(std::string const& parent) {\n auto retry = [](int n) { return kms::LimitedErrorCountRetryPolicy(n).clone(); };\n\n auto conn_1 = kms::MakeKeyManagementServiceConnection();\n auto conn_2 = kms::MakeKeyManagementServiceConnection(\n g::Options{}\n .set\u003cg::EndpointOption\u003e(\"private.googleapis.com\")\n .set\u003ckms::KeyManagementServiceRetryPolicyOption\u003e(retry(3)));\n\n auto client_1 = kms::KeyManagementServiceClient(conn_1);\n auto client_2 = kms::KeyManagementServiceClient(conn_2);\n auto client_3 = kms::KeyManagementServiceClient(conn_2, g::Options{}\n .set\u003ckms::KeyManagementServiceRetryPolicyOption\u003e(retry(5));\n\n auto rpc_1 = client_1.ListKeyRings(parent);\n auto rpc_2 = client_2.ListKeyRings(parent);\n auto rpc_3 = client_3.ListKeyRings(parent);\n auto rpc_4 = client_3.ListKeyRights(parent,\n g::Options{}.set\u003ckms::KeyManagementServiceRetryPolicyOption\u003e(retry(7)));\n }\n\nIn this case, `rpc_4` will retry the request up to 7 times, because the value of the `kms::RetryPolicyOption` overrides the values at the connection or client level. Meanwhile, `rpc_3` will retry the request 5 times, because the value at the `*Client` level overrides the value at the `*Connection` level. Likewise, `rpc_2` will retry the request 3 times, because this is the value in the `*Connection` and there are no overrides in the client or function calls. Finally, `rpc_1` will use the default. For this service the default is to retry for 30 minutes.\n\nNote that only the connection overrides the `g::EndpointOption`. Overriding this option at the `*Client` or function call level would have no effect.\n\n### Library-specific Options\n\nAll libraries have options that are only meaningful for that library (and ignored by other libraries). In some cases, the option may be specific to a service\\* (sometimes called \"an API\"). In the previous example, the `kms::KeyManagementServiceRetryPolicyOption` is only applicable to `kms::KeyManagementServiceClient` and `kms::KeyManagementServiceConnection`. Other services in the same library (e.g., `kms::EkmServiceClient`) will ignore this option. Likewise, other services in different libraries (e.g. `pubsub::Publisher`) will also ignore the option.\n\n### Classes\n\n- [`google::cloud::EndpointOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1EndpointOption)\n- [`google::cloud::UserAgentProductsOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1UserAgentProductsOption)\n- [`google::cloud::UserProjectOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1UserProjectOption)\n- [`google::cloud::AuthorityOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1AuthorityOption)\n- [`google::cloud::UnifiedCredentialsOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1UnifiedCredentialsOption)\n- [`google::cloud::DelegatesOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1DelegatesOption)\n- [`google::cloud::ScopesOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1ScopesOption)\n- [`google::cloud::AccessTokenLifetimeOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1AccessTokenLifetimeOption)\n- [`google::cloud::CARootsFilePathOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1CARootsFilePathOption)\n- [`google::cloud::GrpcCredentialOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcCredentialOption)\n- [`google::cloud::GrpcNumChannelsOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcNumChannelsOption)\n- [`google::cloud::GrpcChannelArgumentsOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcChannelArgumentsOption)\n- [`google::cloud::GrpcChannelArgumentsNativeOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcChannelArgumentsNativeOption)\n- [`google::cloud::GrpcTracingOptionsOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcTracingOptionsOption)\n- [`google::cloud::GrpcBackgroundThreadPoolSizeOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcBackgroundThreadPoolSizeOption)\n- [`google::cloud::GrpcCompletionQueueOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcCompletionQueueOption)\n- [`google::cloud::GrpcBackgroundThreadsFactoryOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1GrpcBackgroundThreadsFactoryOption)\n- [`google::cloud::Options`](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1Options)\n- [`google::cloud::RestTracingOptionsOption`](/cpp/docs/reference/common/2.11.0/structgoogle_1_1cloud_1_1RestTracingOptionsOption)"]]