Skip to main content

A CLI tool to fetch, filter, and sort models from the OpenRouter API.

Project description

OpenRouter Model Filter

openrouter_model_filter is a command-line tool designed to fetch, filter, and sort models from the OpenRouter API.

The primary idea behind this tool was to make it easy to identify and use the best currently available free models on OpenRouter. However, its filtering capabilities are flexible and can be adapted for various other criteria and use cases beyond just free models.

Installation

pip install openrouter-model-filter

Usage

No API keys are required to use this tool as it only fetches publicly available model information.

By default, openrouter_model_filter fetches models, keeps those tagged as :free, removes common base, instruct, or math specific models (which are often less suitable for general chat), sorts them by context length (descending), and returns a newline-separated list of model IDs. This sorting order generally places models with larger context windows, often the most recent or "frontier-like" ones, at the top of the list.

You can customize the behavior using various command-line options:

openrouter_model_filter --help

Example with llm by Simon Willison

This tool was initially created to be integrated with Simon Willison's llm tool. The following command demonstrates how to use openrouter_model_filter to select one of the top 5 free models at random and then use it with llm:

llm --model "openrouter/$(openrouter_model_filter --n 5 | shuf | head -n 1)" "Hi, please tell me which model you are and what company made you."

Note: When using models via OpenRouter, you often need to explicitly agree to their terms, which may include allowing your prompts to be used for training by the model providers. Please check the OpenRouter documentation and model-specific terms.

Filtering Options

  • --n: Number of models to return (-1 for all).
  • --return-format: Output format (dict, json, str). Default is str.
  • --keep-regexes: Comma-separated regexes. Models matching ALL regexes are kept. Default is .*:free.
  • --remove-regexes: Comma-separated regexes. Models matching ANY regex are removed. Default is .*\bbase\b.*,.*\binstruct\b.*,.*\bmath\b. Pass "" for no removal.
  • --sort-key: Key to sort models by (e.g., context_length, name). Default is context_length. Pass "" for no sorting.

For example, to get the top 3 free models sorted by name:

openrouter_model_filter --n 3 --sort-key name

To get all models that are not free, in JSON format, without sorting:

openrouter_model_filter --keep-regexes ".*" --remove-regexes ".*:free" --return-format json --sort-key ""

Development

This project uses click for the CLI and requests for API interaction.

Further development and contributions are welcome!


This project was developed with assistance from aider.chat.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openrouter_model_filter-1.0.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openrouter_model_filter-1.0.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file openrouter_model_filter-1.0.0.tar.gz.

File metadata

  • Download URL: openrouter_model_filter-1.0.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for openrouter_model_filter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 07829afdc209ff334253516404e3e217c9a1981cc7f1471074033c86ee35fb39
MD5 a4ad4bc25549193568add76ddcdb3446
BLAKE2b-256 7552da6b3ffcd64e9bfa2d3966c73c4f9d49f7b3e68c8ccd813a49d0df331518

See more details on using hashes here.

File details

Details for the file openrouter_model_filter-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openrouter_model_filter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 971b0573e2fa61b630de98c24d3f57fa41dc91bd97eaffb43d6dc78d7e3acbea
MD5 05094f95251228d0fd591551d4f2398e
BLAKE2b-256 4af236e0af3a40e5b544f698db5ce53a2be3f7e81b5dbbbd4a5cd24351781bb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page