BedrockRuntimeClient.converse
rboto-bedrock-runtime==0.4.0 · Service index · Types
Model summary (excerpt): Sends messages to the specified Amazon Bedrock model. Converse provides a consistent interface that works with all models that support messages. This allows you to write code once and use it with different models. If a model has unique inference parameters, you can also pass those unique parameters to the model. Data retention for this request depends on the applicable account or project...
Install and imports
from rboto import BedrockRuntimeClient
from collections.abc import Sequence
from rboto_bedrock_runtime.types import (
ConverseOutput,
GuardrailConfiguration,
InferenceConfiguration,
JSONValue,
Message,
OutputConfig,
PerformanceConfiguration,
PromptVariableValues,
ServiceTier,
SystemContentBlock,
ToolConfiguration,
)
Signature
async def converse(
*,
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: GuardrailConfiguration | 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,
) -> ConverseOutput: ...
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 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
ConverseOutput.
Read-only native attributes, accessed as response.field. Collection getters materialize Python values; to_dict() recursively materializes a mapping. Streams are consumed once.
| Field | Type | Presence | References |
|---|---|---|---|
output |
ConverseValueOutput | None |
Always present | ConverseValueOutput |
stop_reason |
StopReasonOutput |
Always present | StopReasonOutput |
usage |
TokenUsageOutput | None |
Always present | TokenUsageOutput |
metrics |
ConverseMetricsOutput | None |
Always present | ConverseMetricsOutput |
additional_model_response_fields |
JSONValue | None |
Always present | JSONValue |
trace |
ConverseTraceOutput | None |
Always present | ConverseTraceOutput |
performance_config |
PerformanceConfigurationValueOutput | None |
Always present | PerformanceConfigurationValueOutput |
service_tier |
ServiceTierValueOutput | None |
Always present | ServiceTierValueOutput |
| 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.
Related types
ConverseOutput, GuardrailConfiguration, 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.
No output stream.
Errors
Import from rboto_bedrock_runtime.exceptions:
AccessDeniedError, InternalServerError, ModelError, ModelNotReadyError, ModelTimeoutError, ResourceNotFoundError, ServiceUnavailableError, ThrottlingError, ValidationError.
Other service failures use the service base error; credential, transport and timeout failures use shared errors.
Example
Complete, type-checked service example. Replace its placeholders and configure credentials before running it.
import asyncio
from rboto import BedrockRuntimeClient
from rboto_bedrock_runtime.types import Message
async def main() -> None:
client = BedrockRuntimeClient(region="us-east-1")
message: Message = {"role": "user", "content": [{"text": "Explain async I/O briefly."}]}
response = await client.converse(model_id="YOUR_MODEL_ID", messages=[message])
print(response.output)
print(response.usage)
if __name__ == "__main__":
asyncio.run(main())