SDK for PHP 3.x

Client: Aws\SageMakerRuntime\SageMakerRuntimeClient
Service ID: runtime.sagemaker
Version: 2017-05-13

This page describes the parameters and results for the operations of the Amazon SageMaker Runtime (2017-05-13), and shows how to use the Aws\SageMakerRuntime\SageMakerRuntimeClient object to call the described operations. This documentation is specific to the 2017-05-13 API version of the service.

Operation Summary

Each of the following operations can be created from a client using $client->getCommand('CommandName'), where "CommandName" is the name of one of the following operations. Note: a command is a value that encapsulates an operation and the parameters used to create an HTTP request.

You can also create and send a command immediately using the magic methods available on a client object: $client->commandName(/* parameters */). You can send the command asynchronously (returning a promise) by appending the word "Async" to the operation name: $client->commandNameAsync(/* parameters */).

InvokeEndpoint ( array $params = [] )
After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint.
InvokeEndpointAsync ( array $params = [] )
After you deploy a model into production using Amazon SageMaker hosting services, your client applications use this API to get inferences from the model hosted at the specified endpoint in an asynchronous manner.
InvokeEndpointWithResponseStream ( array $params = [] )
Invokes a model at the specified endpoint to return the inference response as a stream.

Operations

InvokeEndpoint

$result = $client->invokeEndpoint([/* ... */]);
$promise = $client->invokeEndpointAsync([/* ... */]);

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

For an overview of Amazon SageMaker, see How It Works.

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

Calls to InvokeEndpoint 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.

A customer's model containers must respond to requests within 60 seconds. The model itself can have a maximum processing time of 60 seconds before responding to invocations. If your model is going to take 50-60 seconds of processing time, the SDK socket timeout should be set to be 70 seconds.

Endpoints are scoped to an individual account, and are not public. The URL does not contain the account ID, but Amazon SageMaker determines the account ID from the authentication token that is supplied by the caller.

Parameter Syntax

$result = $client->invokeEndpoint([
    'Accept' => '<string>',
    'Body' => <string || resource || Psr\Http\Message\StreamInterface>, // REQUIRED
    'ContentType' => '<string>',
    'CustomAttributes' => '<string>',
    'EnableExplanations' => '<string>',
    'EndpointName' => '<string>', // REQUIRED
    'InferenceComponentName' => '<string>',
    'InferenceId' => '<string>',
    'TargetContainerHostname' => '<string>',
    'TargetModel' => '<string>',
    'TargetVariant' => '<string>',
]);

Parameter Details

Members
Accept
Type: string

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

Body
Required: Yes
Type: blob (string|resource|Psr\Http\Message\StreamInterface)

Provides input data, in the format specified in the ContentType request header. Amazon SageMaker passes all of the data in the body to the model.

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

ContentType
Type: string

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

CustomAttributes
Type: string

Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker 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 Python SDK.

EnableExplanations
Type: string

An optional JMESPath expression used to override the EnableExplanations parameter of the ClarifyExplainerConfig API. See the EnableExplanations section in the developer guide for more information.

EndpointName
Required: Yes
Type: string

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

InferenceComponentName
Type: string

If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke.

InferenceId
Type: string

If you provide a value, it is added to the captured data when you enable data capture on the endpoint. For information about data capture, see Capture Data.

TargetContainerHostname
Type: string

If the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke.

TargetModel
Type: string

The model to request for inference when invoking a multi-model endpoint.

TargetVariant
Type: string

Specify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights.

For information about how to use variant targeting to perform a/b testing, see Test models in production

Result Syntax

[
    'Body' => <string || resource || Psr\Http\Message\StreamInterface>,
    'ContentType' => '<string>',
    'CustomAttributes' => '<string>',
    'InvokedProductionVariant' => '<string>',
]

Result Details

Members
Body
Required: Yes
Type: blob (string|resource|Psr\Http\Message\StreamInterface)

Includes the inference provided by the model.

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

If the explainer is activated, the body includes the explanations provided by the model. For more information, see the Response section under Invoke the Endpoint in the Developer Guide.

ContentType
Type: string

The MIME type of the inference returned from the model container.

CustomAttributes
Type: string

Provides additional information in the response about the inference returned by a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to return an ID received in the CustomAttributes header of a request or other metadata that a service endpoint was programmed to produce. 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). If the customer wants the custom attribute returned, the model must set the custom attribute to be included on the way back.

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 Python SDK.

InvokedProductionVariant
Type: string

Identifies the production variant that was invoked.

Errors

InternalFailure:

An internal failure occurred.

ServiceUnavailable:

The service is unavailable. Try your call again.

ValidationError:

Inspect your request and try again.

ModelError:

Model (owned by the customer in the container) returned 4xx or 5xx error code.

InternalDependencyException:

Your request caused an exception with an internal dependency. Contact customer support.

ModelNotReadyException:

Either a serverless endpoint variant's resources are still being provisioned, or a multi-model endpoint is still downloading or loading the target model. Wait and try your request again.

InvokeEndpointAsync

$result = $client->invokeEndpointAsync([/* ... */]);
$promise = $client->invokeEndpointAsyncAsync([/* ... */]);

After you deploy a model into production using Amazon SageMaker 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 strips all POST headers except those supported by the API. Amazon SageMaker 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.

Parameter Syntax

$result = $client->invokeEndpointAsync([
    'Accept' => '<string>',
    'ContentType' => '<string>',
    'CustomAttributes' => '<string>',
    'EndpointName' => '<string>', // REQUIRED
    'InferenceId' => '<string>',
    'InputLocation' => '<string>', // REQUIRED
    'InvocationTimeoutSeconds' => <integer>,
    'RequestTTLSeconds' => <integer>,
]);

Parameter Details

Members
Accept
Type: string

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

ContentType
Type: string

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

CustomAttributes
Type: string

Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker 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 Python SDK.

EndpointName
Required: Yes
Type: string

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

InferenceId
Type: string

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

InputLocation
Required: Yes
Type: string

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

InvocationTimeoutSeconds
Type: int

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.

RequestTTLSeconds
Type: int

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.

Result Syntax

[
    'FailureLocation' => '<string>',
    'InferenceId' => '<string>',
    'OutputLocation' => '<string>',
]

Result Details

Members
FailureLocation
Type: string

The Amazon S3 URI where the inference failure response payload is stored.

InferenceId
Type: string

Identifier for an inference request. This will be the same as the InferenceId specified in the input. Amazon SageMaker will generate an identifier for you if you do not specify one.

OutputLocation
Type: string

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

Errors

InternalFailure:

An internal failure occurred.

ServiceUnavailable:

The service is unavailable. Try your call again.

ValidationError:

Inspect your request and try again.

InvokeEndpointWithResponseStream

$result = $client->invokeEndpointWithResponseStream([/* ... */]);
$promise = $client->invokeEndpointWithResponseStreamAsync([/* ... */]);

Invokes a model at the specified endpoint to return the inference response as a stream. The inference stream provides the response payload incrementally as a series of parts. Before you can get an inference stream, you must have access to a model that's deployed using Amazon SageMaker hosting services, and the container for that model must support inference streaming.

For more information that can help you use this API, see the following sections in the Amazon SageMaker Developer Guide:

Before you can use this operation, your IAM permissions must allow the sagemaker:InvokeEndpoint action. For more information about Amazon SageMaker actions for IAM policies, see Actions, resources, and condition keys for Amazon SageMaker in the IAM Service Authorization Reference.

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

Calls to InvokeEndpointWithResponseStream 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.

Parameter Syntax

$result = $client->invokeEndpointWithResponseStream([
    'Accept' => '<string>',
    'Body' => <string || resource || Psr\Http\Message\StreamInterface>, // REQUIRED
    'ContentType' => '<string>',
    'CustomAttributes' => '<string>',
    'EndpointName' => '<string>', // REQUIRED
    'InferenceComponentName' => '<string>',
    'InferenceId' => '<string>',
    'TargetContainerHostname' => '<string>',
    'TargetVariant' => '<string>',
]);

Parameter Details

Members
Accept
Type: string

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

Body
Required: Yes
Type: blob (string|resource|Psr\Http\Message\StreamInterface)

Provides input data, in the format specified in the ContentType request header. Amazon SageMaker passes all of the data in the body to the model.

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

ContentType
Type: string

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

CustomAttributes
Type: string

Provides additional information about a request for an inference submitted to a model hosted at an Amazon SageMaker 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 Python SDK.

EndpointName
Required: Yes
Type: string

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

InferenceComponentName
Type: string

If the endpoint hosts one or more inference components, this parameter specifies the name of inference component to invoke for a streaming response.

InferenceId
Type: string

An identifier that you assign to your request.

TargetContainerHostname
Type: string

If the endpoint hosts multiple containers and is configured to use direct invocation, this parameter specifies the host name of the container to invoke.

TargetVariant
Type: string

Specify the production variant to send the inference request to when invoking an endpoint that is running two or more variants. Note that this parameter overrides the default behavior for the endpoint, which is to distribute the invocation traffic based on the variant weights.

For information about how to use variant targeting to perform a/b testing, see Test models in production

Result Syntax

[
    'Body' => [ // EventParsingIterator
        'InternalStreamFailure' => [
            'Message' => '<string>',
        ],
        'ModelStreamError' => [
            'ErrorCode' => '<string>',
            'Message' => '<string>',
        ],
        'PayloadPart' => [
            'Bytes' => <string || resource || Psr\Http\Message\StreamInterface>,
        ],
    ],
    'ContentType' => '<string>',
    'CustomAttributes' => '<string>',
    'InvokedProductionVariant' => '<string>',
]

Result Details

Members
Body
Required: Yes
Type: EventParsingIterator supplying the following structures: PayloadPart, ModelStreamError, InternalStreamFailure

A stream of payload parts. Each part contains a portion of the response for a streaming inference request.

ContentType
Type: string

The MIME type of the inference returned from the model container.

CustomAttributes
Type: string

Provides additional information in the response about the inference returned by a model hosted at an Amazon SageMaker endpoint. The information is an opaque value that is forwarded verbatim. You could use this value, for example, to return an ID received in the CustomAttributes header of a request or other metadata that a service endpoint was programmed to produce. 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). If the customer wants the custom attribute returned, the model must set the custom attribute to be included on the way back.

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 Python SDK.

InvokedProductionVariant
Type: string

Identifies the production variant that was invoked.

Using an EventParsingIterator

To use an EventParsingIterator, you will need to loop over the events it will generate and check the top-level field to determine which type of event it is.

foreach($result['Body'] as $event) {
    if (isset($event['InternalStreamFailure'])) {
        // Handle the 'InternalStreamFailure' event.
    } else if (isset($event['ModelStreamError'])) {
        // Handle the 'ModelStreamError' event.
    } else if (isset($event['PayloadPart'])) {
        // Handle the 'PayloadPart' event.
    }
}

Errors

InternalFailure:

An internal failure occurred.

ServiceUnavailable:

The service is unavailable. Try your call again.

ValidationError:

Inspect your request and try again.

ModelError:

Model (owned by the customer in the container) returned 4xx or 5xx error code.

ModelStreamError:

An error occurred while streaming the response body. This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

InternalStreamFailure:

The stream processing failed because of an unknown error, exception or failure. Try your request again.

Shapes

InternalDependencyException

Description

Your request caused an exception with an internal dependency. Contact customer support.

Members
Message
Type: string

InternalFailure

Description

An internal failure occurred.

Members
Message
Type: string

InternalStreamFailure

Description

The stream processing failed because of an unknown error, exception or failure. Try your request again.

Members
Message
Type: string

ModelError

Description

Model (owned by the customer in the container) returned 4xx or 5xx error code.

Members
LogStreamArn
Type: string

The Amazon Resource Name (ARN) of the log stream.

Message
Type: string
OriginalMessage
Type: string

Original message.

OriginalStatusCode
Type: int

Original status code.

ModelNotReadyException

Description

Either a serverless endpoint variant's resources are still being provisioned, or a multi-model endpoint is still downloading or loading the target model. Wait and try your request again.

Members
Message
Type: string

ModelStreamError

Description

An error occurred while streaming the response body. This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

Members
ErrorCode
Type: string

This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

Message
Type: string

PayloadPart

Description

A wrapper for pieces of the payload that's returned in response to a streaming inference request. A streaming inference response consists of one or more payload parts.

Members
Bytes
Type: blob (string|resource|Psr\Http\Message\StreamInterface)

A blob that contains part of the response for your streaming inference request.

ResponseStream

Description

A stream of payload parts. Each part contains a portion of the response for a streaming inference request.

Members
InternalStreamFailure
Type: InternalStreamFailure structure

The stream processing failed because of an unknown error, exception or failure. Try your request again.

ModelStreamError
Type: ModelStreamError structure

An error occurred while streaming the response body. This error can have the following error codes:

ModelInvocationTimeExceeded

The model failed to finish sending the response within the timeout period allowed by Amazon SageMaker.

StreamBroken

The Transmission Control Protocol (TCP) connection between the client and the model was reset or closed.

PayloadPart
Type: PayloadPart structure

A wrapper for pieces of the payload that's returned in response to a streaming inference request. A streaming inference response consists of one or more payload parts.

ServiceUnavailable

Description

The service is unavailable. Try your call again.

Members
Message
Type: string

ValidationError

Description

Inspect your request and try again.

Members
Message
Type: string