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.
Pixeltable’s OpenRouter integration enables you to access multiple LLM
providers through a unified API via OpenRouter.
Prerequisites
Important notes
- OpenRouter usage may incur costs based on the models you use and your
usage volume.
- Be mindful of sensitive data and consider security measures when
integrating with external services.
First you’ll need to install required libraries and enter your
OpenRouter API key.
Now let’s create a Pixeltable directory to hold the tables for our demo.
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘openrouter_demo’.
<pixeltable.catalog.dir.Dir at 0x12e2fb710>
Chat completions
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
OpenRouter.
Created table ‘chat’.
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 2 rows with 0 errors in 7.59 s (0.26 rows/s)
Using different models
One of OpenRouter’s key benefits is easy access to models from multiple
providers. Let’s create a table that compares responses from Anthropic
Claude, OpenAI GPT-4, and Meta Llama.
Created table ‘compare_models’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 1 row with 0 errors in 1.27 s (0.79 rows/s)
Advanced features: provider routing
OpenRouter allows you to specify provider preferences for fallback
behavior and cost optimization.
Created table ‘routing’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 1 row with 0 errors in 3.97 s (0.25 rows/s)
Advanced Features: Context Window Optimization
OpenRouter supports transforms like ‘middle-out’ to optimize handling of
long contexts.
Created table ‘transforms’.
Added 0 column values with 0 errors in 0.01 s
Added 0 column values with 0 errors in 0.01 s
No rows affected.
Inserted 1 row with 0 errors in 1.82 s (0.55 rows/s)
Learn more
To learn more about advanced techniques like RAG operations in
Pixeltable, check out the RAG Operations in
Pixeltable
tutorial.
For more information about OpenRouter’s features and available models,
visit:
If you have any questions, don’t hesitate to reach out.