Skip to content

invoke_endpoint_async async

invoke_endpoint_async(
    endpoint_name: EndpointName,
    *,
    config_overrides: Optional[AsyncSageMakerRuntimeClientConfig] = None,
    content_type: Optional[Header] = None,
    accept: Optional[Header] = None,
    custom_attributes: Optional[CustomAttributesHeader] = None,
    inference_id: Optional[InferenceId] = None,
    input_location: Optional[InputLocationHeader] = None,
    s3_output_path_extension: Optional[S3OutputPathExtensionHeader] = None,
    filename: Optional[FilenameHeader] = None,
    request_ttl_seconds: Optional[RequestTTLSecondsHeader] = None,
    invocation_timeout_seconds: Optional[InvocationTimeoutSecondsHeader] = None,
    body: Optional[AsyncBodyBlob] = None,
) -> InvokeEndpointAsyncOutput

After you deploy a model into production using Amazon SageMaker AI hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.

Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.

Amazon SageMaker AI strips all POST headers except those supported by the API. Amazon SageMaker AI might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax.

Calls to InvokeEndpointAsync are authenticated by using Amazon Web Services Signature Version 4. For information, see Authenticating Requests (Amazon Web Services Signature Version 4) in the Amazon S3 API Reference.

Parameters:

  • endpoint_name (EndpointName) –

    The name of the endpoint that you specified when you created the endpoint using the CreateEndpoint API.

  • content_type (Optional[Header], default: None ) –

    The MIME type of the input data in the request body.

  • accept (Optional[Header], default: None ) –

    The desired MIME type of the inference response from the model container.

  • custom_attributes (Optional[CustomAttributesHeader], default: None ) –

    Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker AI endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in Section 3.3.6. Field Value Components of the Hypertext Transfer Protocol (HTTP/1.1).

    The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with Trace ID: in your post-processing function.

    This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker AI Python SDK.

  • inference_id (Optional[InferenceId], default: None ) –

    The identifier for the inference request. Amazon SageMaker AI will generate an identifier for you if none is specified.

  • input_location (Optional[InputLocationHeader], default: None ) –

    The Amazon S3 URI where the inference request payload is stored.

  • s3_output_path_extension (Optional[S3OutputPathExtensionHeader], default: None ) –

    The path extension that is appended to the Amazon S3 output path where the inference response payload is stored.

  • filename (Optional[FilenameHeader], default: None ) –

    The filename for the inference response payload stored in Amazon S3. If not specified, Amazon SageMaker AI generates a filename based on the inference ID.

  • request_ttl_seconds (Optional[RequestTTLSecondsHeader], default: None ) –

    Maximum age in seconds a request can be in the queue before it is marked as expired. The default is 6 hours, or 21,600 seconds.

  • invocation_timeout_seconds (Optional[InvocationTimeoutSecondsHeader], default: None ) –

    Maximum amount of time in seconds a request can be processed before it is marked as expired. The default is 15 minutes, or 900 seconds.

  • body (Optional[AsyncBodyBlob], default: None ) –

    Provides inline input data for the inference request, in the format specified in the ContentType request header. Use this parameter to send the request payload directly in the API call instead of uploading it to Amazon S3 and referencing it with InputLocation. The inline payload can be up to 128,000 bytes.

    Body and InputLocation are mutually exclusive. Provide exactly one of them.

    For information about the format of the request body, see Common Data Formats-Inference.

Raises:

Source code in docs_src/capo_sagemaker_runtime/_services/async_sage_maker_runtime.py
async def invoke_endpoint_async(
    self,
    endpoint_name: "capo_sagemaker_runtime.types.endpoint_name.EndpointName",
    *,
    config_overrides: Optional[AsyncSageMakerRuntimeClientConfig] = None,
    content_type: Optional["capo_sagemaker_runtime.types.header.Header"] = None,
    accept: Optional["capo_sagemaker_runtime.types.header.Header"] = None,
    custom_attributes: Optional[
        "capo_sagemaker_runtime.types.custom_attributes_header.CustomAttributesHeader"
    ] = None,
    inference_id: Optional[
        "capo_sagemaker_runtime.types.inference_id.InferenceId"
    ] = None,
    input_location: Optional[
        "capo_sagemaker_runtime.types.input_location_header.InputLocationHeader"
    ] = None,
    s3_output_path_extension: Optional[
        "capo_sagemaker_runtime.types.s3_output_path_extension_header.S3OutputPathExtensionHeader"
    ] = None,
    filename: Optional[
        "capo_sagemaker_runtime.types.filename_header.FilenameHeader"
    ] = None,
    request_ttl_seconds: Optional[
        "capo_sagemaker_runtime.types.request_ttl_seconds_header.RequestTTLSecondsHeader"
    ] = None,
    invocation_timeout_seconds: Optional[
        "capo_sagemaker_runtime.types.invocation_timeout_seconds_header.InvocationTimeoutSecondsHeader"
    ] = None,
    body: Optional[
        "capo_sagemaker_runtime.types.async_body_blob.AsyncBodyBlob"
    ] = None,
) -> "capo_sagemaker_runtime.types.invoke_endpoint_async_output.InvokeEndpointAsyncOutput":
    """<p>After you deploy a model into production using Amazon SageMaker AI hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.</p> <p>Inference requests sent to this API are enqueued for asynchronous processing. The processing of the inference request may or may not complete before you receive a response from this API. The response from this API will not contain the result of the inference request but contain information about where you can locate it.</p> <p>Amazon SageMaker AI strips all POST headers except those supported by the API. Amazon SageMaker AI might add additional headers. You should not rely on the behavior of headers outside those enumerated in the request syntax. </p> <p>Calls to <code>InvokeEndpointAsync</code> are authenticated by using Amazon Web Services Signature Version 4. For information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-authenticating-requests.html">Authenticating Requests (Amazon Web Services Signature Version 4)</a> in the <i>Amazon S3 API Reference</i>.</p>

    Args:
        endpoint_name: <p>The name of the endpoint that you specified when you created the endpoint using the <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/API_CreateEndpoint.html">CreateEndpoint</a> API.</p>
        content_type: <p>The MIME type of the input data in the request body.</p>
        accept: <p>The desired MIME type of the inference response from the model container.</p>
        custom_attributes: <p>Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker AI endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to provide an ID that you can use to track a request or to provide other metadata that a service endpoint was programmed to process. The value must consist of no more than 1024 visible US-ASCII characters as specified in <a href="https://datatracker.ietf.org/doc/html/rfc7230#section-3.2.6">Section 3.3.6. Field Value Components</a> of the Hypertext Transfer Protocol (HTTP/1.1). </p> <p>The code in your model is responsible for setting or updating any custom attributes in the response. If your code does not set this value in the response, an empty value is returned. For example, if a custom attribute represents the trace ID, your model can prepend the custom attribute with <code>Trace ID:</code> in your post-processing function. </p> <p>This feature is currently supported in the Amazon Web Services SDKs but not in the Amazon SageMaker AI Python SDK. </p>
        inference_id: <p>The identifier for the inference request. Amazon SageMaker AI will generate an identifier for you if none is specified. </p>
        input_location: <p>The Amazon S3 URI where the inference request payload is stored.</p>
        s3_output_path_extension: <p>The path extension that is appended to the Amazon S3 output path where the inference response payload is stored.</p>
        filename: <p>The filename for the inference response payload stored in Amazon S3. If not specified, Amazon SageMaker AI generates a filename based on the inference ID.</p>
        request_ttl_seconds: <p>Maximum age in seconds a request can be in the queue before it is marked as expired. The default is 6 hours, or 21,600 seconds.</p>
        invocation_timeout_seconds: <p>Maximum amount of time in seconds a request can be processed before it is marked as expired. The default is 15 minutes, or 900 seconds.</p>
        body: <p>Provides inline input data for the inference request, in the format specified in the <code>ContentType</code> request header. Use this parameter to send the request payload directly in the API call instead of uploading it to Amazon S3 and referencing it with <code>InputLocation</code>. The inline payload can be up to 128,000 bytes.</p> <p> <code>Body</code> and <code>InputLocation</code> are mutually exclusive. Provide exactly one of them.</p> <p>For information about the format of the request body, see <a href="https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html">Common Data Formats-Inference</a>.</p>

    Raises:
        capo_sagemaker_runtime.errors.internal_failure.InternalFailure: <p> An internal failure occurred. </p>
        capo_sagemaker_runtime.errors.service_unavailable.ServiceUnavailable: <p> The service is unavailable. Try your call again. </p>
        capo_sagemaker_runtime.errors.validation_error.ValidationError: <p> Inspect your request and try again. </p>
        capo_sagemaker_runtime.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_sagemaker_runtime.types.invoke_endpoint_async_input.InvokeEndpointAsyncInput]",
    ) -> AsyncOperationResponse[
        "capo_sagemaker_runtime.types.invoke_endpoint_async_output.InvokeEndpointAsyncOutput"
    ]:
        import capo_sagemaker_runtime._operations.amazon_sage_maker_runtime.invoke_endpoint_async

        (
            output,
            http_response,
        ) = await capo_sagemaker_runtime._operations.amazon_sage_maker_runtime.invoke_endpoint_async.async_invoke_endpoint_async(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_sagemaker_runtime.types.invoke_endpoint_async_input.InvokeEndpointAsyncInput",
    ) -> dict[str, Any]:
        import capo_sagemaker_runtime.types.invoke_endpoint_async_input

        return capo_sagemaker_runtime.types.invoke_endpoint_async_input.redact_sensitive(
            input_
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("InvokeEndpointAsync", redact_input=_redact_input),
    )
    input_: capo_sagemaker_runtime.types.invoke_endpoint_async_input.InvokeEndpointAsyncInput = {
        "endpoint_name": endpoint_name
    }
    if content_type is not None:
        input_["content_type"] = content_type
    if accept is not None:
        input_["accept"] = accept
    if custom_attributes is not None:
        input_["custom_attributes"] = custom_attributes
    if inference_id is not None:
        input_["inference_id"] = inference_id
    if input_location is not None:
        input_["input_location"] = input_location
    if s3_output_path_extension is not None:
        input_["s3_output_path_extension"] = s3_output_path_extension
    if filename is not None:
        input_["filename"] = filename
    if request_ttl_seconds is not None:
        input_["request_ttl_seconds"] = request_ttl_seconds
    if invocation_timeout_seconds is not None:
        input_["invocation_timeout_seconds"] = invocation_timeout_seconds
    if body is not None:
        input_["body"] = body

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output