Bedrock
bedrock
LLMeter targets for testing the Amazon Bedrock Converse and ConverseStream APIs
Alternatively, see:
- bedrock_invoke for testing Bedrock InvokeModel and InvokeModelWithResponseStream APIs, or
- openai for testing OpenAI-compatible endpoints from Bedrock Mantle
BedrockBase
BedrockBase(model_id, endpoint_name=None, region=None, inference_config=None, bedrock_boto3_client=None, max_attempts=3)
Bases: Endpoint[TBedrockConverseResponseBase], Generic[TBedrockConverseResponseBase]
Base class for interacting with Amazon Bedrock endpoints.
This class provides core functionality for making requests to Amazon Bedrock endpoints, handling configuration and client initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
The identifier for the model to use |
required |
endpoint_name
|
str | None
|
Name of the endpoint. Defaults to None. |
None
|
region
|
str | None
|
AWS region to use. Defaults to None. |
None
|
inference_config
|
dict | None
|
Configuration for inference. Defaults to None. |
None
|
bedrock_boto3_client
|
client
|
Pre-configured boto3 client. Defaults to None. |
None
|
max_attempts
|
int
|
Maximum number of retry attempts. Defaults to 3. |
3
|
Source code in llmeter/endpoints/bedrock.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
create_payload
staticmethod
create_payload(user_message, max_tokens=None, **kwargs)
Create a payload for the Bedrock Converse API request with optional multi-modal content.
⚠️ SECURITY WARNING: Format detection is for testing/development convenience ONLY. This method does NOT validate file safety, integrity, or protect against malicious content. DO NOT use with untrusted files (user uploads, external sources) without proper validation, sanitization, and security measures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_message
|
str | list[ContentItem]
|
A single text string, or an ordered list mixing strings
and :class: |
required |
max_tokens
|
int | None
|
Maximum number of tokens to generate. Defaults to 256. |
None
|
**kwargs
|
Any
|
Additional keyword arguments to include in the payload. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The formatted payload for the Bedrock API request. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If parameters have invalid types. |
ValueError
|
If parameters have invalid values. |
Examples:
Text only::
create_payload("Hello")
Image with text (order preserved)::
create_payload([
ImageContent.from_path("photo.jpg"),
"What's in this image?",
])
Mixed content::
create_payload([
"Compare the chart with the report:",
ImageContent.from_path("chart.png"),
DocumentContent.from_path("report.pdf"),
])
Source code in llmeter/endpoints/bedrock.py
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 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
prepare_payload
prepare_payload(payload)
Enforce required properties on the input to Bedrock Converse* APIs
In particular, ensure modelId is set in line with this Endpoint's configured model ID
and apply self._inference_config if no config was explicitly set on the payload.
Source code in llmeter/endpoints/bedrock.py
304 305 306 307 308 309 310 311 312 313 314 | |
BedrockConverse
BedrockConverse(model_id, endpoint_name=None, region=None, inference_config=None, bedrock_boto3_client=None, max_attempts=3)
Bases: BedrockBase[ConverseResponseTypeDef]
Source code in llmeter/endpoints/bedrock.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
invoke
invoke(payload)
Invoke the Bedrock converse API with the given payload.
Source code in llmeter/endpoints/bedrock.py
318 319 320 321 322 | |
process_raw_response
process_raw_response(raw_response, start_t, response)
Parse the response from a Bedrock converse API call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
InvocationResponse
|
Raw response from the Bedrock API. |
required |
start_t
|
float
|
The timestamp when the request was initiated. |
required |
Returns:
| Type | Description |
|---|---|
None
|
InvocationResponse with the generated text and metadata. |
Source code in llmeter/endpoints/bedrock.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
BedrockConverseStream
BedrockConverseStream(model_id, endpoint_name=None, region=None, inference_config=None, bedrock_boto3_client=None, max_attempts=3, ttft_visible_tokens_only=True)
Bases: BedrockBase[ConverseStreamResponseTypeDef]
Streaming endpoint for the Bedrock Converse API.
When extended thinking is enabled, the stream contains reasoningContent deltas before the
visible text deltas. The ttft_visible_tokens_only parameter controls which delta sets
time_to_first_token:
True(default) - TTFT is set on the firsttextdelta. Reasoning deltas are ignored for timing.False- TTFT is set on the first delta of any kind, including reasoning content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
Bedrock model identifier. |
required |
endpoint_name
|
str | None
|
Display name. Defaults to |
None
|
region
|
str | None
|
AWS region. Defaults to |
None
|
inference_config
|
dict | None
|
Default inference configuration. |
None
|
bedrock_boto3_client
|
Pre-configured boto3 client. |
None
|
|
max_attempts
|
int
|
Maximum retry attempts. Defaults to 3. |
3
|
ttft_visible_tokens_only
|
bool
|
When |
True
|
Source code in llmeter/endpoints/bedrock.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
process_raw_response
process_raw_response(raw_response, start_t, response)
Parse the streaming response from a Bedrock ConverseStream API call.
Only text deltas contribute to response_text. reasoningContent deltas are used solely
for TTFT measurement when ttft_visible_tokens_only is False.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_response
|
The raw response from the Bedrock API. |
required | |
start_t
|
float
|
The timestamp when the request was initiated. |
required |
response
|
InvocationResponse
|
The output response object to be updated in-place. |
required |
Source code in llmeter/endpoints/bedrock.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 | |