Table of Contents

Class WebhooksClient

Namespace
GenerativeAI.Clients
Assembly
GenerativeAI.dll

A client for the Gemini Webhooks API (/webhooks): register endpoints that receive event notifications for batch jobs, interactions and video generation instead of polling, ping them and rotate their signing secrets.

public class WebhooksClient : BaseClient
Inheritance
WebhooksClient
Inherited Members
Extension Methods

Remarks

The wire format follows python-genai's generated webhooks client (snake_case field and query parameter names). Requests go to {base}/{version}/webhooks on the Gemini Developer API and to {base}/{version}/projects/{project}/locations/{location}/webhooks on Vertex AI.

Constructors

WebhooksClient(IPlatformAdapter, HttpClient?, ILogger?)

Initializes a new instance of the WebhooksClient class.

public WebhooksClient(IPlatformAdapter platform, HttpClient? httpClient = null, ILogger? logger = null)

Parameters

platform IPlatformAdapter

The platform adapter (Google AI or Vertex AI).

httpClient HttpClient

Optional HTTP client.

logger ILogger

Optional logger.

Methods

CreateAsync(CreateWebhookRequest, CancellationToken)

Creates a new webhook (POST /webhooks).

public Task<Webhook> CreateAsync(CreateWebhookRequest request, CancellationToken cancellationToken = default)

Parameters

request CreateWebhookRequest

The webhook definition; Uri and SubscribedEvents are required.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Webhook>

The created webhook. NewSigningSecret is only populated in this response.

CreateAsync(string, IEnumerable<string>, string?, CancellationToken)

Creates a new webhook (POST /webhooks).

public Task<Webhook> CreateAsync(string uri, IEnumerable<string> subscribedEvents, string? name = null, CancellationToken cancellationToken = default)

Parameters

uri string

The URI to which webhook events will be sent.

subscribedEvents IEnumerable<string>

The events to subscribe to (see WebhookEvents).

name string

Optional user-provided name of the webhook.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Webhook>

The created webhook. NewSigningSecret is only populated in this response.

DeleteAsync(string, CancellationToken)

Deletes a webhook (DELETE /webhooks/{id}).

public Task DeleteAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The webhook ID (a webhooks/ prefix is accepted).

cancellationToken CancellationToken

A cancellation token.

Returns

Task

A task that completes when the webhook has been deleted.

GetAsync(string, CancellationToken)

Gets a webhook (GET /webhooks/{id}).

public Task<Webhook> GetAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The webhook ID (a webhooks/ prefix is accepted).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Webhook>

The webhook.

GetWebhooksUrl()

Gets the URL of the webhooks collection.

protected string GetWebhooksUrl()

Returns

string

The collection URL.

ListAllAsync(int?, CancellationToken)

Enumerates all webhooks, fetching subsequent pages as needed.

public IAsyncEnumerable<Webhook> ListAllAsync(int? pageSize = null, CancellationToken cancellationToken = default)

Parameters

pageSize int?

Optional page size used for each request.

cancellationToken CancellationToken

A cancellation token.

Returns

IAsyncEnumerable<Webhook>

An async sequence of every webhook.

ListAsync(int?, string?, CancellationToken)

Lists webhooks, one page at a time (GET /webhooks).

public Task<WebhookListResponse> ListAsync(int? pageSize = null, string? pageToken = null, CancellationToken cancellationToken = default)

Parameters

pageSize int?

The maximum number of webhooks to return (the service defaults to 50, max 1000).

pageToken string

A NextPageToken from a previous call.

cancellationToken CancellationToken

A cancellation token.

Returns

Task<WebhookListResponse>

One page of webhooks.

PingAsync(string, CancellationToken)

Sends a ping event to a webhook (POST /webhooks/{id}:ping), e.g. to test the endpoint.

public Task<WebhookPingResponse> PingAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string

The webhook ID (a webhooks/ prefix is accepted).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<WebhookPingResponse>

The (currently empty) ping response.

RotateSigningSecretAsync(string, string?, CancellationToken)

Generates a new signing secret for a webhook (POST /webhooks/{id}:rotateSigningSecret).

public Task<WebhookRotateSigningSecretResponse> RotateSigningSecretAsync(string id, string? revocationBehavior = null, CancellationToken cancellationToken = default)

Parameters

id string

The webhook ID (a webhooks/ prefix is accepted).

revocationBehavior string

Optional revocation behavior for the previous signing secrets (see WebhookRevocationBehaviors).

cancellationToken CancellationToken

A cancellation token.

Returns

Task<WebhookRotateSigningSecretResponse>

The response holding the newly generated secret.

UpdateAsync(string, WebhookUpdate, string?, CancellationToken)

Updates a webhook (PATCH /webhooks/{id}).

public Task<Webhook> UpdateAsync(string id, WebhookUpdate update, string? updateMask = null, CancellationToken cancellationToken = default)

Parameters

id string

The webhook ID (a webhooks/ prefix is accepted).

update WebhookUpdate

The fields to update; unset (null) fields are not sent.

updateMask string

Optional comma-separated list of fields to update, sent as the update_mask query parameter (e.g. "uri,subscribed_events").

cancellationToken CancellationToken

A cancellation token.

Returns

Task<Webhook>

The updated webhook.

See Also