Skip to content

BedrockRuntimeClient.converse_stream

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

Model summary (excerpt): Sends messages to the specified Amazon Bedrock model and returns the response in a stream. ConverseStream provides a consistent API that works with all Amazon Bedrock models that support messages. This allows you to write code once and use it with different models. Should a model have unique inference parameters, you can also pass those unique parameters to the model. To find out if a model...

Install and imports

python -m pip install "rboto[bedrock-runtime]==0.4.0"
from rboto import BedrockRuntimeClient
from collections.abc import Sequence
from rboto_bedrock_runtime.types import (
    ConverseStreamOutput,
    GuardrailStreamConfiguration,
    InferenceConfiguration,
    JSONValue,
    Message,
    OutputConfig,
    PerformanceConfiguration,
    PromptVariableValues,
    ServiceTier,
    SystemContentBlock,
    ToolConfiguration,
)

Signature

async def converse_stream(
    *,
    model_id: str,
    messages: Sequence[Message] | None = None,
    system: Sequence[SystemContentBlock] | None = None,
    inference_config: InferenceConfiguration | None = None,
    tool_config: ToolConfiguration | None = None,
    guardrail_config: GuardrailStreamConfiguration | None = None,
    project_identifier: str | None = None,
    additional_model_request_fields: JSONValue | None = None,
    prompt_variables: dict[str, PromptVariableValues] | None = None,
    additional_model_response_field_paths: Sequence[str] | None = None,
    request_metadata: dict[str, str] | None = None,
    performance_config: PerformanceConfiguration | None = None,
    service_tier: ServiceTier | None = None,
    output_config: OutputConfig | None = None,
) -> ConverseStreamOutput: ...

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 Specifies the model or throughput with which to run inference, or the prompt resource to use in inference. The value depends on the resource 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...
messages No The messages that you want to send to the model.
system No A prompt that provides instructions or context to the model about the task it should perform, or the persona it should adopt during the conversation.
inference_config No Inference parameters to pass to the model. Converse and ConverseStream support a base set of inference parameters. If you need to pass additional parameters that the model supports, use the additionalModelRequestFields request field.
tool_config No Configuration information for the tools that the model can use when generating a response. For information about models that support streaming tool use, see Supported models and model features .
guardrail_config No Configuration information for a guardrail that you want to use in the request. If you include guardContent blocks in the content field in the messages field, the guardrail operates only on those messages. If you include no guardContent blocks, the guardrail operates on all messages in the request body and in any included prompt resource.
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....
additional_model_request_fields No Additional inference parameters that the model supports, beyond the base set of inference parameters that Converse and ConverseStream support in the inferenceConfig field. For more information, see Model parameters .
prompt_variables No Contains a map of variables in a prompt from Prompt management to objects containing the values to fill in for them when running model invocation. This field is ignored if you don't specify a prompt resource in the modelId field.
additional_model_response_field_paths No Additional model parameters field paths to return in the response. Converse and ConverseStream return the requested fields as a JSON Pointer object in the additionalModelResponseFields field. The following is example JSON for additionalModelResponseFieldPaths . [ "/stop_sequence" ] For information about the JSON Pointer syntax, see the Internet Engineering Task Force (IETF) documentation....
request_metadata No Key-value pairs that you can use to filter invocation logs.
performance_config No Model performance settings for the request.
service_tier No Specifies the processing tier configuration used for serving the request.
output_config No Output configuration for a model response.

Output

ConverseStreamOutput.

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

Field Type Presence References
stream AsyncIterator[ConverseStreamEventOutput] Always present ConverseStreamEventOutput

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

ConverseStreamOutput, GuardrailStreamConfiguration, InferenceConfiguration, JSONValue, Message, OutputConfig, PerformanceConfiguration, PromptVariableValues, ServiceTier, SystemContentBlock, ToolConfiguration

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: ConverseStreamOutput.

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

Errors

Import from rboto_bedrock_runtime.exceptions:

AccessDeniedError, InternalServerError, ModelError, ModelNotReadyError, ModelStreamError, ModelTimeoutError, ResourceNotFoundError, 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