class documentation

Contain an RPC invocation with retries and authorization.

Generated client methods use Request. It controls one RPC:

  • preparing and populating protobuf request objects,
  • attaching metadata and idempotency keys,
  • performing an authorization step when needed, and
  • executing retry logic with per-attempt timeouts.

Callers typically either await the request or call wait to run it synchronously.

nebius.aio.request_kwargs.RequestKwargs contains parameters that apply to all request types. Generated methods and wrappers pass these parameters through. Use this class to infer and validate request parameters.

Example:

from nebius.sdk import SDK
from nebius.aio.cli_config import Config
from nebius.api.nebius.storage.v1 import (
    BucketServiceClient,
    CreateBucketRequest,
)

sdk = SDK(
    config_reader=Config(),
    user_agent_prefix="example-application/1.0",
)
service = BucketServiceClient(sdk)

# Create a request (typically done by generated client methods)
request = service.create(CreateBucketRequest(name="my-bucket"))

# Await the request asynchronously
response = await request
print(f"Created bucket: {response}")

# Or wait synchronously
response = request.wait()
print(f"Created bucket: {response}")

# Get request status
status = await request.status()
print(f"Request status: {status.code}")

# Get request ID
req_id = await request.request_id()
print(f"Request ID: {req_id}")

# Get trace ID
trace_id = await request.trace_id()
print(f"Trace ID: {trace_id}")

# Get initial metadata
initial_md = await request.initial_metadata()
print(f"Initial metadata: {dict(initial_md)}")

# Get trailing metadata
trailing_md = await request.trailing_metadata()
print(f"Trailing metadata: {dict(trailing_md)}")

# Synchronous helpers
req_id_sync = request.request_id_sync()
trace_id_sync = request.trace_id_sync()
initial_md_sync = request.initial_metadata_sync()
trailing_md_sync = request.trailing_metadata_sync()
Parameters
channelChannel used to resolve address channels and perform synchronous execution when callers use the synchronous helpers.
serviceFully-qualified service name used to construct the RPC path (e.g. "nebius.service.v1.MyService").
methodRPC method name (bare, without the service prefix), for example "Get" or "List".
requestThe request payload. Supported mutable protobuf messages are copied when the wrapper is created. Unknown custom values retain their historical pass-through behavior and must be thread-safe.
result_pb2_classProtobuf class used to deserialize the RPC response bytes into a message instance.
metadataOptional initial gRPC metadata to attach to the call.
timeoutOverall timeout (seconds) applied to the request execution portion, including dispatch to the SDK loop. Or None for infinite timeout. Default is DEFAULT_TIMEOUT.
auth_timeoutTimeout budget (seconds) reserved for authorization flows plus SDK-loop dispatch and request execution. When provided the total dispatch + authorization + request time will not exceed this value. Default is DEFAULT_AUTH_TIMEOUT. Provide None for infinite timeout.
auth_optionsOptional dictionary forwarded to the authenticator when performing authorization. See the authenticator documentation for provider-specific keys.
credentialsOptional gRPC CallCredentials to use for the RPC invocation.
compressionOptional gRPC compression setting for the RPC.
result_wrapperOptional callable used to post-process the raw protobuf response into a higher-level domain object. It is called as result_wrapper(service_method: str, channel: Channel, pb_obj).
grpc_channel_overrideOptionally provide an AddressChannel instance to use instead of resolving one from the main channel. This is useful for tests or when the caller already has a concrete address-bound channel.
error_wrapperOptional callable that maps a RequestStatus into a RequestError subclass used by the SDK. When omitted a default service-specific wrapper is used.
retriesNumber of retry attempts for transient failures. Default is 3.
per_retry_timeoutTimeout (seconds) applied to each retry attempt individually. You can pass None for infinite timeout. Default is DEFAULT_PER_RETRY_TIMEOUT.
Raises
ValueErrorIf a timeout value is NaN or infinite. Use None for an unlimited timeout.
Method __await__ Support awaiting the Request instance.
Method __init__ Initialize the request with the provided parameters.
Method __repr__ Return a short representation including service, method and status.
Method cancel Request cancellation and report whether the intent was accepted.
Method cancelled Return True if the call was cancelled (locally or remotely).
Method compression.setter Undocumented
Method credentials.setter Undocumented
Method current_status Return the current request status or an unfinished sentinel.
Method done Return True if the underlying gRPC call has completed.
Async Method initial_metadata Return the initial metadata from the RPC.
Method initial_metadata_sync Synchronously return the initial metadata received from the RPC.
Method input_metadata Return the metadata that will be sent with the request (mutable).
Async Method request_id Return the request ID from the initial metadata.
Method request_id_sync Synchronous helper to return the request id.
Method run_sync_with_timeout Run an awaitable synchronously using the channel's sync runner.
Async Method status Return the final request status, awaiting completion if needed.
Method timeout.setter Undocumented
Async Method trace_id Return the trace ID from the initial metadata.
Method trace_id_sync Synchronous helper to return the trace id.
Async Method trailing_metadata Return the trailing metadata from the RPC.
Method trailing_metadata_sync Synchronously return the trailing metadata received from the RPC.
Method wait Wait for the request synchronously.
Method wait_for_ready.setter Undocumented
Property compression Return the configured compression option for the RPC call.
Property credentials Return optional gRPC CallCredentials attached to the request.
Property timeout Return the configured overall timeout for the request in seconds.
Property wait_for_ready Return the wait_for_ready flag used when starting the RPC call.
Async Method _await_native_call Await the active native call without losing a completed result.
Async Method _await_result Await the request's shared submission and return its result.
Method _check_process Reject a request inherited by a child process before locking.
Method _claim_await Claim the request's documented one-shot await operation.
Async Method _complete_authoritative_success Copy terminal state without allowing SDK close to erase success.
Method _convert_request_error Attempt to raise and swallow a RequestError from an AioRpcError.
Method _ensure_submitted Schedule the request once and return its shared awaitable.
Async Method _get_request_id Ensure metadata is received and return the request and trace ids.
Method _mark_native_attempt_terminal Publish native attempt completion before its awaiter resumes.
Method _parse_request_id Extract request and trace ids from cached initial metadata.
Method _pause_request_deadline Pause the request-only clock while authorization runs.
Method _raise_request_error Convert a gRPC AioRpcError into the SDK's RequestError and status.
Method _release_grpc_channel Release and forget the request's current transport lease.
Async Method _request_with_authorization_loop Wrap request retry loop with an authorization loop.
Async Method _request_with_authorization_loop_impl Authenticate and run the native request/retry state machine.
Method _resolve_authorization_retry Publish an authorization retry decision atomically.
Method _resume_request_deadline Resume the request-only clock for native RPC and retry work.
Async Method _retry_loop Core retry loop for the RPC invocation.
Method _send Prepare and start the underlying gRPC unary-unary call.
Method _structured_error_is_retriable Classify rich service retry hints before publishing finality.
Method _sync_wait_timeout Return the bounded wait used by synchronous request adapters.
Instance Variable _auth_options Undocumented
Instance Variable _auth_timeout Undocumented
Instance Variable _authorization_deadline Undocumented
Instance Variable _awaited Undocumented
Instance Variable _call Undocumented
Instance Variable _cancel_after_terminal_attempt Undocumented
Instance Variable _cancelled Undocumented
Instance Variable _channel Undocumented
Instance Variable _compression Undocumented
Instance Variable _credentials Undocumented
Instance Variable _dispatch_deadline Undocumented
Instance Variable _dispatch_started Undocumented
Instance Variable _error_wrapper Undocumented
Instance Variable _future Undocumented
Instance Variable _future_lock Undocumented
Instance Variable _grpc_channel Undocumented
Instance Variable _grpc_channel_override Undocumented
Instance Variable _initial_metadata Undocumented
Instance Variable _input Undocumented
Instance Variable _input_metadata Undocumented
Instance Variable _method Undocumented
Instance Variable _native_attempt_terminal Undocumented
Instance Variable _native_code Undocumented
Instance Variable _native_terminal Undocumented
Instance Variable _per_retry_timeout Undocumented
Instance Variable _process_id Undocumented
Instance Variable _registry Undocumented
Instance Variable _request_deadline Undocumented
Instance Variable _request_deadline_paused Undocumented
Instance Variable _request_id Undocumented
Instance Variable _request_timeout_remaining Undocumented
Instance Variable _result_pb2_class Undocumented
Instance Variable _result_wrapper Undocumented
Instance Variable _retries Undocumented
Instance Variable _retry_decision_pending Undocumented
Instance Variable _route Undocumented
Instance Variable _sent Undocumented
Instance Variable _service Undocumented
Instance Variable _start_time Undocumented
Instance Variable _status Undocumented
Instance Variable _submission_deadline Undocumented
Instance Variable _timeout Undocumented
Instance Variable _trace_id Undocumented
Instance Variable _trailing_metadata Undocumented
Instance Variable _wait_for_ready Undocumented
def __await__(self) -> Generator[Any, None, Res]: (source)

Support awaiting the Request instance.

The first await schedules the internal request; awaiting a finished request raises a RuntimeError to prevent double-execution semantics.

def __init__(self, channel: Channel, service: str, method: str, request: Req, result_pb2_class: type[Any], metadata: Metadata | Iterable[tuple[str, str]] | None = None, timeout: float | None | UnsetType = Unset, auth_timeout: float | None | UnsetType = Unset, auth_options: dict[str, str] | None = None, credentials: CallCredentials | None = None, compression: Compression | None = None, result_wrapper: Callable[[str, Channel, Any], Res] | None = None, grpc_channel_override: AddressChannel | None = None, error_wrapper: Callable[[RequestStatus], RequestError] | None = None, retries: int | None = 3, per_retry_timeout: float | None | UnsetType = Unset, route: Route | None = None): (source)

Initialize the request with the provided parameters.

def __repr__(self) -> str: (source)

Return a short representation including service, method and status.

def cancel(self) -> bool: (source)

Request cancellation and report whether the intent was accepted.

If the gRPC call exists, cancel that call. Otherwise, set a local flag to prevent the request from sending the call.

A native attempt can finish immediately before its SDK-loop wrapper classifies the result. In that narrow interval this method returns True because it accepted the cancellation intent, but an already authoritative success still wins. The request then completes successfully and cancelled returns False. Thus the return value describes acceptance at call time, not a guarantee about the request's eventual terminal state.

def cancelled(self) -> bool: (source)

Return True if the call was cancelled (locally or remotely).

@compression.setter
def compression(self, compression: Compression | None): (source)

Undocumented

@credentials.setter
def credentials(self, credentials: CallCredentials | None): (source)

Undocumented

Return the current request status or an unfinished sentinel.

When the RPC has not yet started this returns UnfinishedRequestStatus.INITIALIZED. When the call is in progress it returns UnfinishedRequestStatus.SENT. When the call completed it returns a concrete RequestStatus.

Returns
either nebius.aio.request_status.RequestStatus or nebius.aio.request_status.UnfinishedRequestStatusUndocumented
def done(self) -> bool: (source)

Return True if the underlying gRPC call has completed.

async def initial_metadata(self) -> Metadata: (source)

Return the initial metadata from the RPC.

If the request failed but initial metadata was still produced it will be returned. Otherwise a RequestError is raised.

def initial_metadata_sync(self) -> Metadata: (source)

Synchronously return the initial metadata received from the RPC.

If initial metadata is not already cached this helper awaits the request (via the sync runner) and returns the initial metadata. :returns: initial metadata :rtype: nebius.base.metadata.Metadata

def input_metadata(self) -> Metadata: (source)

Return the metadata that will be sent with the request (mutable).

Before first submission, callers may modify the returned object. The SDK snapshots it when the request is first awaited or synchronously waited. After submission this method returns a copy, so external mutation cannot race authorization or transport processing on the SDK loop.

async def request_id(self) -> str: (source)

Return the request ID from the initial metadata.

This coroutine awaits the request if the metadata is not available.

This method wraps _get_request_id.

def request_id_sync(self) -> str: (source)

Synchronous helper to return the request id.

If the id is already cached it is returned synchronously. Otherwise the request is awaited via the sync runner and the id is returned.

def run_sync_with_timeout(self, func: Awaitable[T]) -> T: (source)

Run an awaitable synchronously using the channel's sync runner.

Bound the synchronous wait by the request budget and, when the request uses authorization, its authorization budget. For a request that has already been submitted, use the remaining absolute submission deadline rather than granting a fresh timeout. If the runner raises TimeoutError, convert it to RequestError with DEADLINE_EXCEEDED. Callers can then inspect all timeout failures in the same way.

Parameters
func:Awaitable[T]awaitable to execute
Returns
Tresult of the awaitable
Raises
RequestErrorwhen execution times out or the request fails
async def status(self) -> RequestStatus: (source)

Return the final request status, awaiting completion if needed.

When the request fails but a status object is still available it is returned. Otherwise a RequestError is raised.

@timeout.setter
def timeout(self, timeout: float | None): (source)

Undocumented

async def trace_id(self) -> str: (source)

Return the trace ID from the initial metadata.

This coroutine awaits the request if the metadata is not available. This method wraps _get_request_id.

def trace_id_sync(self) -> str: (source)

Synchronous helper to return the trace id.

If the id is already cached it is returned synchronously. Otherwise the request is awaited via the sync runner and the id is returned.

async def trailing_metadata(self) -> Metadata: (source)

Return the trailing metadata from the RPC.

If the request failed but trailing metadata was still produced it will be returned. Otherwise a RequestError is raised.

def trailing_metadata_sync(self) -> Metadata: (source)

Synchronously return the trailing metadata received from the RPC.

If trailing metadata is not already cached this helper awaits the request (via the sync runner) and returns the trailing metadata. :returns: trailing metadata :rtype: nebius.base.metadata.Metadata

def wait(self) -> Res: (source)

Wait for the request synchronously.

Equivalent to run_sync_with_timeout(self).

@wait_for_ready.setter
def wait_for_ready(self, wait_for_ready: bool | None): (source)

Undocumented

Return the configured compression option for the RPC call.

Return optional gRPC CallCredentials attached to the request.

Return the configured overall timeout for the request in seconds.

None means no timeout.

@property
wait_for_ready: bool | None = (source)

Return the wait_for_ready flag used when starting the RPC call.

async def _await_native_call(self) -> Res: (source)

Await the active native call without losing a completed result.

SDK shutdown cancels runtime tasks directly. When the native done callback has already published completion, recover that authoritative result or error instead of allowing wrapper cancellation to replace it.

Returns
ResNative response value.
Raises
RequestSentNoCallErrorIf no native call is active.
async def _await_result(self) -> Res: (source)

Await the request's shared submission and return its result.

def _check_process(self): (source)

Reject a request inherited by a child process before locking.

def _claim_await(self): (source)

Claim the request's documented one-shot await operation.

async def _complete_authoritative_success(self, result: Any) -> Res: (source)

Copy terminal state without allowing SDK close to erase success.

The native response is already authoritative when this method starts. Runtime shutdown can cancel the parent submission. A shielded child task processes final metadata, converts errors, wraps the result, and releases the transport. The parent waits for this task before it returns.

Parameters
result:AnyNative response value.
Returns
ResNative or wrapped response value.
def _convert_request_error(self, err: AioRpcError): (source)

Attempt to raise and swallow a RequestError from an AioRpcError.

This helper is used to set status and other metadata that came with the AioRpcError without actually raising the RequestError.

def _ensure_submitted(self) -> Awaitable[Res]: (source)

Schedule the request once and return its shared awaitable.

Built-in channels return a reusable cross-loop handle, allowing synchronous wait to avoid an unnecessary second runtime task. Legacy channels retain their loop-local scheduled-awaitable behavior.

Returns
Awaitable[Res]Shared request awaitable.
async def _get_request_id(self) -> tuple[str, str]: (source)

Ensure metadata is received and return the request and trace ids.

Returns a tuple (request_id, trace_id) extracted from the initial metadata. This coroutine awaits the request if the metadata is not available.

def _mark_native_attempt_terminal(self, completed: object): (source)

Publish native attempt completion before its awaiter resumes.

The SDK loop still has to classify a terminal attempt as success, final error, or retriable error. Cancellation during that interval is recorded but does not cancel the wrapper task and erase a native success.

def _parse_request_id(self): (source)

Extract request and trace ids from cached initial metadata.

Raises RequestError when initial metadata is not present.

def _pause_request_deadline(self): (source)

Pause the request-only clock while authorization runs.

SDK-loop queueing is charged before the first pause. Native RPC work, retry classification, and backoff consume the retained budget; time spent authenticating does not. The authorization deadline separately caps authentication plus all request attempts.

def _raise_request_error(self, err: AioRpcError): (source)

Convert a gRPC AioRpcError into the SDK's RequestError and status.

This extracts initial/trailing metadata, parses request identifiers and attempts to convert the gRPC status into the SDK's structured RequestStatus. The resulting status is stored on self._status and a nebius.aio.service_error.RequestError is raised.

def _release_grpc_channel(self, *, discard: bool = False): (source)

Release and forget the request's current transport lease.

Clearing the reference before invoking channel code prevents an outer authorization retry from reusing a wrapper that has already returned to the shared pool. It also ensures a custom release failure cannot leave this request claiming a lease whose pool state is unknown.

Parameters
discard:boolWhether the transport must be discarded instead of returned for reuse.
async def _request_with_authorization_loop(self) -> Res: (source)

Wrap request retry loop with an authorization loop.

This outer ownership guard releases a caller-supplied transport when provider construction, authentication, or cancellation fails before the native retry loop assumes responsibility for the lease. Cleanup failures are logged without replacing the original request error.

Returns
ResDeserialized or wrapped response value.
async def _request_with_authorization_loop_impl(self) -> Res: (source)

Authenticate and run the native request/retry state machine.

The authorization loop will attempt to authenticate and then execute the request retry loop. If the result is UNAUTHENTICATED and the authenticator allows retry, it will re-authenticate and try again while respecting the overall auth timeout.

Returns
ResDeserialized or wrapped response value.
def _resolve_authorization_retry(self, retry: bool) -> bool: (source)

Publish an authorization retry decision atomically.

An UNAUTHENTICATED native error remains terminal while the authenticator decides whether the logical request may retry. A cancellation accepted during that interval wins only when a retry would otherwise occur; a final native error remains authoritative.

Parameters
retry:boolWhether authentication and the RPC would be retried.
Returns
boolWhether a queued cancellation prevents that retry.
def _resume_request_deadline(self): (source)

Resume the request-only clock for native RPC and retry work.

async def _retry_loop(self, outer_deadline: float | None = None, *, defer_unauthenticated_release: bool = False) -> Res: (source)

Core retry loop for the RPC invocation.

This coroutine executes the RPC, applies per-attempt and overall timeouts, and implements retry/backoff rules for retriable errors. It returns the RPC result or raises the error that terminated the operation.

Parameters
outer_deadline:float | Noneoptional absolute monotonic timestamp that caps the total time budget for this retry loop.
defer_unauthenticated_release:boolKeep the active transport when an UNAUTHENTICATED error must be classified by the outer authorization loop. The outer loop either retains an explicit override for its retry or releases an ordinary pool lease.
Returns
Resthe deserialized RPC result (or wrapped result via result_wrapper when configured).
Raises
RequestError, AioRpcError, CancelledErrordepending on the failure mode.
def _send(self, timeout: float | None): (source)

Prepare and start the underlying gRPC unary-unary call.

Responsibilities:

  • Validate/serialize the request payload.
  • Populate parent identifiers into the request when absent and the channel exposes a parent id.
  • Resolve an AddressChannel via Channel.get_channel_by_method when no override was provided.
  • Create the gRPC call object and store it on self._call.
Parameters
timeout:optional floatper-attempt timeout to use for the RPC invocation.
Raises
RequestErrorwhen the request payload cannot be serialized or the request has been cancelled.
def _structured_error_is_retriable(self, error: AioRpcError) -> bool: (source)

Classify rich service retry hints before publishing finality.

Native gRPC status codes alone are insufficient: a rich status can carry a service error whose retry policy is CALL. Decode that status before cancel decides whether the logical request is final. Conversion is repeated by _raise_request_error only on the exceptional path so that the public status retains request IDs.

Parameters
error:AioRpcErrorNative RPC error containing optional rich status data.
Returns
boolWhether its structured status requests a call retry.
def _sync_wait_timeout(self) -> float | None: (source)

Return the bounded wait used by synchronous request adapters.

Applicable authorization deadlines start when built-in runtime work is submitted and bound the full authentication-plus-request process. Request timeout excludes authentication, so it is the outer wait only when authorization does not apply. Before submission this method makes the same choice when the channel exposes the caller-safe provider probe. Legacy channels enforce both independent clocks inside their request state machine. A small grace period lets the internal timeout path publish its structured error and finish cancellation before the outer blocking wait expires.

Returns
float | NoneRemaining synchronous wait in seconds, or None when both request and authorization budgets are unlimited.
_auth_options = (source)

Undocumented

_auth_timeout: float | None = (source)

Undocumented

_authorization_deadline: float | None = (source)

Undocumented

_awaited: bool = (source)

Undocumented

Undocumented

_cancel_after_terminal_attempt: bool = (source)

Undocumented

_cancelled: bool = (source)

Undocumented

_channel = (source)

Undocumented

_compression = (source)

Undocumented

_credentials = (source)

Undocumented

_dispatch_deadline: float | None = (source)

Undocumented

_dispatch_started: ConcurrentFuture[None] | None = (source)

Undocumented

_error_wrapper = (source)

Undocumented

Undocumented

_future_lock = (source)

Undocumented

_grpc_channel = (source)

Undocumented

_grpc_channel_override = (source)

Undocumented

_initial_metadata: Metadata | None = (source)

Undocumented

Undocumented

_input_metadata = (source)

Undocumented

Undocumented

_native_attempt_terminal: bool = (source)

Undocumented

_native_code: StatusCode | None = (source)

Undocumented

_native_terminal: bool = (source)

Undocumented

_per_retry_timeout: float | None = (source)

Undocumented

_process_id = (source)

Undocumented

_registry = (source)

Undocumented

_request_deadline: float | None = (source)

Undocumented

_request_deadline_paused: bool = (source)

Undocumented

_request_id: str | None = (source)

Undocumented

_request_timeout_remaining: float | None = (source)

Undocumented

_result_pb2_class = (source)

Undocumented

_result_wrapper = (source)

Undocumented

_retries = (source)

Undocumented

_retry_decision_pending: bool = (source)

Undocumented

Undocumented

Undocumented

_service = (source)

Undocumented

_start_time = (source)

Undocumented

_status: RequestStatusExtended | None = (source)

Undocumented

_submission_deadline: float | None = (source)

Undocumented

Undocumented

_trace_id: str | None = (source)

Undocumented

_trailing_metadata: Metadata | None = (source)

Undocumented

_wait_for_ready: bool | None = (source)

Undocumented