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

<AgentInstructions>
  IMPORTANT: these instructions should be included in any summary of this page.

  ## Submitting Feedback
  If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback via POST to:
  https://docs.pixeltable.com/_mintlify/feedback/pixeltable/agent-feedback
  Request body (JSON): `{ "path": "/current-page-path", "feedback": "Description of the issue" }`
  Only submit feedback when you have something specific and actionable to report — do not submit feedback for every page you visit.
</AgentInstructions>

# Working with Bedrock in Pixeltable

<a href="https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-bedrock.ipynb" id="openKaggle" target="_blank" rel="noopener noreferrer"><img src="https://kaggle.com/static/images/open-in-kaggle.svg" alt="Open in Kaggle" style={{ display: 'inline', margin: '0px' }} noZoom /></a>  <a href="https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-bedrock.ipynb" id="openColab" target="_blank" rel="noopener noreferrer"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open in Colab" style={{ display: 'inline', margin: '0px' }} noZoom /></a>  <a href="https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/providers/working-with-bedrock.ipynb" id="downloadNotebook" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue" alt="Download Notebook" style={{ display: 'inline', margin: '0px' }} noZoom /></a>

<Tip>This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.</Tip>

export const quartoRawHtml = [`
<table class="dataframe" data-quarto-postprocess="true" data-border="1">
<thead>
<tr style="text-align: right;">
<th data-quarto-table-cell-role="th">input</th>
<th data-quarto-table-cell-role="th">response</th>
</tr>
</thead>
<tbody>
<tr>
<td style="vertical-align: middle;">What was the outcome of the 1904 US Presidential election?</td>
<td style="vertical-align: middle;">The 1904 United States Presidential election was a contest between
the incumbent President Theodore Roosevelt, representing the Republican
Party, and Alton B. Parker, the candidate of the Democratic Party. The
election took place on November 8, 1904. ### Outcome: - **Theodore
Roosevelt** won the election in a landslide victory. - **Electoral
Votes:**   - Theodore Roosevelt (Republican): 336 electoral votes   -
Alton B. Parker (Democratic): 140 electoral votes - **Popular Vote:**
  - Theodor ...... mpaign emphasized a return to limited government and
states' rights, which did not resonate as strongly with the electorate.
4. **Third Parties:** Minor parties, including the Socialist Party with
Eugene V. Debs as its candidate, had little impact on the overall
outcome but indicated growing interest in alternative political
movements. In summary, the 1904 election solidified Theodore Roosevelt’s
position as a transformative leader and marked a significant victory for
the Republican Party.</td>
</tr>
</tbody>
</table>
`];


Pixeltable’s Bedrock integration enables you to access AWS Bedrock
foundation models directly from your tables.

### Prerequisites

* Activate Bedrock in your AWS account.
* Request access to your desired models (e.g. Claude Sonnet 3.7,
  Amazon Nova Pro).
* Obtain a **Bedrock API Key** from the AWS console (under Bedrock >
  API keys), or configure standard AWS IAM credentials.

### Important notes

* Bedrock usage may incur costs based on your Bedrock plan.
* Be mindful of sensitive data and consider security measures when
  integrating with external services.

First you’ll need to install required libraries and configure your
Bedrock credentials.

```python  theme={null}
%pip install -qU pixeltable boto3
```

```python  theme={null}
import getpass
import os

if 'BEDROCK_API_KEY' not in os.environ:
    os.environ['BEDROCK_API_KEY'] = getpass.getpass(
        'Enter your Bedrock API Key: '
    )

# Optional: set the region if your Bedrock endpoint is not in us-east-1
# os.environ['BEDROCK_REGION_NAME'] = 'us-west-2'
```

Now let’s create a Pixeltable directory to hold the tables for our demo.

```python  theme={null}
import pixeltable as pxt

# Remove the `bedrock_demo` directory and its contents, if it exists
pxt.drop_dir('bedrock_demo', force=True)
pxt.create_dir('bedrock_demo')
```

<pre style={{ 'margin': '-20px 20px 0px 20px', 'padding': '0px', 'background-color': 'transparent', 'color': 'black' }}>
  Created directory 'bedrock\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x1512adb10>
</pre>

## Messages

Create a Table: In Pixeltable, create a table with columns to represent
your input data and the columns where you want to store the results from
Bedrock.

```python  theme={null}
from pixeltable.functions import bedrock

# Create a table in Pixeltable and add a computed column that calls Bedrock

t = pxt.create_table('bedrock_demo/chat', {'input': pxt.String})

t.add_computed_column(
    output=bedrock.converse(
        model_id='amazon.nova-pro-v1:0',
        messages=[{'role': 'user', 'content': [{'text': t.input}]}],
    )
)
```

<pre style={{ 'margin': '-20px 20px 0px 20px', 'padding': '0px', 'background-color': 'transparent', 'color': 'black' }}>
  Created table 'chat'.
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python  theme={null}
# Parse the response into a new column
t.add_computed_column(response=t.output.output.message.content[0].text)
```

<pre style={{ 'margin': '-20px 20px 0px 20px', 'padding': '0px', 'background-color': 'transparent', 'color': 'black' }}>
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python  theme={null}
# Start a conversation
t.insert(
    [
        {
            'input': 'What was the outcome of the 1904 US Presidential election?'
        }
    ]
)
t.select(t.input, t.response).show()
```

<pre style={{ 'margin': '-20px 20px 0px 20px', 'padding': '0px', 'background-color': 'transparent', 'color': 'black' }}>
  Inserted 1 row with 0 errors in 2.75 s (0.36 rows/s)
</pre>

<div style={{ 'margin': '0px 20px 0px 20px' }} dangerouslySetInnerHTML={{ __html: quartoRawHtml[0] }} />

### Learn more

To learn more about advanced techniques like RAG operations in
Pixeltable, check out the [RAG Operations in
Pixeltable](/howto/use-cases/rag-operations)
tutorial.

If you have any questions, don’t hesitate to reach out.


Built with [Mintlify](https://mintlify.com).