Skip to main content

openrouter-free-models - Find the best working free model on OpenRouter

Project description

openrouter-free-models

Find the best working free LLM model on OpenRouter.

Automatically tests available free models and returns the first one with available quota.

Installation

pip install openrouter-free-models

Requirements

Quick Start

from openrouter_free_models import get_best_free_model

# Get the best working free model
model = get_best_free_model(api_key="your_api_key")

# Access model information
print(model.name)              # 'google/gemini-flash-1.5'
print(model.context_length)    # 1000000
print(model.provider)          # 'google'
print(model.supports_tools)    # True

# Get all info as dictionary
info = model.to_dict()

Usage

Using convenience function

from openrouter_free_models import get_best_free_model

model = get_best_free_model(api_key="your_api_key")
print(f"Using: {model.name}")

Using FreeModel class directly

from free_router import FreeModel
from openrouter_free_models import FreeModel

model = FreeModel(api_key="your_api_key")
print(model.name)
print(model.context_length)

Environment variable

Set your API key as environment variable:

export OPENROUTER_API_KEY="your_api_key_here"
import os
from openrouter_free_models import get_best_free_model

model = get_best_free_model(api_key=os.environ['OPENROUTER_API_KEY'])

API Reference

get_best_free_model(api_key: str) -> FreeModel

Convenience function that returns a FreeModel instance with the best working model.

Parameters:

  • api_key (str): Your OpenRouter API key (required)

Returns: FreeModel instance

Raises: Exception if no working free model is found

FreeModel(api_key: str)

Main class for finding the best free model.

Parameters:

  • api_key (str): Your OpenRouter API key (required)

Properties:

  • name (str): Model identifier (e.g., 'google/gemini-flash-1.5')
  • context_length (int): Maximum context length in tokens
  • provider (str): Provider name (e.g., 'google', 'meta-llama')
  • supports_tools (bool): Whether model supports function calling

Methods:

  • to_dict() -> dict: Returns all model information as a dictionary

ModelInfo Object

Returned model information includes:

Attribute Type Description
name str Full model identifier
context_length int Context window size in tokens
provider str Provider (extracted from name)
supports_tools bool Function calling support

How It Works

  1. Fetches all free models from OpenRouter API
  2. Sorts them by context length (largest first)
  3. Tests each model with a tiny request to check for available quota
  4. Returns the first working model with quota
  5. Raises exception if no model has available quota

Example Output

>>> from openrouter_free_models import get_best_free_model
>>> model = get_best_free_model(api_key="sk-...")
🔍 Searching for free models on OpenRouter...
📋 Found 23 free models. Testing for available quota...
   [1/10] Testing google/gemini-flash-1.5...  No quota (402)
   [2/10] Testing meta-llama/llama-3-8b-instruct...  WORKING

>>> print(model.name)
meta-llama/llama-3-8b-instruct

>>> print(model.context_length)
8192

>>> print(model.to_dict())
{'name': 'meta-llama/llama-3-8b-instruct', 'context_length': 8192, 'provider': 'meta-llama', 'supports_tools': True}

Error Handling

try:
    model = get_best_free_model(api_key="your_key")
except Exception as e:
    print(f"Failed: {e}")
    # All free models have exhausted their quota
    # Try again later or use a paid model

License

MIT

Links

Contributing

Issues and pull requests are welcome.

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_free_models-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

openrouter_free_models-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file openrouter_free_models-0.1.0.tar.gz.

File metadata

File hashes

Hashes for openrouter_free_models-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c9fe83aea356f4d39610246a3238de97d02c3bd7eb006e570413ef249f47a15b
MD5 04938f8f4cfec2c5ecf4c6d364e54391
BLAKE2b-256 a04a777a03b45a5816c20dfa7a62dfba4d072d6245e7188020b4599c39579dbf

See more details on using hashes here.

File details

Details for the file openrouter_free_models-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openrouter_free_models-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3cfcfaebacd93432bcca47b9e218af96d4c221c2488855d3e17cacca6b05b81
MD5 e3e228da88e1322fcc372c6952006a58
BLAKE2b-256 3ed6c9b83088c0854ef84bf75533f1012d992c7428fd547724cb4d0887a56ee8

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