This shows how to override the retry policies for automl_v1::AutoMlClient:
auto options =
google::cloud::Options{}
.set<google::cloud::automl_v1::
AutoMlConnectionIdempotencyPolicyOption>(
CustomIdempotencyPolicy().clone())
.set<google::cloud::automl_v1::AutoMlRetryPolicyOption>(
google::cloud::automl_v1::AutoMlLimitedErrorCountRetryPolicy(3)
.clone())
.set<google::cloud::automl_v1::AutoMlBackoffPolicyOption>(
google::cloud::ExponentialBackoffPolicy(
/*initial_delay=*/std::chrono::milliseconds(200),
/*maximum_delay=*/std::chrono::seconds(45),
/*scaling=*/2.0)
.clone());
auto connection = google::cloud::automl_v1::MakeAutoMlConnection(options);
// c1 and c2 share the same retry policies
auto c1 = google::cloud::automl_v1::AutoMlClient(connection);
auto c2 = google::cloud::automl_v1::AutoMlClient(connection);
// You can override any of the policies in a new client. This new client
// will share the policies from c1 (or c2) *except* for the retry policy.
auto c3 = google::cloud::automl_v1::AutoMlClient(
connection,
google::cloud::Options{}
.set<google::cloud::automl_v1::AutoMlRetryPolicyOption>(
google::cloud::automl_v1::AutoMlLimitedTimeRetryPolicy(
std::chrono::minutes(5))
.clone()));
// You can also override the policies in a single call:
// c3.SomeRpc(..., google::cloud::Options{}
// .set<google::cloud::automl_v1::AutoMlRetryPolicyOption>(
// google::cloud::automl_v1::AutoMlLimitedErrorCountRetryPolicy(10).clone()));
Assuming you have created a custom idempotency policy. Such as:
class CustomIdempotencyPolicy
: public google::cloud::automl_v1::AutoMlConnectionIdempotencyPolicy {
public:
~CustomIdempotencyPolicy() override = default;
std::unique_ptr<google::cloud::automl_v1::AutoMlConnectionIdempotencyPolicy>
clone() const override {
return std::make_unique<CustomIdempotencyPolicy>(*this);
}
// Override inherited functions to define as needed.
};
[[["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 page provides documentation for overriding retry policies for the \u003ccode\u003eautoml_v1::AutoMlClient\u003c/code\u003e in C++.\u003c/p\u003e\n"],["\u003cp\u003eVersion 2.37.0-rc is the latest release candidate, with multiple other versions available from 2.36.0 down to 2.11.0.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a custom idempotency policy, like the provided \u003ccode\u003eCustomIdempotencyPolicy\u003c/code\u003e example, to control retry behavior.\u003c/p\u003e\n"],["\u003cp\u003eRetry policies can be set at the connection level, shared among multiple clients, or overridden in individual client constructors or method calls.\u003c/p\u003e\n"],["\u003cp\u003eThe documentation provides code snippets demonstrating how to set retry policies, including options for error count and time-based retries, along with custom backoff strategies.\u003c/p\u003e\n"]]],[],null,["Version 2.36.0keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/automl/latest/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.41.0](/cpp/docs/reference/automl/2.41.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.40.0](/cpp/docs/reference/automl/2.40.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.39.0](/cpp/docs/reference/automl/2.39.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.38.0](/cpp/docs/reference/automl/2.38.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.37.0](/cpp/docs/reference/automl/2.37.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.36.0](/cpp/docs/reference/automl/2.36.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.35.0](/cpp/docs/reference/automl/2.35.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.34.0](/cpp/docs/reference/automl/2.34.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.33.0](/cpp/docs/reference/automl/2.33.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.32.0](/cpp/docs/reference/automl/2.32.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.31.0](/cpp/docs/reference/automl/2.31.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.30.0](/cpp/docs/reference/automl/2.30.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.29.0](/cpp/docs/reference/automl/2.29.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.28.0](/cpp/docs/reference/automl/2.28.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.27.0](/cpp/docs/reference/automl/2.27.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.26.0](/cpp/docs/reference/automl/2.26.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.25.1](/cpp/docs/reference/automl/2.25.1/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.24.0](/cpp/docs/reference/automl/2.24.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.23.0](/cpp/docs/reference/automl/2.23.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.22.1](/cpp/docs/reference/automl/2.22.1/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.21.0](/cpp/docs/reference/automl/2.21.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.20.0](/cpp/docs/reference/automl/2.20.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.19.0](/cpp/docs/reference/automl/2.19.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.18.0](/cpp/docs/reference/automl/2.18.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.17.0](/cpp/docs/reference/automl/2.17.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.16.0](/cpp/docs/reference/automl/2.16.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.15.1](/cpp/docs/reference/automl/2.15.1/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.14.0](/cpp/docs/reference/automl/2.14.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.13.0](/cpp/docs/reference/automl/2.13.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.12.0](/cpp/docs/reference/automl/2.12.0/automl_v1_1_1AutoMlClient-retry-snippet)\n- [2.11.0](/cpp/docs/reference/automl/2.11.0/automl_v1_1_1AutoMlClient-retry-snippet) \n\nOverride automl_v1::AutoMlClient Retry Policies\n===============================================\n\nThis shows how to override the retry policies for automl_v1::AutoMlClient: \n\n auto options =\n google::cloud::Options{}\n .set\u003cgoogle::cloud::automl_v1::\n AutoMlConnectionIdempotencyPolicyOption\u003e(\n CustomIdempotencyPolicy().clone())\n .set\u003cgoogle::cloud::automl_v1::AutoMlRetryPolicyOption\u003e(\n google::cloud::automl_v1::AutoMlLimitedErrorCountRetryPolicy(3)\n .clone())\n .set\u003cgoogle::cloud::automl_v1::AutoMlBackoffPolicyOption\u003e(\n google::cloud::ExponentialBackoffPolicy(\n /*initial_delay=*/std::chrono::milliseconds(200),\n /*maximum_delay=*/std::chrono::seconds(45),\n /*scaling=*/2.0)\n .clone());\n auto connection = google::cloud::automl_v1::MakeAutoMlConnection(options);\n\n // c1 and c2 share the same retry policies\n auto c1 = google::cloud::automl_v1::AutoMlClient(connection);\n auto c2 = google::cloud::automl_v1::AutoMlClient(connection);\n\n // You can override any of the policies in a new client. This new client\n // will share the policies from c1 (or c2) *except* for the retry policy.\n auto c3 = google::cloud::automl_v1::AutoMlClient(\n connection,\n google::cloud::Options{}\n .set\u003cgoogle::cloud::automl_v1::AutoMlRetryPolicyOption\u003e(\n google::cloud::automl_v1::AutoMlLimitedTimeRetryPolicy(\n std::chrono::minutes(5))\n .clone()));\n\n // You can also override the policies in a single call:\n // c3.SomeRpc(..., google::cloud::Options{}\n // .set\u003cgoogle::cloud::automl_v1::AutoMlRetryPolicyOption\u003e(\n // google::cloud::automl_v1::AutoMlLimitedErrorCountRetryPolicy(10).clone()));\n\nAssuming you have created a custom idempotency policy. Such as: \n\n class CustomIdempotencyPolicy\n : public google::cloud::automl_v1::AutoMlConnectionIdempotencyPolicy {\n public:\n ~CustomIdempotencyPolicy() override = default;\n std::unique_ptr\u003cgoogle::cloud::automl_v1::AutoMlConnectionIdempotencyPolicy\u003e\n clone() const override {\n return std::make_unique\u003cCustomIdempotencyPolicy\u003e(*this);\n }\n // Override inherited functions to define as needed.\n };"]]