Easy access to 100s of LLMs with a few lines of code (using Openrouter).
Project description
irouter
Access 100s of LLMs with 2 lines of code.
Installation
- Install
irouterfrom PyPI:
pip install irouter
- 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'}
For more information on Call, check out the call.ipynb notebook in the nbs folder.
If you would like to track message history and token usage, use Chat.
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}}
For more information on Chat, check out the chat.ipynb notebook in the nbs folder.
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']
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file irouter-0.1.0.tar.gz.
File metadata
- Download URL: irouter-0.1.0.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c086a30cc0b63949ba3a7a176c5d933ba3da17f2c622110d8344d236d97328ea
|
|
| MD5 |
295fc9555b446e834ab301992332ed78
|
|
| BLAKE2b-256 |
ae21b7ac9a4b48f4e5094e34484670981fdb8513c6231bfceea943f27369c54c
|
File details
Details for the file irouter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: irouter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc18cb7306998f315c160c9c7f6a6df243e2a97c53a3e0cffe0317354efae19f
|
|
| MD5 |
eda4d3a038802ed2b592ed0ec61fa718
|
|
| BLAKE2b-256 |
f04b8e0c72f16774f314da586a8b2f257abbc8602b343b0707903fd3b0731b9f
|