Working with OpenRouter in Pixeltable

Pixeltable's OpenRouter integration enables you to access multiple LLM providers through a unified API via OpenRouter.

Providers · Notebook · Updated

Colab runs it in your browser. If it calls a model provider, it asks for that provider's API key in a cell.

What it covers

  • Chat completions
  • Using different models
  • Advanced features: provider routing
  • Advanced Features: Context Window Optimization

What it uses

Install
terminal
pip install pixeltable openai
Environment variables it names
OPENROUTER_API_KEY
Pixeltable calls
openrouter.chat_completions()pxt.create_table()add_computed_column()insert()

A look at the code

working-with-openrouter.ipynb
from pixeltable.functions import openrouter
# Create a table in Pixeltable and add a computed column that calls OpenRouter
t = pxt.create_table('openrouter_demo/chat', {'input': pxt.String})
messages = [{'role': 'user', 'content': t.input}]
t.add_computed_column(
output=openrouter.chat_completions(
messages=messages,
model='anthropic/claude-sonnet-5.5',
model_kwargs={
# Optional dict with parameters compatible with the model
'max_tokens': 300,
'temperature': 0.7,
},
)
)

One cell of the notebook, copied as it is. Open it in Colab for the rest.

Browse all 103
  • Working with Pydantic in Pixeltable

    Pixeltable's Pydantic integration enables type-safe data insertion using Pydantic models. Instead of inserting raw dictionaries, you can define structured models with validation and insert them directly into Pixeltable tables.

    Updated Open in Colab
  • Working with Tigris in Pixeltable

    This tutorial demonstrates how to configure Pixeltable to use Tigris for storage. This lets you store unlimited amounts of images in Tigris' global data plane, allowing your images to load fast everywhere.

    Updated Open in Colab