> ## Documentation Index
> Fetch the complete documentation index at: https://docs.promptlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Bedrock

> Automatically trace supported direct Amazon Bedrock Runtime calls made with Boto3 or AWS SDK v3.

PromptLayer can auto-instrument Amazon Bedrock Runtime calls made with Boto3 or AWS SDK v3 and export supported operations as OpenTelemetry spans. Each supported direct Bedrock call appears in PromptLayer as both a trace span and an associated request log without replacing the native AWS client.

<Note>
  This integration covers direct Boto3 `bedrock-runtime` calls in Python and `@aws-sdk/client-bedrock-runtime` calls in JavaScript. It does not instrument `aioboto3` or the separate Anthropic Bedrock client.
</Note>

## Supported APIs

| API surface           | Python                                                      | JavaScript                    |
| --------------------- | ----------------------------------------------------------- | ----------------------------- |
| Converse              | Supported (`client.converse(...)`)                          | Supported (`ConverseCommand`) |
| Converse streaming    | Supported (`client.converse_stream(...)`)                   | Not supported                 |
| InvokeModel           | Supported (`client.invoke_model(...)`)                      | Not supported                 |
| InvokeModel streaming | Supported (`client.invoke_model_with_response_stream(...)`) | Not supported                 |

Only the language-specific surfaces in this table receive Bedrock-specific PromptLayer request log enrichment. In Python, consume or close a streaming response before flushing so its span can finish.

<Warning>
  Bedrock auto-instrumentation uses the general OpenTelemetry Botocore or AWS SDK instrumentor. Enabling it can also trace other AWS SDK service calls made by the same process, although Bedrock-specific request log enrichment applies only to the supported Bedrock Runtime operations.
</Warning>

## Prerequisites

* A [PromptLayer API key](/quickstart#prerequisites) for the workspace that should receive the traces
* AWS credentials, a region, and access to the Bedrock model or inference profile your application calls
* Python 3.10 or later for Python, or Node.js 20 or later for JavaScript

Export the PromptLayer API key before the application starts. The example below also uses `AWS_REGION` and `AWS_BEDROCK_MODEL` as application configuration:

```bash theme={null}
export PROMPTLAYER_API_KEY="pl_..."
export AWS_REGION="us-east-1"
export AWS_BEDROCK_MODEL="your-model-or-inference-profile-id"
```

PromptLayer captures supported Bedrock message content by default. Review [Capture Prompts and Responses](#capture-prompts-and-responses) before sending provider requests.

## Python

### 1. Install the SDKs

```bash theme={null}
pip install "promptlayer[otel-genai-instrumentation]" boto3
```

### 2. Configure Bedrock instrumentation

Configure tracing before creating the Bedrock Runtime client or making the first request:

```python theme={null}
import os

import boto3
from promptlayer import configure_tracing

tracer_provider = configure_tracing(providers=("bedrock",))
client = boto3.client(
    "bedrock-runtime",
    region_name=os.environ["AWS_REGION"],
)

try:
    response = client.converse(
        modelId=os.environ["AWS_BEDROCK_MODEL"],
        messages=[
            {
                "role": "user",
                "content": [
                    {"text": "Explain distributed tracing in one sentence."}
                ],
            }
        ],
        inferenceConfig={"maxTokens": 128},
    )
    print(response["output"]["message"]["content"][0]["text"])
finally:
    client.close()
    tracer_provider.force_flush()
```

The canonical selector is `bedrock`. Python also accepts `amazon.bedrock` and `aws.bedrock` as aliases for the same Botocore instrumentor.

<Accordion title="Use an existing Python PromptLayer client">
  If your application already creates a PromptLayer client, select Bedrock when enabling tracing:

  ```python theme={null}
  import boto3
  from promptlayer import PromptLayer

  pl = PromptLayer(
      enable_tracing=True,
      tracing_providers=("bedrock",),
  )
  client = boto3.client("bedrock-runtime", region_name="us-east-1")
  ```

  Omit `tracing_providers` to instrument every supported provider SDK that is installed.
</Accordion>

## JavaScript

### 1. Install the SDKs

```bash theme={null}
npm install promptlayer @aws-sdk/client-bedrock-runtime
```

### 2. Preload PromptLayer instrumentation

The preload must run before the application imports the AWS SDK client:

```bash theme={null}
node --import promptlayer/register app.mjs
```

### 3. Use the AWS SDK normally

```javascript theme={null}
import {
  BedrockRuntimeClient,
  ConverseCommand,
} from "@aws-sdk/client-bedrock-runtime";
import { shutdownTracing } from "promptlayer";

const client = new BedrockRuntimeClient({
  region: process.env.AWS_REGION,
});

try {
  const response = await client.send(
    new ConverseCommand({
      modelId: process.env.AWS_BEDROCK_MODEL,
      messages: [
        {
          role: "user",
          content: [
            { text: "Explain distributed tracing in one sentence." },
          ],
        },
      ],
      inferenceConfig: { maxTokens: 128 },
    }),
  );
  console.log(
    response.output?.message?.content
      ?.map((block) => block.text ?? "")
      .join(""),
  );
} finally {
  client.destroy();
  await shutdownTracing();
}
```

The preload instruments every supported provider. To instrument only Bedrock, call `configureTracing({ providers: ["bedrock"] })` in a bootstrap module and dynamically import the application afterward. See [Select Providers](/features/observability/traces/auto-instrumentation/overview#select-providers).

## Capture Prompts and Responses

PromptLayer captures supported Bedrock request and response content by default. To export metadata-only telemetry, opt out before tracing is configured:

<CodeGroup>
  ```bash Python theme={null}
  export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT="NO_CONTENT"
  ```

  ```bash JavaScript theme={null}
  export OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT="false"
  ```
</CodeGroup>

JavaScript can instead pass `captureContent: false` to `configureTracing()`.

Content coverage differs by Bedrock Runtime operation:

| Operation                             | Python content                                                                   | JavaScript content                                              |
| ------------------------------------- | -------------------------------------------------------------------------------- | --------------------------------------------------------------- |
| Converse                              | Request messages, system instructions, and the response message                  | Request messages, system instructions, and the response message |
| Converse streaming                    | Request messages and system instructions; streamed response content is not added | Not instrumented                                                |
| InvokeModel and InvokeModel streaming | Request and response bodies are not added                                        | Not instrumented                                                |

All supported operations still include non-content telemetry supplied by the instrumentor, such as the model, timing, token usage when available, and errors.

<Warning>
  Content capture can send user messages, model responses, system instructions, tool arguments and results, and other application data to PromptLayer. Because it is enabled by default, review your privacy, retention, and compliance requirements and opt out before the first Bedrock request when necessary.
</Warning>

## Verify the Integration

Run one supported Bedrock Runtime request, consume any Python response stream, flush or shut down tracing, and open [Traces](/features/observability/traces) in PromptLayer. The Bedrock span should have an associated request log and identify the Converse or InvokeModel API.

If no span appears:

* Confirm instrumentation is configured before the first Bedrock Runtime request.
* Confirm the client and operation are listed for your language in [Supported APIs](#supported-apis).
* In JavaScript, confirm the preload or bootstrap runs before `@aws-sdk/client-bedrock-runtime` loads.
* Confirm `PROMPTLAYER_API_KEY` belongs to the workspace you are checking.
* For Python streaming calls, fully consume or close the stream before flushing.
* Flush tracing before a short-lived process exits.
* If only message content is missing, confirm content capture was not disabled, check the operation-specific coverage above, and restart the process after changing the setting.
