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

# AWS Bedrock

> Trace AWS Bedrock foundation model calls with Netra auto-instrumentation. Monitor prompts, completions, token usage, and latency across all models.

<img src="https://mintcdn.com/netra/u6ajHWd7ki_9CRWQ/images/integration-logos/llm-providers/amazon-bedrock.png?fit=max&auto=format&n=u6ajHWd7ki_9CRWQ&q=85&s=e69a1516ebc1927d172d40227d37db4d" alt="AWS Bedrock" width="239" height="80" data-path="images/integration-logos/llm-providers/amazon-bedrock.png" />

## Installation

Install the Netra SDK along with the AWS SDK for Bedrock:

<CodeGroup>
  ```bash Python theme={null}
  pip install netra-sdk boto3
  ```

  ```bash TypeScript theme={null}
  npm install netra-sdk @aws-sdk/client-bedrock-runtime
  ```
</CodeGroup>

## Usage

Netra SDK automatically instruments AWS Bedrock calls when you enable the `botocore` instrumentation. This captures traces for all Bedrock API calls including model invocations, streaming responses, and embeddings.

## Basic Setup

Initialize Netra with Bedrock instrumentation enabled:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  import boto3
  import os

  # Initialize Netra SDK
  Netra.init(
      headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
      app_name="bedrock-app"
  )

  # Create Bedrock client - automatically instrumented
  bedrock = boto3.client(
      service_name='bedrock-runtime',
      region_name='us-east-1'
  )

  # Make Bedrock calls - automatically traced
  response = bedrock.invoke_model(
      modelId='anthropic.claude-v2',
      body='{"prompt": "Hello, world!"}'
  )
  ```

  ```typescript TypeScript theme={null}
  import { Netra } from "netra-sdk";
  import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime";

  // Initialize Netra SDK (must await)
  await Netra.init({
      headers: `x-api-key=${process.env.NETRA_API_KEY}`,
      appName: "bedrock-app"
  });

  // Create Bedrock client - automatically instrumented
  const client = new BedrockRuntimeClient({
      region: "us-east-1"
  });

  // Make Bedrock calls - automatically traced
  const command = new InvokeModelCommand({
      modelId: "anthropic.claude-v2",
      body: JSON.stringify({ prompt: "Hello, world!" })
  });

  const response = await client.send(command);
  ```
</CodeGroup>

## Model Invocation

The SDK automatically captures model invocations with full request and response details:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  import boto3
  import json
  import os

  Netra.init(headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}")

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

  # Text generation
  response = bedrock.invoke_model(
      modelId='anthropic.claude-v2',
      body=json.dumps({
          "prompt": "Explain AI observability",
          "max_tokens_to_sample": 300
      })
  )
  ```

  ```typescript TypeScript theme={null}
  import { Netra } from "netra-sdk";
  import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime";

  await Netra.init({
      headers: `x-api-key=${process.env.NETRA_API_KEY}`
  });

  const client = new BedrockRuntimeClient({ region: "us-east-1" });

  const command = new InvokeModelCommand({
      modelId: "anthropic.claude-v2",
      body: JSON.stringify({
          prompt: "Explain AI observability",
          max_tokens_to_sample: 300
      })
  });

  await client.send(command);
  ```
</CodeGroup>

## Streaming Responses

Bedrock streaming responses are automatically traced with full visibility:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  import boto3
  import json
  import os

  Netra.init(headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}")

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

  response = bedrock.invoke_model_with_response_stream(
      modelId='anthropic.claude-v2',
      body=json.dumps({
          "prompt": "Write a story",
          "max_tokens_to_sample": 500
      })
  )

  # Stream automatically traced
  for event in response['body']:
      chunk = json.loads(event['chunk']['bytes'])
      print(chunk.get('completion', ''))
  ```

  ```typescript TypeScript theme={null}
  import { Netra } from "netra-sdk";
  import { BedrockRuntimeClient, InvokeModelWithResponseStreamCommand } from "@aws-sdk/client-bedrock-runtime";

  await Netra.init({
      headers: `x-api-key=${process.env.NETRA_API_KEY}`
  });

  const client = new BedrockRuntimeClient({ region: "us-east-1" });

  const command = new InvokeModelWithResponseStreamCommand({
      modelId: "anthropic.claude-v2",
      body: JSON.stringify({
          prompt: "Write a story",
          max_tokens_to_sample: 500
      })
  });

  const response = await client.send(command);

  // Stream automatically traced
  for await (const event of response.body) {
      console.log(event.chunk?.bytes);
  }
  ```
</CodeGroup>

## Session Tracking

Track user sessions and conversations with Bedrock models:

<CodeGroup>
  ```python Python theme={null}
  from netra import Netra
  import boto3
  import json

  Netra.init(api_key="your-api-key")
  Netra.set_session_id("session-123")
  Netra.set_user_id("user-456")

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

  # All calls automatically tagged with session context
  response = bedrock.invoke_model(
      modelId='anthropic.claude-v2',
      body=json.dumps({"prompt": "Hello"})
  )
  ```

  ```typescript TypeScript theme={null}
  import { Netra } from "netra-sdk";
  import { BedrockRuntimeClient, InvokeModelCommand } from "@aws-sdk/client-bedrock-runtime";

  await Netra.init({
      headers: `x-api-key=${process.env.NETRA_API_KEY}`
  });

  Netra.setSessionId("session-123");
  Netra.setUserId("user-456");

  const client = new BedrockRuntimeClient({ region: "us-east-1" });

  // All calls automatically tagged with session context
  const command = new InvokeModelCommand({
      modelId: "anthropic.claude-v2",
      body: JSON.stringify({ prompt: "Hello" })
  });

  await client.send(command);
  ```
</CodeGroup>

# Next Steps

* [Getting Started with AWS Bedrock](https://aws.amazon.com/bedrock/getting-started/)
* [Auto-Instrumentation Guide](https://docs.getnetra.ai/tracing/auto-instrumentation)
* [Session Tracking](https://docs.getnetra.ai/tracing/session)
* [Advanced Configuration](https://docs.getnetra.ai/tracing/advanced-config/programatic-config)
