Skip to content

Add CMEK arguments to client.batches.create#2643

Open
matt-davis27 wants to merge 1 commit into
googleapis:mainfrom
matt-davis27:batch-job-cmek
Open

Add CMEK arguments to client.batches.create#2643
matt-davis27 wants to merge 1 commit into
googleapis:mainfrom
matt-davis27:batch-job-cmek

Conversation

@matt-davis27

Copy link
Copy Markdown

Description

Fixes #2622.

Add Customer Managed Encryption Key [CMEK] arguments to client.batches.create (which allows the user to set the keys directly in the configuration of a new batch job)

Summary of Changes

types.py — Added encryption_spec field to both:

  • CreateBatchJobConfig(pydantic model) — accepts EncryptionSpec or dict
  • CreateBatchJobConfigDict (TypedDict) — accepts EncryptionSpecDict

batches.py — Added mapping in _CreateBatchJobConfig_to_vertex that converts encryption_spec.kms_key_name to encryptionSpec.kmsKeyName on the API request body.

tests/batches/test_create_with_cmek.py — new test file to ensure CMEK arguments are parsed correctly and added to batch job.

Usage

You can now add CMEK to your batch job config in one of two ways:

# Via config
client.batches.create(
    model="gemini-2.5-flash",
    src="gs://bucket/input",
    config=genai.types.CreateBatchJobConfig(
        dest="gs://bucket/output",
        encryption_spec=genai.types.EncryptionSpec(
            kms_key_name="projects/my-project/locations/us-central1/keyRings/my-kr/cryptoKeys/my-key"
        ),
    ),
)

# Via dict shorthand
client.batches.create(
    model="gemini-2.5-flash",
    src="gs://bucket/input",
    config={
        "dest": "gs://bucket/output",
        "encryption_spec": {"kms_key_name": "projects/.../cryptoKeys/my-key"},
    },
)

@google-cla

google-cla Bot commented Jun 22, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Venkaiahbabuneelam Venkaiahbabuneelam self-assigned this Jun 23, 2026
@Venkaiahbabuneelam Venkaiahbabuneelam added the size:XL Code changes > 100 lines label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL Code changes > 100 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CMEK directly in Gemini Batch Job Configuration

2 participants