Amazon Bedrock Runtime

2023/09/28 - Amazon Bedrock Runtime - 2 new api methods

Changes  Model Invocation logging added to enable or disable logs in customer account. Model listing and description support added. Provisioned Throughput feature added. Custom model support added for creating custom models. Also includes list, and delete functions for custom model.

InvokeModel (new) Link ¶

Invokes the specified Bedrock model to run inference using the input provided in the request body. You use InvokeModel to run inference for text models, image models, and embedding models.

For more information about invoking models, see Using the API in the Bedrock User Guide .

For example requests, see Examples (after the Errors section).

See also: AWS API Documentation

Request Syntax

client.invoke_model(
    accept='string',
    body=b'bytes'|file,
    contentType='string',
    modelId='string'
)
type accept

string

param accept

The desired MIME type of the inference body in the response. The default value is application/json .

type body

bytes or seekable file-like object

param body

[REQUIRED]

Input data in the format specified in the content-type request header. To see the format and content of this field for different models, refer to Inference parameters .

type contentType

string

param contentType

The MIME type of the input data in the request. The default value is application/json .

type modelId

string

param modelId

[REQUIRED]

Identifier of the model.

rtype

dict

returns

Response Syntax

{
    'body': b'bytes'|file,
    'contentType': 'string'
}

Response Structure

  • (dict) --

    • body (bytes or seekable file-like object) --

      Inference response from the model in the format specified in the content-type header field. To see the format and content of this field for different models, refer to Inference parameters .

    • contentType (string) --

      The MIME type of the inference result.

InvokeModelWithResponseStream (new) Link ¶

Invoke the specified Bedrock model to run inference using the input provided. Return the response in a stream.

For more information about invoking models, see Using the API in the Bedrock User Guide .

For an example request and response, see Examples (after the Errors section).

See also: AWS API Documentation

Request Syntax

client.invoke_model_with_response_stream(
    accept='string',
    body=b'bytes'|file,
    contentType='string',
    modelId='string'
)
type accept

string

param accept

The desired MIME type of the inference body in the response. The default value is application/json .

type body

bytes or seekable file-like object

param body

[REQUIRED]

Inference input in the format specified by the content-type. To see the format and content of this field for different models, refer to Inference parameters .

type contentType

string

param contentType

The MIME type of the input data in the request. The default value is application/json .

type modelId

string

param modelId

[REQUIRED]

Id of the model to invoke using the streaming request.

rtype

dict

returns

The response of this operation contains an :class:`.EventStream` member. When iterated the :class:`.EventStream` will yield events based on the structure below, where only one of the top level keys will be present for any given event.

Response Syntax

{
    'body': EventStream({
        'chunk': {
            'bytes': b'bytes'
        },
        'internalServerException': {
            'message': 'string'
        },
        'modelStreamErrorException': {
            'message': 'string',
            'originalMessage': 'string',
            'originalStatusCode': 123
        },
        'throttlingException': {
            'message': 'string'
        },
        'validationException': {
            'message': 'string'
        }
    }),
    'contentType': 'string'
}

Response Structure

  • (dict) --

    • body (:class:`.EventStream`) --

      Inference response from the model in the format specified by Content-Type. To see the format and content of this field for different models, refer to Inference parameters .

      • chunk (dict) --

        Content included in the response.

        • bytes (bytes) --

          Base64-encoded bytes of payload data.

      • internalServerException (dict) --

        An internal server error occurred. Retry your request.

        • message (string) --

      • modelStreamErrorException (dict) --

        An error occurred while streaming the response.

        • message (string) --

        • originalMessage (string) --

          The original message.

        • originalStatusCode (integer) --

          The original status code.

      • throttlingException (dict) --

        The number of requests exceeds the limit. Resubmit your request later.

        • message (string) --

      • validationException (dict) --

        Input validation failed. Check your request parameters and retry the request.

        • message (string) --

    • contentType (string) --

      The MIME type of the inference result.