class Request(Generic[
Constructor: Request(channel, service, method, request, ...)
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 | |
| channel | Channel used to resolve address channels and perform synchronous execution when callers use the synchronous helpers. |
| service | Fully-qualified service name used to construct the RPC path (e.g. "nebius.service.v1.MyService"). |
| method | RPC method name (bare, without the service prefix), for example "Get" or "List". |
| request | The 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 | Protobuf class used to deserialize the RPC response bytes into a message instance. |
| metadata | Optional initial gRPC metadata to attach to the call. |
| timeout | Overall timeout (seconds) applied to the request execution
portion, including dispatch to the SDK loop. Or None for infinite
timeout.
Default is DEFAULT_TIMEOUT. |
| auth | Timeout 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 | Optional dictionary forwarded to the authenticator when performing authorization. See the authenticator documentation for provider-specific keys. |
| credentials | Optional gRPC CallCredentials to use for the
RPC invocation. |
| compression | Optional gRPC compression setting for the RPC. |
| result | Optional 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 | Optionally 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 | Optional callable that maps a RequestStatus
into a RequestError subclass used by the SDK. When omitted a
default service-specific wrapper is used. |
| retries | Number of retry attempts for transient failures. Default is 3. |
| per | Timeout (seconds) applied to each retry attempt
individually. You can pass None for infinite timeout. Default is
DEFAULT_PER_RETRY_TIMEOUT. |
| Raises | |
ValueError | If 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 |
Undocumented |
| Method | credentials |
Undocumented |
| Method | current |
Return the current request status or an unfinished sentinel. |
| Method | done |
Return True if the underlying gRPC call has completed. |
| Async Method | initial |
Return the initial metadata from the RPC. |
| Method | initial |
Synchronously return the initial metadata received from the RPC. |
| Method | input |
Return the metadata that will be sent with the request (mutable). |
| Async Method | request |
Return the request ID from the initial metadata. |
| Method | request |
Synchronous helper to return the request id. |
| Method | run |
Run an awaitable synchronously using the channel's sync runner. |
| Async Method | status |
Return the final request status, awaiting completion if needed. |
| Method | timeout |
Undocumented |
| Async Method | trace |
Return the trace ID from the initial metadata. |
| Method | trace |
Synchronous helper to return the trace id. |
| Async Method | trailing |
Return the trailing metadata from the RPC. |
| Method | trailing |
Synchronously return the trailing metadata received from the RPC. |
| Method | wait |
Wait for the request synchronously. |
| Method | wait |
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 |
Return the wait_for_ready flag used when starting the RPC call. |
| Async Method | _await |
Await the active native call without losing a completed result. |
| Async Method | _await |
Await the request's shared submission and return its result. |
| Method | _check |
Reject a request inherited by a child process before locking. |
| Method | _claim |
Claim the request's documented one-shot await operation. |
| Async Method | _complete |
Copy terminal state without allowing SDK close to erase success. |
| Method | _convert |
Attempt to raise and swallow a RequestError from an AioRpcError. |
| Method | _ensure |
Schedule the request once and return its shared awaitable. |
| Async Method | _get |
Ensure metadata is received and return the request and trace ids. |
| Method | _mark |
Publish native attempt completion before its awaiter resumes. |
| Method | _parse |
Extract request and trace ids from cached initial metadata. |
| Method | _pause |
Pause the request-only clock while authorization runs. |
| Method | _raise |
Convert a gRPC AioRpcError into the SDK's RequestError and status. |
| Method | _release |
Release and forget the request's current transport lease. |
| Async Method | _request |
Wrap request retry loop with an authorization loop. |
| Async Method | _request |
Authenticate and run the native request/retry state machine. |
| Method | _resolve |
Publish an authorization retry decision atomically. |
| Method | _resume |
Resume the request-only clock for native RPC and retry work. |
| Async Method | _retry |
Core retry loop for the RPC invocation. |
| Method | _send |
Prepare and start the underlying gRPC unary-unary call. |
| Method | _structured |
Classify rich service retry hints before publishing finality. |
| Method | _sync |
Return the bounded wait used by synchronous request adapters. |
| Instance Variable | _auth |
Undocumented |
| Instance Variable | _auth |
Undocumented |
| Instance Variable | _authorization |
Undocumented |
| Instance Variable | _awaited |
Undocumented |
| Instance Variable | _call |
Undocumented |
| Instance Variable | _cancel |
Undocumented |
| Instance Variable | _cancelled |
Undocumented |
| Instance Variable | _channel |
Undocumented |
| Instance Variable | _compression |
Undocumented |
| Instance Variable | _credentials |
Undocumented |
| Instance Variable | _dispatch |
Undocumented |
| Instance Variable | _dispatch |
Undocumented |
| Instance Variable | _error |
Undocumented |
| Instance Variable | _future |
Undocumented |
| Instance Variable | _future |
Undocumented |
| Instance Variable | _grpc |
Undocumented |
| Instance Variable | _grpc |
Undocumented |
| Instance Variable | _initial |
Undocumented |
| Instance Variable | _input |
Undocumented |
| Instance Variable | _input |
Undocumented |
| Instance Variable | _method |
Undocumented |
| Instance Variable | _native |
Undocumented |
| Instance Variable | _native |
Undocumented |
| Instance Variable | _native |
Undocumented |
| Instance Variable | _per |
Undocumented |
| Instance Variable | _process |
Undocumented |
| Instance Variable | _registry |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _request |
Undocumented |
| Instance Variable | _result |
Undocumented |
| Instance Variable | _result |
Undocumented |
| Instance Variable | _retries |
Undocumented |
| Instance Variable | _retry |
Undocumented |
| Instance Variable | _route |
Undocumented |
| Instance Variable | _sent |
Undocumented |
| Instance Variable | _service |
Undocumented |
| Instance Variable | _start |
Undocumented |
| Instance Variable | _status |
Undocumented |
| Instance Variable | _submission |
Undocumented |
| Instance Variable | _timeout |
Undocumented |
| Instance Variable | _trace |
Undocumented |
| Instance Variable | _trailing |
Undocumented |
| Instance Variable | _wait |
Undocumented |
Support awaiting the Request instance.
The first await schedules the internal request; awaiting a finished request raises a RuntimeError to prevent double-execution semantics.
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.
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.
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.UnfinishedRequestStatus | Undocumented |
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.
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
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.
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.
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.
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[ | awaitable to execute |
| Returns | |
T | result of the awaitable |
| Raises | |
RequestError | when execution times out or the request fails |
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.
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.
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.
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.
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
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 | |
Res | Native response value. |
| Raises | |
RequestSentNoCallError | If no native call is active. |
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:Any | Native response value. |
| Returns | |
Res | Native or wrapped response value. |
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.
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[ | Shared request awaitable. |
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.
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.
Extract request and trace ids from cached initial metadata.
Raises RequestError when initial metadata is not present.
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.
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.
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:bool | Whether the transport must be discarded instead of returned for reuse. |
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 | |
Res | Deserialized or wrapped response value. |
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 | |
Res | Deserialized or wrapped response value. |
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:bool | Whether authentication and the RPC would be retried. |
| Returns | |
bool | Whether a queued cancellation prevents that retry. |
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 | |
outerfloat | None | optional absolute monotonic timestamp that caps the total time budget for this retry loop. |
deferbool | Keep 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 | |
Res | the deserialized RPC result (or wrapped result via result_wrapper when configured). |
| Raises | |
RequestError, AioRpcError, CancelledError | depending on the failure mode. |
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
AddressChannelviaChannel.get_channel_by_methodwhen no override was provided. - Create the gRPC call object and store it on self._call.
| Parameters | |
timeout:optional float | per-attempt timeout to use for the RPC invocation. |
| Raises | |
RequestError | when the request payload cannot be serialized or the request has been cancelled. |
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:AioRpcError | Native RPC error containing optional rich status data. |
| Returns | |
bool | Whether its structured status requests a call retry. |
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 | None | Remaining synchronous wait in seconds, or None when both request and authorization budgets are unlimited. |