Skip to content

BedrockRuntimeClient.invoke_model_with_response_stream

rboto-bedrock-runtime==0.4.0 · Service index · Types

Model summary (excerpt): Invoke the specified Amazon Bedrock model to run inference using the prompt and inference parameters provided in the request body. The response is returned in a stream. To see if a model supports streaming, call GetFoundationModel and check the responseStreamingSupported field in the response. The CLI doesn't support streaming operations in Amazon Bedrock, including...

Install and imports

python -m pip install "rboto[bedrock-runtime]==0.4.0"
from rboto import BedrockRuntimeClient
from rboto_bedrock_runtime.types import (
    InvokeModelWithResponseStreamOutput,
    PerformanceConfigLatency,
    ServiceTierType,
    Trace,
)

Signature

async def invoke_model_with_response_stream(
    *,
    model_id: str,
    body: bytes | None = None,
    content_type: str | None = None,
    accept: str | None = None,
    trace: Trace | None = None,
    guardrail_identifier: str | None = None,
    guardrail_version: str | None = None,
    performance_config_latency: PerformanceConfigLatency | None = None,
    service_tier: ServiceTierType | None = None,
    request_metadata: str | None = None,
    project_identifier: str | None = None,
) -> InvokeModelWithResponseStreamOutput: ...

Arguments without defaults are required. None omits an optional request argument. Static types do not validate resource existence, permissions, lengths, ranges, or conditional service requirements.

Arguments

Argument Required Model notes (excerpt)
model_id Yes The unique identifier of the model to invoke to run inference. The modelId to provide depends on the type of model or throughput that you use: If you use a base model, specify the model ID or its ARN. For a list of model IDs for base models, see Amazon Bedrock base model IDs (on-demand throughput) in the Amazon Bedrock User Guide. If you use an inference profile, specify the inference profile...
body No The prompt and inference parameters in the format specified in the contentType in the header. You must provide the body in JSON format. To see the format and content of the request and response bodies for different models, refer to Inference parameters . For more information, see Run inference in the Bedrock User Guide.
content_type No The MIME type of the input data in the request. You must specify application/json .
accept No The desired MIME type of the inference body in the response. The default value is application/json .
trace No Specifies whether to enable or disable the Bedrock trace. If enabled, you can see the full Bedrock trace.
guardrail_identifier No The unique identifier of the guardrail that you want to use. If you don't provide a value, no guardrail is applied to the invocation. An error is thrown in the following situations. You don't provide a guardrail identifier but you specify the amazon-bedrock-guardrailConfig field in the request body. You enable the guardrail but the contentType isn't application/json . You provide a guardrail...
guardrail_version No The version number for the guardrail. The value can also be DRAFT .
performance_config_latency No Model performance settings for the request.
service_tier No Specifies the processing tier type used for serving the request.
request_metadata No Key-value pairs that you can use to filter invocation logs.
project_identifier No The ID or Amazon Resource Name (ARN) of the project to use for this invocation. The project must be active and belong to your AWS account and the AWS Region to which you send the request. Specify default or omit this field to use the default project for your account. For a non-default project, the inference target must resolve to a foundation model or system-defined inference profile....

Output

InvokeModelWithResponseStreamOutput.

Typed response mapping, accessed as response["field"].

Field Type Presence References
body AsyncIterator[ResponseStream] Always present ResponseStream
content_type str Always present —
performance_config_latency PerformanceConfigLatencyOutput | None Always present PerformanceConfigLatencyOutput
service_tier ServiceTierTypeOutput | None Always present ServiceTierTypeOutput

| None means a value can be absent. Output mappings include every declared key; optional input keys may be omitted. Unknown output enum/union variants are not automatically valid inputs.

InvokeModelWithResponseStreamOutput, PerformanceConfigLatency, ServiceTierType, Trace

Follow these links for nested inputs and outputs; recursive types link back to the same type page.

Pagination and streaming

No generated paginator for this operation.

Output streams: InvokeModelWithResponseStreamOutput.

Consume with async for. Do not reuse a consumed stream.

Errors

Import from rboto_bedrock_runtime.exceptions:

AccessDeniedError, InternalServerError, ModelError, ModelNotReadyError, ModelStreamError, ModelTimeoutError, ResourceNotFoundError, ServiceQuotaExceededError, ServiceUnavailableError, ThrottlingError, ValidationError.

Stream decoding may also raise the linked modeled event errors.

Other service failures use the service base error; credential, transport and timeout failures use shared errors.

Service guide · Pinned model