From 7a4fb51127dd9cba8e32587866ae03608505b2bd Mon Sep 17 00:00:00 2001 From: Ayush Agrawal Date: Fri, 6 Feb 2026 15:56:08 -0800 Subject: [PATCH] feat: Support encryption_spec in tuning job creation configuration for GenAI SDK PiperOrigin-RevId: 866649048 --- src/main/java/com/google/genai/Tunings.java | 12 ++++++ .../genai/types/CreateTuningJobConfig.java | 40 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/main/java/com/google/genai/Tunings.java b/src/main/java/com/google/genai/Tunings.java index e6bccb56b73..cf1476c4d11 100644 --- a/src/main/java/com/google/genai/Tunings.java +++ b/src/main/java/com/google/genai/Tunings.java @@ -221,6 +221,11 @@ ObjectNode createTuningJobConfigToMldev( throw new IllegalArgumentException("outputUri parameter is not supported in Gemini API."); } + if (!Common.isZero(Common.getValueByPath(fromObject, new String[] {"encryptionSpec"}))) { + throw new IllegalArgumentException( + "encryptionSpec parameter is not supported in Gemini API."); + } + return toObject; } @@ -532,6 +537,13 @@ ObjectNode createTuningJobConfigToVertex( Common.getValueByPath(fromObject, new String[] {"outputUri"})); } + if (Common.getValueByPath(fromObject, new String[] {"encryptionSpec"}) != null) { + Common.setValueByPath( + parentObject, + new String[] {"encryptionSpec"}, + Common.getValueByPath(fromObject, new String[] {"encryptionSpec"})); + } + return toObject; } diff --git a/src/main/java/com/google/genai/types/CreateTuningJobConfig.java b/src/main/java/com/google/genai/types/CreateTuningJobConfig.java index 3f92664a872..f3c73c5a7a7 100644 --- a/src/main/java/com/google/genai/types/CreateTuningJobConfig.java +++ b/src/main/java/com/google/genai/types/CreateTuningJobConfig.java @@ -136,6 +136,14 @@ public abstract class CreateTuningJobConfig extends JsonSerializable { @JsonProperty("outputUri") public abstract Optional outputUri(); + /** + * The encryption spec of the tuning job. Customer-managed encryption key options for a TuningJob. + * If this is set, then all resources created by the TuningJob will be encrypted with provided + * encryption key. + */ + @JsonProperty("encryptionSpec") + public abstract Optional encryptionSpec(); + /** Instantiates a builder for CreateTuningJobConfig. */ @ExcludeFromGeneratedCoverageReport public static Builder builder() { @@ -640,6 +648,38 @@ public Builder clearOutputUri() { return outputUri(Optional.empty()); } + /** + * Setter for encryptionSpec. + * + *

encryptionSpec: The encryption spec of the tuning job. Customer-managed encryption key + * options for a TuningJob. If this is set, then all resources created by the TuningJob will be + * encrypted with provided encryption key. + */ + @JsonProperty("encryptionSpec") + public abstract Builder encryptionSpec(EncryptionSpec encryptionSpec); + + /** + * Setter for encryptionSpec builder. + * + *

encryptionSpec: The encryption spec of the tuning job. Customer-managed encryption key + * options for a TuningJob. If this is set, then all resources created by the TuningJob will be + * encrypted with provided encryption key. + */ + @CanIgnoreReturnValue + public Builder encryptionSpec(EncryptionSpec.Builder encryptionSpecBuilder) { + return encryptionSpec(encryptionSpecBuilder.build()); + } + + @ExcludeFromGeneratedCoverageReport + abstract Builder encryptionSpec(Optional encryptionSpec); + + /** Clears the value of encryptionSpec field. */ + @ExcludeFromGeneratedCoverageReport + @CanIgnoreReturnValue + public Builder clearEncryptionSpec() { + return encryptionSpec(Optional.empty()); + } + public abstract CreateTuningJobConfig build(); }