Skip to main content

Easy access to 100s of LLMs with a few lines of code (using Openrouter).

Project description

irouter

PyPI version PyPI downloads Python Version uv Ruff

irouter ("Intelligence Router") is a Python package with a simple interface to access 100s of LLMs with 2 lines of code.

Installation

  1. Install irouter from PyPI:
pip install irouter
  1. Create an account on OpenRouter and generate an API key.

3a. (recommended!) Set the OpenRouter API key as an environment variable:

export OPENROUTER_API_KEY=your_api_key

In this way you can use irouter objects like Call and Chat without have to pass an API key.

from irouter import Call
c = Call(model="moonshotai/kimi-k2:free")

3b. Alternatively, pass api_key to irouter objects like Call and Chat.

from irouter import Call
c = Call(model="moonshotai/kimi-k2:free", api_key="your_api_key")

Usage

Call

Call is the simplest interface to call one or more LLMs.

Single LLM

from irouter import Call
c = Call(model="moonshotai/kimi-k2:free")
c("Who are you?")
# "I'm Kimi, your AI friend from Moonshot AI. I'm here to chat, answer your questions, and help you out whenever you need it."

Multiple LLMs

from irouter import Call
c = Call(model=["moonshotai/kimi-k2:free", "google/gemini-2.0-flash-exp:free"])
c("Who are you?")
# {'moonshotai/kimi-k2:free': "I'm Kimi, your AI friend from Moonshot AI. I'm here to chat, answer your questions, and help you out whenever you need it.",
#  'google/gemini-2.0-flash-exp:free': 'I am a large language model, trained by Google.\n'}

Chat

Chat is an easy way to interface with one or more LLMs, while tracking message history and token usage.

Single LLM

from irouter import Chat
c = Chat(model="moonshotai/kimi-k2:free")
c("Who are you?")
print(c.history) # {'moonshotai/kimi-k2:free': [...]}
print(c.usage) # {'moonshotai/kimi-k2:free': {'prompt_tokens': 8, 'completion_tokens': 8, 'total_tokens': 16}}

Multiple LLMs

from irouter import Chat
c = Chat(model=["moonshotai/kimi-k2:free", "google/gemini-2.0-flash-exp:free"])
c("Who are you?")
print(c.history) 
# {'moonshotai/kimi-k2:free': [...], 
# 'google/gemini-2.0-flash-exp:free': [...]}
print(c.usage) 
# {'moonshotai/kimi-k2:free': {'prompt_tokens': 8, 'completion_tokens': 8, 'total_tokens': 16}, 
# 'google/gemini-2.0-flash-exp:free': {'prompt_tokens': 8, 'completion_tokens': 10, 'total_tokens': 18}}

Image

Both Call and Chat support images from image URLs or local images.

Adding images is as simple as providing a list of strings with:

  • text and/or
  • image URL(s) and/or
  • image path(s)

Make sure to select an LLM that supports image input, like gpt-4o-mini.

Example image
from irouter import Chat
ic = Chat("gpt-4o-mini")
# Image URL
ic(["https://www.petlandflorida.com/wp-content/uploads/2022/04/shutterstock_1290320698-1-scaled.jpg", 
    "What is in the image?"])
# or local image
# ic(["../assets/puppy.jpg", "What is in the image?"])
# Example output:
# The image shows a cute puppy, ..., The background is blurred, 
# with green hues suggesting an outdoors setting.

# Images are tracked in history
print(ic.history)
# [{'role': 'system', 'content': 'You are a helpful assistant.'}, 
#  {'role': 'user', 'content': [{'type': 'image_url', 'image_url':
#  {'url': '...'}}, {'type': 'text', 'text': 'What is in the image?'}]}, 
#  {'role': 'assistant', 'content': 'The image shows a cute puppy...'}]

For more information on Chat, check out the chat.ipynb notebook in the nbs folder.

PDF Support

Both Call and Chat support PDF processing from URLs or local files.

from irouter import Call
c = Call("moonshotai/kimi-k2:free")
pdf_url = "https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf"
c([pdf_url, "What is the main contribution of this paper?"])
# 'The main contribution of this paper is the introduction of the Transformer architecture...'

Audio Support

Some LLMs have native audio support. Simply pass a local filepath that points to a .mp3 or .wav file with the instruction as a list of strings.

from irouter import Call
c = Call("google/gemini-2.5-flash")
c(["../assets/bottles.mp3", "What do you hear?"])
# 'I hear the sound of a glass bottle being opened and closed...'

Multiple Modalities

Combine text, images, PDFs, and audio in a single request by simply passing a list of strings.

from irouter import Call
c = Call("google/gemini-2.5-flash")
c(["../assets/bottles.mp3", "../assets/puppy.jpg", "What do you hear and see?"])
# 'I hear sounds of glass and see a small, fluffy dog...'

Misc

get_all_models

You can easily get all 300+ models available with irouter using get_all_models.

from irouter.base import get_all_models
get_all_models()
# ['llm_provider1/model1', ... 'llm_providerx/modelx']

history_to_markdown

Convert chat history to markdown for easy display in Jupyter notebooks.

from irouter.base import history_to_markdown
history_to_markdown(c.history, ipython=True)

Credits

This project is built on top of the OpenRouter API infrastructure, which provides access to LLMs through a unified interface.

This project is inspired by Answer.AI's projects like cosette and claudette.

irouter generalizes this idea to support 100s of LLMs, which includes OpenAI and Anthropic models and more, thanks to OpenRouter's infrastructure.

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

irouter-0.1.2.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

irouter-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file irouter-0.1.2.tar.gz.

File metadata

  • Download URL: irouter-0.1.2.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for irouter-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9d91cf118ed465bc9e4aa95ee07fa0ffa75ca1cd289f84d9b31b484d06934156
MD5 89d16e51ae81b8c29bcc6822349413bd
BLAKE2b-256 ad259cb93be1e98d7c674d28d27376a7aada4278d66dce46c44883585ac5dff4

See more details on using hashes here.

File details

Details for the file irouter-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: irouter-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for irouter-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 263196a90ad8a5c81e2ad3b3a2039b7905d1c8bb82dbe9d0c98b536be1e66293
MD5 73cadac0d47b364afd98e00ac33a9682
BLAKE2b-256 e51febe198db21d91add172f2007941356a273062e2448dc2e2ee69bca194e63

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