AWS Bedrock — Example Configuration

Partial supportclient.send(new ConverseStreamCommand(...)) is instrumented for streaming calls. Input and output token counts are captured automatically from the stream metadata.

Setup

Import the ready-to-use converseStream method config from the Weflayr Bedrock provider:

const { weflayr_setup, weflayr_instrument } = require('weflayr');
const { converseStream } = require('weflayr/src/providers/bedrock-runtime');
const { BedrockRuntimeClient, ConverseStreamCommand } = require('@aws-sdk/client-bedrock-runtime');

weflayr_setup({
  intake_url:    process.env.WEFLAYR_INTAKE_URL,
  client_id:     process.env.WEFLAYR_CLIENT_ID,
  client_secret: process.env.WEFLAYR_CLIENT_SECRET,
  event_mode: 'default',
  methods: [converseStream],
});

const client = weflayr_instrument(new BedrockRuntimeClient({
  region: 'us-east-1',
  token: { token: process.env.AWS_BEARER_TOKEN_BEDROCK },
}));
import os
import boto3
from weflayr import weflayr_setup, weflayr_instrument

weflayr_setup({
    "intake_url":    os.environ["WEFLAYR_INTAKE_URL"],
    "client_id":     os.environ["WEFLAYR_CLIENT_ID"],
    "client_secret": os.environ["WEFLAYR_CLIENT_SECRET"],
    "event_mode":    "default",
    "methods":       [{"call": "converse_stream"}],
})

client = weflayr_instrument(boto3.client("bedrock-runtime", region_name="us-east-1"))

converseStream bundles the call, streamPath, and streamMiddleware for client.send(new ConverseStreamCommand(...)) so you don’t need to wire them manually.

Streaming call

const modelId = 'us.anthropic.claude-haiku-4-5-20251001-v1:0';

const response = await client.send(
  new ConverseStreamCommand({
    modelId,
    messages: [{ role: 'user', content: [{ text: 'Tell me a short story about a robot.' }] }],
    __weflayr_tags: {
      provider: 'bedrock',
      feature: 'chat',
      customer_id: 'acme-corp',
    },
  })
);

for await (const event of response.stream) {
  if (event.contentBlockDelta) {
    process.stdout.write(event.contentBlockDelta.delta?.text || '');
  }
}
model_id = "us.anthropic.claude-haiku-4-5-20251001-v1:0"

response = client.converse_stream(
    modelId=model_id,
    messages=[{"role": "user", "content": [{"text": "Tell me a short story about a robot."}]}],
    __weflayr_tags={
        "provider": "bedrock",
        "feature": "chat",
        "customer_id": "acme-corp",
    },
)

for event in response["stream"]:
    if "contentBlockDelta" in event:
        print(event["contentBlockDelta"]["delta"].get("text", ""), end="", flush=True)

Note that Bedrock’s ConverseStreamCommand uses a different message format than OpenAI: content is an array of objects ([{ text: '...' }]) rather than a plain string. The __weflayr_tags field is passed inside the command params and stripped before the request reaches Bedrock.

Configuration notes

Setting Value Reason
methods converseStream Pre-built config for ConverseStreamCommand; reads token counts from stream metadata
ignore_fields messages[].content[].text Strip prompt text; keep token usage and model metadata

What converseStream captures

Token counts are extracted from the metadata chunk emitted at the end of each Bedrock stream:

Field Source
model Command params (modelId)
input_tokens chunk.metadata.usage.inputTokens
output_tokens chunk.metadata.usage.outputTokens