ApiBaseSendAsyncTRequest, TResponse Method

Sends an HTTP request (e.g., POST, PUT, or PATCH) to the specified URL.

Definition

Namespace: GenerativeAI.Core
Assembly: GenerativeAI (in GenerativeAI.dll) Version: 2.0.2+aa51399cad6d90cc71158d589a6268608b3c1893
C#
protected Task<TResponse> SendAsync<TRequest, TResponse>(
	string url,
	TRequest payload,
	HttpMethod method,
	CancellationToken cancellationToken = default
)

Parameters

url  String
The full URL of the API endpoint.
payload  TRequest
The request payload to send in the body.
method  HttpMethod
The HTTP method (e.g., POST, PUT, PATCH).
cancellationToken  CancellationToken  (Optional)
Token to propagate notification that the operation should be canceled.

Type Parameters

TRequest
The type of the request payload.
TResponse
The type to deserialize the response into.

Return Value

TaskTResponse
The deserialized object from the response.

Exceptions

HttpRequestExceptionThrows upon a non-success status code.
InvalidOperationExceptionThrows if deserialization fails.

See Also