---
title: "Anthropic Integration with Pixeltable: Claude as Computed Columns"
description: "Run Anthropic Claude as a Pixeltable computed column. messages() on insert, cached per row, with the official SDK behind one import."
tool: "Anthropic"
keywords:
  - Anthropic Pixeltable integration
  - Claude Python pipeline
  - Anthropic messages API
  - Claude computed column
  - Claude Haiku Pixeltable
url: "https://www.pixeltable.com/integrations/anthropic"
---

# Anthropic Integration with Pixeltable: Claude as Computed Columns

Run Anthropic Claude as a Pixeltable computed column. messages() on insert, cached per row, with the official SDK behind one import.

## The Problem

Calling Anthropic from an application usually means a client, a retry loop, and a place to store the completion. The Messages API is well specified, but the surrounding work is not: you persist the prompt, you persist the model name, you persist the text that came back, and you decide when to call again if the prompt changes. A worker that loops rows and writes JSON into a second table will re-call Claude for rows that did not change unless you add your own cache key. Rate limits then land in that worker too. Pixeltable already has a table. The missing piece is treating the Anthropic call as a column of that table, not a side effect of a job.

## The Solution

Pixeltable ships pixeltable.functions.anthropic.messages as a UDF. On a TableModel you assign it to a computed field. Insert a row and that expression runs. Unchanged rows keep the cached Message object. The package throttles from the rate-limit headers Anthropic returns, so you do not configure a token bucket. Set ANTHROPIC_API_KEY, or the [anthropic] section of the Pixeltable config file. pip install anthropic is required. The documented notebook uses create_table and add_computed_column; an application file uses the same UDF as a class assignment and pxt schema update.

## Implementation

### Install and set the API key

Install Pixeltable plus the Anthropic SDK, then export ANTHROPIC_API_KEY.

```python
# pip install -U 'pixeltable[serve]' anthropic
# export ANTHROPIC_API_KEY=...
# pxt init

import pixeltable as pxt
from pixeltable.functions.anthropic import messages

TableModel = pxt.model_base()
```

The UDF requires the anthropic package. The key can also live in $PIXELTABLE_HOME/config.toml under [anthropic]. Do not put the key in app.py.


### Assign messages() on the class

Store the prompt, call Claude, and cache the text of the first content block.

```python
class Notes(TableModel, name='notes'):
    prompt: pxt.String
    output = messages(
        messages=[{'role': 'user', 'content': prompt}],
        model='claude-haiku-4-5-20251001',
        max_tokens=300,
        model_kwargs={
            'system': 'Respond with detailed historical information.',
        },
    )
    response = output.content[0].text

# pxt schema update app.py claude_notes -f
```

messages() returns the Anthropic Message object. content[0].text is the first text block. model_kwargs passes optional Messages API fields such as system. After schema update, insert a prompt and both columns fill for that row.


### Insert a row and read the cached reply

Insert runs Claude for that row only. Select the stored prompt and the parsed text.

```python
notes = pxt.get_table('claude_notes.notes')
notes.insert([
    {'prompt': 'What was the outcome of the 1904 US Presidential election?'},
])
notes.select(notes.prompt, notes.response).collect()
```

get_table uses the app name from schema update plus the class name. A second insert of a different prompt does not recompute the first row. Edit the prompt and dependents of that row run again.


### Optional tools on the same column

Pass Pixeltable tools into messages() when the model should call a function.

```python
@pxt.udf
def get_weather(city: str) -> str:
    return f'Weather in {city}: 72F, sunny'

tools = pxt.tools(get_weather)

class Assistant(TableModel, name='assistant'):
    message: pxt.String
    output = messages(
        messages=[{'role': 'user', 'content': message}],
        model='claude-haiku-4-5-20251001',
        max_tokens=300,
        tools=tools,
    )

# pxt schema update app.py claude_tools -f
```

tools is an optional argument on messages(). Tool choice and extra Messages API fields go in model_kwargs. See the Anthropic SDK page for invoke_tools when you want a second column that runs the tool result.


## Anthropic client in a worker versus a computed column

| Job | Client in a worker | messages() column |
| --- | --- | --- |
| You write | A loop that posts Messages and stores JSON | An assignment on TableModel |
| Runs when | The job ticks or a queue pops | The row or a dependency changes |
| Cache | A key you invent | The column on that row |
| Throttling | A limiter you configure | Headers Anthropic already returns |

## Benefits

- No Messages API wrapper around the official client
- Per-row cache: unchanged prompts do not call Claude again
- Adaptive throttling from Anthropic rate-limit headers
- system and other Messages fields stay in model_kwargs
- Same column shape locally and on Pixeltable Cloud

## Use Cases

- Summarize or classify stored text with Claude
- Draft replies that must stay attached to the source row
- Historical or research Q and A over a prompt column
- Tool-calling assistants whose outputs are queryable
- Batch labeling where only new rows should hit the API

## Performance


| Metric | Value | Description |

| --- | --- | --- |

| Client wrapper | None | messages() is the computed column; the SDK is a dependency, not an extra service |

| Recompute | Changed rows only | Insert and prompt edits run Claude for those rows; the rest stay cached |

| Rate limits | Header-based | The UDF throttles from Anthropic request and token capacity headers |

## Requirements

- Python 3.11+
- pip install -U 'pixeltable[serve]' anthropic
- ANTHROPIC_API_KEY with access to the chosen Claude model
- pxt init in the project root before pxt schema update

## Resources

- [Working with Anthropic](https://docs.pixeltable.com/howto/providers/working-with-anthropic) - Official Pixeltable notebook for messages()
- [Anthropic functions SDK](https://docs.pixeltable.com/sdk/latest/anthropic) - messages() and invoke_tools() reference
- [Claude and Anthropic in Pixeltable](https://www.pixeltable.com/blog/claude-anthropic-multimodal-integration-pixeltable) - Product write-up of the multimodal path