An idiomatic C++ client library for Secret Manager API, a service that stores sensitive data such as API keys, passwords, and certificates.
While this library is GA, please note that the Google Cloud C++ client libraries do not follow Semantic Versioning.
Quickstart
The following shows the code that you'll run in the google/cloud/secretmanager/quickstart/ directory, which should give you a taste of the Secret Manager API C++ client library API.
In some cases, you may need to override the default endpoint used by the client library. Use the google::cloud::EndpointOption when initializing the client library to change this default.
For example, this will override the default endpoint for secretmanager_v1::SecretManagerServiceClient:
// This configuration is common with Private Google Access:
// https://cloud.google.com/vpc/docs/private-google-access
auto options = google::cloud::Options{}.set<google::cloud::EndpointOption>(
"private.googleapis.com");
auto client = google::cloud::secretmanager_v1::SecretManagerServiceClient(
google::cloud::secretmanager_v1::MakeSecretManagerServiceConnection(
options));
The library automatically retries requests that fail with transient errors, and uses exponential backoff to backoff between retries. Application developers can override the default policies.
More Information
Error Handling - describes how the library reports errors.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThis webpage details the C++ client library for Google Cloud's Secret Manager API, which is used to securely store sensitive data like API keys and passwords.\u003c/p\u003e\n"],["\u003cp\u003eThe latest release candidate version is 2.37.0-rc, and the library is currently in General Availability (GA), but it does not follow semantic versioning.\u003c/p\u003e\n"],["\u003cp\u003eThe primary class is \u003ccode\u003esecretmanager_v1::SecretManagerServiceClient\u003c/code\u003e, which contains member functions for all available RPC calls.\u003c/p\u003e\n"],["\u003cp\u003eThe library allows users to override the default API endpoint and authentication configuration for tailored use cases.\u003c/p\u003e\n"],["\u003cp\u003eThe library implements automatic retries and exponential backoff for transient errors, with options for developers to customize these policies.\u003c/p\u003e\n"]]],[],null,["Version 2.10.1keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/secretmanager/latest)\n- [2.41.0](/cpp/docs/reference/secretmanager/2.41.0)\n- [2.40.0](/cpp/docs/reference/secretmanager/2.40.0)\n- [2.39.0](/cpp/docs/reference/secretmanager/2.39.0)\n- [2.38.0](/cpp/docs/reference/secretmanager/2.38.0)\n- [2.37.0](/cpp/docs/reference/secretmanager/2.37.0)\n- [2.36.0](/cpp/docs/reference/secretmanager/2.36.0)\n- [2.35.0](/cpp/docs/reference/secretmanager/2.35.0)\n- [2.34.0](/cpp/docs/reference/secretmanager/2.34.0)\n- [2.33.0](/cpp/docs/reference/secretmanager/2.33.0)\n- [2.32.0](/cpp/docs/reference/secretmanager/2.32.0)\n- [2.31.0](/cpp/docs/reference/secretmanager/2.31.0)\n- [2.30.0](/cpp/docs/reference/secretmanager/2.30.0)\n- [2.29.0](/cpp/docs/reference/secretmanager/2.29.0)\n- [2.28.0](/cpp/docs/reference/secretmanager/2.28.0)\n- [2.27.0](/cpp/docs/reference/secretmanager/2.27.0)\n- [2.26.0](/cpp/docs/reference/secretmanager/2.26.0)\n- [2.25.1](/cpp/docs/reference/secretmanager/2.25.1)\n- [2.24.0](/cpp/docs/reference/secretmanager/2.24.0)\n- [2.23.0](/cpp/docs/reference/secretmanager/2.23.0)\n- [2.22.1](/cpp/docs/reference/secretmanager/2.22.1)\n- [2.21.0](/cpp/docs/reference/secretmanager/2.21.0)\n- [2.20.0](/cpp/docs/reference/secretmanager/2.20.0)\n- [2.19.0](/cpp/docs/reference/secretmanager/2.19.0)\n- [2.18.0](/cpp/docs/reference/secretmanager/2.18.0)\n- [2.17.0](/cpp/docs/reference/secretmanager/2.17.0)\n- [2.16.0](/cpp/docs/reference/secretmanager/2.16.0)\n- [2.15.1](/cpp/docs/reference/secretmanager/2.15.1)\n- [2.14.0](/cpp/docs/reference/secretmanager/2.14.0)\n- [2.13.0](/cpp/docs/reference/secretmanager/2.13.0)\n- [2.12.0](/cpp/docs/reference/secretmanager/2.12.0)\n- [2.11.0](/cpp/docs/reference/secretmanager/2.11.0)\n- [2.10.1](/cpp/docs/reference/secretmanager/2.10.1) \n\nSecret Manager API C++ Client Library\n=====================================\n\nAn idiomatic C++ client library for [Secret Manager API](https://cloud.google.com/secretmanager/), a service that stores sensitive data such as API keys, passwords, and certificates.\n\nWhile this library is **GA** , please note that the Google Cloud C++ client libraries do **not** follow [Semantic Versioning](https://semver.org/).\n\n### Quickstart\n\nThe following shows the code that you'll run in the `google/cloud/secretmanager/quickstart/` directory, which should give you a taste of the Secret Manager API C++ client library API. \n\n #include \"google/cloud/secretmanager/v1/secret_manager_client.h\"\n #include \u003ciostream\u003e\n\n int main(int argc, char* argv[]) try {\n if (argc != 2) {\n std::cerr \u003c\u003c \"Usage: \" \u003c\u003c argv[0] \u003c\u003c \" project-id\\n\";\n return 1;\n }\n\n namespace secretmanager = ::google::cloud::secretmanager_v1;\n auto client = secretmanager::SecretManagerServiceClient(\n secretmanager::MakeSecretManagerServiceConnection());\n\n auto const parent = std::string(\"projects/\") + argv[1];\n for (auto secret : client.ListSecrets(parent)) {\n if (!secret) throw std::move(secret).status();\n std::cout \u003c\u003c secret-\u003eDebugString() \u003c\u003c \"\\n\";\n }\n\n return 0;\n } catch (google::cloud::Status const& status) {\n std::cerr \u003c\u003c \"google::cloud::Status thrown: \" \u003c\u003c status \u003c\u003c \"\\n\";\n return 1;\n }\n\n### Main classes\n\nThe main class in this library is [`secretmanager_v1::SecretManagerServiceClient`](/cpp/docs/reference/secretmanager/2.10.1/classgoogle_1_1cloud_1_1secretmanager__v1_1_1SecretManagerServiceClient). All RPCs are exposed as member functions of this class. Other classes provide helpers, retry policies, configuration parameters, and infrastructure to mock [`secretmanager_v1::SecretManagerServiceClient`](/cpp/docs/reference/secretmanager/2.10.1/classgoogle_1_1cloud_1_1secretmanager__v1_1_1SecretManagerServiceClient) when testing your application.\n\n### Override the default endpoint\n\nIn some cases, you may need to override the default endpoint used by the client library. Use the [`google::cloud::EndpointOption`](https://cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1EndpointOption.html) when initializing the client library to change this default.\n\nFor example, this will override the default endpoint for `secretmanager_v1::SecretManagerServiceClient`: \n\n // This configuration is common with Private Google Access:\n // https://cloud.google.com/vpc/docs/private-google-access\n auto options = google::cloud::Options{}.set\u003cgoogle::cloud::EndpointOption\u003e(\n \"private.googleapis.com\");\n auto client = google::cloud::secretmanager_v1::SecretManagerServiceClient(\n google::cloud::secretmanager_v1::MakeSecretManagerServiceConnection(\n options));\n\n### Override the authentication configuration\n\nSome applications cannot use the default authentication mechanism (known as [Application Default Credentials](https://cloud.google.com/docs/authentication#adc)). You can override this default using [`google::cloud::UnifiedCredentialsOption`](https://cloud.google.com/cpp/docs/reference/common/latest/structgoogle_1_1cloud_1_1UnifiedCredentialsOption.html). The following example shows how to explicitly load a service account key file. \n\n [](std::string const& keyfile) {\n auto is = std::ifstream(keyfile);\n is.exceptions(std::ios::badbit); // Minimal error handling in examples\n auto contents = std::string(std::istreambuf_iterator\u003cchar\u003e(is.rdbuf()), {});\n auto options =\n google::cloud::Options{}.set\u003cgoogle::cloud::UnifiedCredentialsOption\u003e(\n google::cloud::MakeServiceAccountCredentials(contents));\n return google::cloud::secretmanager_v1::SecretManagerServiceClient(\n google::cloud::secretmanager_v1::MakeSecretManagerServiceConnection(\n options));\n }\n\nKeep in mind that we chose this as an example because it is relatively easy to understand. Consult the [Best practices for managing service account keys](https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys) guide for more details.\n\n###### See Also\n\n[Authentication Components](https://cloud.google.com/cpp/docs/reference/common/latest/group__guac.html) - for more information on the factory functions to create [`google::cloud::Credentials`](https://cloud.google.com/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1Credentials.html) objects.\n\n### Retry, Backoff, and Idempotency Policies.\n\nThe library automatically retries requests that fail with transient errors, and uses [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) to backoff between retries. Application developers can override the default policies.\n\n### More Information\n\n- [Error Handling](https://cloud.google.com/cpp/docs/reference/common/latest/common-error-handling.html) - describes how the library reports errors."]]