Skip to main content

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

Contributing

Issues and pull requests are welcome.

Metadata

Release files for openrouter-free-models 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openrouter-free-models 0.1.0
File Size Uploaded Provenance Actions
openrouter_free_models-0.1.0.tar.gz 4.5 kB Without provenance Details for openrouter_free_models-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openrouter-free-models 0.1.0
File Interpreter ABI Platform Actions
openrouter_free_models-0.1.0-py3-none-any.whl Python 3 none any Details for openrouter_free_models-0.1.0-py3-none-any.whl

Total release size: 9.7 kB

Release files / openrouter_free_models-0.1.0.tar.gz

Download URL openrouter_free_models-0.1.0.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c9fe83aea356f4d39610246a3238de97d02c3bd7eb006e570413ef249f47a15b
BLAKE2b-256 checksum
How to use checksums
a04a777a03b45a5816c20dfa7a62dfba4d072d6245e7188020b4599c39579dbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Release files / openrouter_free_models-0.1.0-py3-none-any.whl

Download URL openrouter_free_models-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3cfcfaebacd93432bcca47b9e218af96d4c221c2488855d3e17cacca6b05b81
BLAKE2b-256 checksum
How to use checksums
3ed6c9b83088c0854ef84bf75533f1012d992c7428fd547724cb4d0887a56ee8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.20

Security for openrouter-free-models 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page