InvokeGlobalInferenceGatewayWithResponseStream
Streaming inference. Returns an AWS event stream of
PayloadPart events that carry the model server's
server-sent event (SSE) bytes, so SDKs decode the stream into events
for you.
The errors listed for this operation, other than
InternalStreamFailure, are returned before the response
starts (before the 200 status), so they end the request, not the
stream. None of them can occur after the 200.
InternalStreamFailure appears only as an event in the
stream, after the 200.
Once the 200 is sent, the stream carries the response as
PayloadPart events. If reading the inference gateway's
response fails, the stream carries one
InternalStreamFailure event and then ends.
Errors carry their origin in the Message prefix.
Every typed error's text is in the Message member (JSON
key Message), and starts with one of these
prefixes:
- Global Inference Gateway:
-
The gateway rejected or failed the request itself: validation, authorization, throttling, routing (the gateway or model was not found, or no capacity is available), a gateway limit or time limit, or failing to reach the inference gateway (
Global Inference Gateway: could not reach the inference gateway: <reason>, orGlobal Inference Gateway: timed out waiting for the inference gateway). This includes the 400 for an invalid request and the 413 for a request body that is too large. - inference gateway:
-
The inference gateway serving the model returned an error status. The message gives that status code and up to 256 bytes of its error message, for example
inference gateway: 503 <message>. - inference gateway (<component>):
-
The same, when the inference gateway reports which of its components produced the error, for example
inference gateway (model server): 502 <message>. The component is one of:- config
-
The inference gateway's configuration and proxy layer.
- scheduler
-
The inference gateway's request scheduler.
- model selector
-
The inference gateway's model selector.
- model server
-
The model server.
An InternalStreamFailure event's
Message uses the same prefixes, with the same text the
buffered operation uses for the same failure. Its inference
gateway: message carries no status: inference gateway:
response ended unexpectedly when the inference gateway's
connection failed while it was sending the response.
Every error status the inference gateway returns before the 200 is
a typed error, chosen by that status as for
InvokeGlobalInferenceGateway:
- 400, and any other 4xx not listed here
-
A 400 validation error.
- 401, 403
-
AccessDeniedException(403). - 404
-
ResourceNotFoundException. - 408
-
GatewayTimeoutException(504). - 429
-
ThrottlingException, with theRetry-Afterheader. - 502, and 500, 503 or any other 5xx not listed here
-
BadGatewayException(502). A 5xx from the inference gateway can occur after the model started processing the request, so it is not modeled as retryable, and the gateway may already have tried another inference gateway. - 504
-
GatewayTimeoutException.
This error is not modeled as retryable, but the standard retry modes of AWS SDKs retry 5xx status codes. Each retry runs the inference again.
Request Syntax
POST /global-inference-gateway/GatewayId/invocations-response-stream HTTP/1.1
Accept: Accept
Content-Type: ContentType
X-Amzn-SageMaker-Customer-Identity-Token: CustomerIdentityToken
Body
URI Request Parameters
The request uses the following URI parameters.
- Accept
-
The MIME type you want for the response. It is passed to the model server.
- ContentType
-
The MIME type of the request body, as for
InvokeGlobalInferenceGateway. Passapplication/json.Length Constraints: Minimum length of 1. Maximum length of 1024.
Required: Yes
- CustomerIdentityToken
-
The customer identity token (a JWT), as for
InvokeGlobalInferenceGateway. It is passed unchanged to the inference gateway, which validates it. - GatewayId
-
The ID of the Global Inference Gateway to invoke, as for
InvokeGlobalInferenceGateway.Length Constraints: Minimum length of 1. Maximum length of 64.
Pattern:
[a-z0-9]+Required: Yes
Request Body
The request accepts the following binary data.
- Body
-
The inference request body, as for
InvokeGlobalInferenceGateway, except that the request is always sent with"stream": true: this operation returns an event stream, so a"stream": falsein the body, or nostreamkey, is overridden. A body larger than 10 MiB is rejected withPayloadTooLargeException(413).Length Constraints: Minimum length of 0. Maximum length of 10485760.
Required: Yes
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"InternalStreamFailure": {
},
"ModelStreamError": {
},
"PayloadPart": {
"Bytes": blob
}
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- InternalStreamFailure
-
A failure after the stream started. The stream ends after this event.
Type: Exception
HTTP Status Code:
- ModelStreamError
-
Reserved for a model error during the stream. The Global Inference Gateway doesn't currently send this event. A failure after the stream starts is reported as
InternalStreamFailure.Type: Exception
HTTP Status Code:
- PayloadPart
-
A part of the model server's response.
Type: PayloadPart object
Errors
For information about the errors that are common to all actions, see Common Error Types.
- AccessDeniedException
-
The caller is not authorized to invoke this gateway. Invoking requires the
sagemaker:InvokeGlobalInferenceGatewaypermission, orsagemaker:InvokeGlobalInferenceGatewayWithResponseStreamfor the streaming operation, on the gateway ARN.A message starting
inference gatewaymeans the inference gateway serving the model refused the request with a 401 or 403, for example for its customer identity token. Its status code is in the message (the response status is 403), and up to 256 bytes of its error message are quoted.- Message
-
A description of the error. It starts with a prefix such as
Global Inference Gateway:orinference gateway:that says where the error came from.
HTTP Status Code: 403
- BadGatewayException
-
The gateway could not get a usable response from the inference gateway. The
Messageprefix says why:- Global Inference Gateway: could not reach the inference gateway: <reason>
-
The request could not be sent, or the connection closed before a response arrived. For example, the connection failed, or the inference gateway closed it after reading the request.
- Global Inference Gateway: timed out waiting for the inference gateway
-
The inference gateway stopped sending partway through the response body and the gateway's read timeout expired. The same text on a
GatewayTimeoutExceptionmeans no response arrived at all. - Any other Global Inference Gateway: message
-
The gateway ended a response before it was complete, for example because it exceeded the 10 MiB limit of the buffered operation, the request exceeded its maximum duration, or the inference gateway was taken out of service.
- inference gateway: <status> <message>
-
The inference gateway serving the model returned a 502, 500, 503 or another 5xx error. Its status code is in the message (the response status is 502), and up to 256 bytes of its error message are quoted.
- inference gateway: response ended unexpectedly
-
The inference gateway's connection failed while it was sending the response.
The inference gateway names a component in the prefix when it reports one:
inference gateway (<component>):, where the component isconfig(the inference gateway's configuration and proxy layer),scheduler(its request scheduler),model selector(its model selector) ormodel server(the model server).A 502 can mean the inference already ran, and the gateway may already have tried another inference gateway.
ImportantThis error is not modeled as retryable, but the standard retry modes of AWS SDKs retry 5xx status codes. Each retry runs the inference again.
- Message
-
A description of the error. It starts with a prefix such as
Global Inference Gateway:orinference gateway:that says where the error came from.
HTTP Status Code: 502
- GatewayTimeoutException
-
The inference gateway did not respond in time. The
Messageprefix says whose time limit expired:- Global Inference Gateway: timed out waiting for the inference gateway
-
The gateway's limit on the wait for the first part of the response.
- inference gateway: <status> <message>
-
The inference gateway serving the model returned a 504, or a 408 because it timed out waiting for the request to arrive. Its status code is in the message (the response status is 504), and up to 256 bytes of its error message are quoted.
The inference gateway names a component in the prefix when it reports one:
inference gateway (<component>):, where the component isconfig(the inference gateway's configuration and proxy layer),scheduler(its request scheduler),model selector(its model selector) ormodel server(the model server).A timeout does not prove the inference did not run, and the gateway may already have tried another inference gateway.
ImportantThis error is not modeled as retryable, but the standard retry modes of AWS SDKs retry 5xx status codes. Each retry runs the inference again.
- Message
-
A description of the error. It starts with a prefix such as
Global Inference Gateway:orinference gateway:that says where the error came from.
HTTP Status Code: 504
- InternalServerException
-
An unexpected internal failure occurred.
The gateway returns this error before the request reaches a model, so retrying it does not run the inference again. AWS SDKs retry this error automatically.
- Message
-
A description of the error. It starts with
Global Inference Gateway:, because the Global Inference Gateway returns this error itself.
HTTP Status Code: 500
- InternalStreamFailure
-
A failure after the stream started. The
Messagesays where it came from:Global Inference Gateway:when a gateway time limit expired or the inference gateway was taken out of service, orinference gateway: response ended unexpectedlywhen the inference gateway's connection failed while it was sending the response. The stream ends after this event, and AWS SDKs do not retry it.- Message
-
A description of the failure. It starts with
Global Inference Gateway:orinference gateway:, which says where the failure came from.
HTTP Status Code: 500
- ModelStreamError
-
Reserved for a model error during the stream. The Global Inference Gateway doesn't currently send this event. A failure after the stream starts is reported as
InternalStreamFailure.HTTP Status Code: 400
- PayloadTooLargeException
-
The request body exceeds the 10 MiB limit. Reduce the size of the payload and send the request again.
- Message
-
A description of the error. It starts with
Global Inference Gateway:, because the Global Inference Gateway returns this error itself.
HTTP Status Code: 413
- ResourceNotFoundException
-
No gateway with this ID exists in this account and Region, or no target of the gateway serves the model named in the request body. A model that is served but has no available target right now returns
ServiceUnavailableExceptioninstead.A message starting
inference gatewaymeans the inference gateway serving the model returned a 404; up to 256 bytes of its error message are quoted.- Message
-
A description of the error. It starts with a prefix such as
Global Inference Gateway:orinference gateway:that says where the error came from. - ResourceId
-
The ID of the resource that was not found: the gateway ID, or the model name.
- ResourceType
-
The kind of resource that was not found: the gateway, or the model.
HTTP Status Code: 404
- ServiceUnavailableException
-
The service is temporarily unable to serve the request, for example because no capacity is available for the requested model. The request was not dispatched for inference.
A 503 returned by the inference gateway serving the model after dispatch is reported as
BadGatewayException, with the 503 in itsMessage, not as this error.The gateway returns this error before the request reaches a model, so retrying it does not run the inference again. AWS SDKs retry this error automatically.
- Message
-
A description of the error. It starts with
Global Inference Gateway:, because the Global Inference Gateway returns this error itself.
HTTP Status Code: 503
- ThrottlingException
-
The request was throttled before it was dispatched for inference. Retry the request with backoff, after the
Retry-Afterseconds when the response carries one.A message starting
inference gatewaymeans the last inference gateway tried for the model returned a 429. The gateway may have tried others first, and they may have failed for other reasons. Up to 256 bytes of its error message are quoted.The gateway returns this error before the request reaches a model, so retrying it does not run the inference again. AWS SDKs retry this error automatically.
- Message
-
A description of the error. It starts with a prefix such as
Global Inference Gateway:orinference gateway:that says where the error came from.
HTTP Status Code: 429
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: