invoke_global_inference_gateway
¶
invoke_global_inference_gateway(
gateway_id: GatewayId,
content_type: RequestContentType,
body: RequestPayloadBlob,
*,
config_overrides: Optional[SageMakerGatewayRuntimeClientConfig] = None,
accept: Optional[str] = None,
customer_identity_token: Optional[CustomerIdentityToken] = None,
) -> InvokeGlobalInferenceGatewayOutput
Buffered (non-streaming) inference. Returns the full OpenAI completion body. 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>, or Global 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>. A BadGatewayException can instead read inference gateway: response ended unexpectedly, with no status, when the inference gateway's connection failed while it was sending the response. * 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. Every error status the inference gateway returns is a typed error, chosen by that status: * 400 and any other 4xx not listed here -- a 400 validation error. * 401 and 403 -- AccessDeniedException (403). * 404 -- ResourceNotFoundException. * 408 -- GatewayTimeoutException (504). * 429 -- ThrottlingException, with the Retry-After header. * 502, and 500, 503 or any other 5xx not listed here -- BadGatewayException (502). A 500 or 503 from the inference gateway comes after the request was dispatched, so it is not modeled as retryable, and the gateway may already have tried another inference gateway. Standard SDK retry modes may still retry a 5xx status; set max attempts to 1 if a repeated inference is unacceptable. * 504 -- GatewayTimeoutException.
Parameters:
-
gateway_id(GatewayId) –The ID of the Global Inference Gateway to invoke. IAM policies refer to the gateway by its ARN,
arn:<partition>:sagemaker:<region>:<account>:global-inference-gateway/<id>. -
accept(Optional[str], default:None) –The MIME type you want for the response. It is passed to the model server.
-
content_type(RequestContentType) –The MIME type of the request body. Pass
application/json(parameters such ascharset=utf-8are allowed): the body is one OpenAI JSON object. The Global Inference Gateway rejects other content types with a 415 error. -
customer_identity_token(Optional[CustomerIdentityToken], default:None) –Per-caller customer identity token (a JWT), forwarded unchanged to the inference gateway, which validates it. The gateway does not use it to authorize the request. Include it in the SigV4 signed headers so it cannot be altered in transit. Redacted from logs, metrics and traces.
-
body(RequestPayloadBlob) –The inference request body: one OpenAI JSON object, at most 10 MiB. Its content is passed to the model server unchanged, except that the request is always sent with
"stream": false: this operation returns one JSON document, so a"stream": truein the body is overridden (use InvokeGlobalInferenceGatewayWithResponseStream to stream). A body that is not one JSON object, or that repeats the top-levelmodelkey with different values, is rejected with a 400 validation error. A body larger than 10 MiB is rejected with PayloadTooLargeException (413). The gateway reads onlymodelandstream, and does not store the body.
Raises:
-
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 startinginference 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. -
BadGatewayException–502 -- 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-- on the buffered operation, the inference gateway stopped sending partway through the response body and the gateway's read timeout expired. (The same text on a GatewayTimeoutException means no response arrived.) * Any otherGlobal 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). Not modeled as retryable: a 502 can mean the inference already ran, and the gateway may already have tried another inference gateway. Standard SDK retry modes may still retry a 5xx status, which would run (and bill) the inference again; set max attempts to 1 if a repeated inference is unacceptable. -
GatewayTimeoutException–504 -- 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). Not modeled as retryable: a timeout does not prove the inference did not run, and the gateway may already have tried another inference gateway. Standard SDK retry modes may still retry a 5xx status, which could run (and bill) the inference again; set max attempts to 1 if a repeated inference is unacceptable. -
InternalServerException–An unexpected internal failure occurred.
-
PayloadTooLargeException–The request body exceeds the 10 MiB limit. Reduce the size of the payload and send the request again.
-
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 ServiceUnavailableException instead. A message starting
inference gatewaymeans the inference gateway serving the model returned a 404; up to 256 bytes of its error message are quoted. -
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 its
Message, not as this error. -
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 startinginference 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. -
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_sagemaker_gateway_runtime/_services/sage_maker_gateway_runtime.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |