module pixeltable.functions.openrouter
Pixeltable UDFs that wrap the OpenRouter API.
OpenRouter provides a unified interface to multiple LLM providers. In order to use it,
you must first sign up at https://openrouter.ai, create an API key, and configure it
as described in the Working with OpenRouter tutorial.
udf chat_completions()
Chat Completion API via OpenRouter.
OpenRouter provides access to multiple LLM providers through a unified API.
For additional details, see: https://openrouter.ai/docs
Supported models can be found at: https://openrouter.ai/models
Request throttling:
Applies the rate limit set in the config (section openrouter, key rate_limit). If no rate
limit is configured, uses a default of 600 RPM.
Requirements:
Parameters:
messages (Json): A list of messages comprising the conversation so far.
model (String): ID of the model to use (e.g., 'anthropic/claude-3.5-sonnet', 'openai/gpt-4').
model_kwargs (Json | None): Additional OpenAI-compatible parameters.
tools (Json | None): List of tools available to the model.
tool_choice (Json | None): Controls which (if any) tool is called by the model.
provider (Json | None): OpenRouter-specific provider preferences (e.g., {'order': ['Anthropic', 'OpenAI']}).
transforms (Json | None): List of message transforms to apply (e.g., ['middle-out']).
Returns:
Json: A dictionary containing the response in OpenAI format.
Examples:
Basic chat completion:
With provider routing:
With transforms:
Last modified on January 15, 2026