Skip to content

Commit 772d2fc

Browse files
MarkDaoustcopybara-github
authored andcommitted
feat: Add webhook_config to batches.create() and models.generate_videos()
For dynamic per-request webhook notifications on batch jobs and video generation LROs. PiperOrigin-RevId: 899099328
1 parent b91bda5 commit 772d2fc

5 files changed

Lines changed: 158 additions & 7 deletions

File tree

google/genai/batches.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,13 @@ def _CreateBatchJobConfig_to_mldev(
526526
if getv(from_object, ['dest']) is not None:
527527
raise ValueError('dest parameter is not supported in Gemini API.')
528528

529+
if getv(from_object, ['webhook_config']) is not None:
530+
setv(
531+
parent_object,
532+
['batch', 'webhookConfig'],
533+
getv(from_object, ['webhook_config']),
534+
)
535+
529536
return to_object
530537

531538

@@ -547,6 +554,9 @@ def _CreateBatchJobConfig_to_vertex(
547554
),
548555
)
549556

557+
if getv(from_object, ['webhook_config']) is not None:
558+
raise ValueError('webhook_config parameter is not supported in Vertex AI.')
559+
550560
return to_object
551561

552562

google/genai/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,11 @@ def _GenerateVideosConfig_to_mldev(
21542154
if getv(from_object, ['labels']) is not None:
21552155
raise ValueError('labels parameter is not supported in Gemini API.')
21562156

2157+
if getv(from_object, ['webhook_config']) is not None:
2158+
setv(
2159+
parent_object, ['webhookConfig'], getv(from_object, ['webhook_config'])
2160+
)
2161+
21572162
return to_object
21582163

21592164

@@ -2280,6 +2285,9 @@ def _GenerateVideosConfig_to_vertex(
22802285
if getv(from_object, ['labels']) is not None:
22812286
setv(parent_object, ['labels'], getv(from_object, ['labels']))
22822287

2288+
if getv(from_object, ['webhook_config']) is not None:
2289+
raise ValueError('webhook_config parameter is not supported in Vertex AI.')
2290+
22832291
return to_object
22842292

22852293

google/genai/tests/batches/test_create.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,51 @@
6565
exception_if_vertex='Unsupported destination',
6666
has_union=True,
6767
),
68+
pytest_helper.TestTableItem(
69+
name='test_create_with_webhook_config',
70+
parameters=types._CreateBatchJobParameters(
71+
model=_GEMINI_MODEL,
72+
src={
73+
'inlined_requests': [
74+
{
75+
'contents': [
76+
{'parts': [{'text': 'say hello'}], 'role': 'user'}
77+
]
78+
},
79+
]
80+
},
81+
config=types.CreateBatchJobConfig(
82+
display_name=_DISPLAY_NAME,
83+
webhook_config=types.WebhookConfig(
84+
uris=['https://example.com/webhook'],
85+
user_metadata={'batch_id': '123'},
86+
),
87+
),
88+
),
89+
exception_if_vertex='not supported in Vertex AI',
90+
),
91+
pytest_helper.TestTableItem(
92+
name='test_create_with_webhook_config_dict',
93+
parameters=types._CreateBatchJobParameters(
94+
model=_GEMINI_MODEL,
95+
src={
96+
'inlined_requests': [
97+
{
98+
'contents': [
99+
{'parts': [{'text': 'say hello'}], 'role': 'user'}
100+
]
101+
},
102+
]
103+
},
104+
config={
105+
'display_name': _DISPLAY_NAME,
106+
'webhook_config': {
107+
'uris': ['https://example.com/webhook'],
108+
},
109+
},
110+
),
111+
exception_if_vertex='not supported in Vertex AI',
112+
),
68113
]
69114

70115
pytestmark = [

google/genai/tests/models/test_generate_videos.py

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@
104104
labels={"veo_label_key": "generate_videos"},
105105
),
106106
),
107-
exception_if_mldev=(
108-
"not supported in Gemini API"
109-
),
107+
exception_if_mldev="not supported in Gemini API",
110108
),
111109
pytest_helper.TestTableItem(
112110
name="test_from_text_source",
@@ -202,9 +200,7 @@
202200
),
203201
),
204202
),
205-
exception_if_mldev=(
206-
"not supported in Gemini API"
207-
),
203+
exception_if_mldev="not supported in Gemini API",
208204
),
209205
pytest_helper.TestTableItem(
210206
name="test_all_parameters_mldev",
@@ -253,6 +249,39 @@
253249
"output_gcs_uri parameter is not supported in Gemini API"
254250
),
255251
),
252+
pytest_helper.TestTableItem(
253+
name="test_with_webhook_config",
254+
parameters=types._GenerateVideosParameters(
255+
model=VEO_MODEL_LATEST,
256+
prompt="Man with a dog",
257+
config=types.GenerateVideosConfig(
258+
number_of_videos=1,
259+
webhook_config=types.WebhookConfig(
260+
uris=["https://example.com/webhook"],
261+
user_metadata={"job_id": "video_123"},
262+
),
263+
),
264+
),
265+
exception_if_vertex=(
266+
"webhook_config parameter is not supported in Vertex AI"
267+
),
268+
),
269+
pytest_helper.TestTableItem(
270+
name="test_with_webhook_config_dict",
271+
parameters=types._GenerateVideosParameters(
272+
model=VEO_MODEL_LATEST,
273+
prompt="Man with a dog",
274+
config={
275+
"number_of_videos": 1,
276+
"webhook_config": {
277+
"uris": ["https://example.com/webhook"],
278+
},
279+
},
280+
),
281+
exception_if_vertex=(
282+
"webhook_config parameter is not supported in Vertex AI"
283+
),
284+
),
256285
]
257286

258287
pytestmark = pytest_helper.setup(
@@ -757,4 +786,3 @@ async def test_generated_video_extension_from_source_poll_async(client):
757786
video2 = operation2.result.generated_videos[0].video
758787
assert video2.uri
759788
assert await client.aio.files.download(file=video2)
760-

google/genai/types.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11097,6 +11097,46 @@ class VideoGenerationMaskDict(TypedDict, total=False):
1109711097
VideoGenerationMaskOrDict = Union[VideoGenerationMask, VideoGenerationMaskDict]
1109811098

1109911099

11100+
class WebhookConfig(_common.BaseModel):
11101+
"""Configuration for webhook notifications.
11102+
11103+
Used to configure webhook endpoints that will receive notifications
11104+
when long-running operations (e.g., batch jobs, video generation) complete.
11105+
"""
11106+
11107+
uris: Optional[list[str]] = Field(
11108+
default=None,
11109+
description="""The webhook URIs to receive notifications. If set, these
11110+
webhook URIs will be used instead of the registered webhooks.""",
11111+
)
11112+
user_metadata: Optional[dict[str, Any]] = Field(
11113+
default=None,
11114+
description="""User metadata that will be included in each webhook event
11115+
notification. Use this to attach custom key-value data to correlate
11116+
webhook events with your internal systems.""",
11117+
)
11118+
11119+
11120+
class WebhookConfigDict(TypedDict, total=False):
11121+
"""Configuration for webhook notifications.
11122+
11123+
Used to configure webhook endpoints that will receive notifications
11124+
when long-running operations (e.g., batch jobs, video generation) complete.
11125+
"""
11126+
11127+
uris: Optional[list[str]]
11128+
"""The webhook URIs to receive notifications. If set, these
11129+
webhook URIs will be used instead of the registered webhooks."""
11130+
11131+
user_metadata: Optional[dict[str, Any]]
11132+
"""User metadata that will be included in each webhook event
11133+
notification. Use this to attach custom key-value data to correlate
11134+
webhook events with your internal systems."""
11135+
11136+
11137+
WebhookConfigOrDict = Union[WebhookConfig, WebhookConfigDict]
11138+
11139+
1110011140
class GenerateVideosConfig(_common.BaseModel):
1110111141
"""Configuration for generating videos."""
1110211142

@@ -11180,6 +11220,11 @@ class GenerateVideosConfig(_common.BaseModel):
1118011220
default=None,
1118111221
description="""User specified labels to track billing usage.""",
1118211222
)
11223+
webhook_config: Optional[WebhookConfig] = Field(
11224+
default=None,
11225+
description="""Webhook configuration for receiving notifications when the
11226+
video generation operation completes.""",
11227+
)
1118311228

1118411229

1118511230
class GenerateVideosConfigDict(TypedDict, total=False):
@@ -11252,6 +11297,10 @@ class GenerateVideosConfigDict(TypedDict, total=False):
1125211297
labels: Optional[dict[str, str]]
1125311298
"""User specified labels to track billing usage."""
1125411299

11300+
webhook_config: Optional[WebhookConfigDict]
11301+
"""Webhook configuration for receiving notifications when the
11302+
video generation operation completes."""
11303+
1125511304

1125611305
GenerateVideosConfigOrDict = Union[
1125711306
GenerateVideosConfig, GenerateVideosConfigDict
@@ -16376,6 +16425,12 @@ class CreateBatchJobConfig(_common.BaseModel):
1637616425
"gs://path/to/output/data" or "bq://projectId.bqDatasetId.bqTableId".
1637716426
""",
1637816427
)
16428+
webhook_config: Optional[WebhookConfig] = Field(
16429+
default=None,
16430+
description="""Webhook configuration for receiving notifications when the batch
16431+
operation completes.
16432+
""",
16433+
)
1637916434

1638016435

1638116436
class CreateBatchJobConfigDict(TypedDict, total=False):
@@ -16393,6 +16448,11 @@ class CreateBatchJobConfigDict(TypedDict, total=False):
1639316448
"gs://path/to/output/data" or "bq://projectId.bqDatasetId.bqTableId".
1639416449
"""
1639516450

16451+
webhook_config: Optional[WebhookConfigDict]
16452+
"""Webhook configuration for receiving notifications when the batch
16453+
operation completes.
16454+
"""
16455+
1639616456

1639716457
CreateBatchJobConfigOrDict = Union[
1639816458
CreateBatchJobConfig, CreateBatchJobConfigDict

0 commit comments

Comments
 (0)