This is an unofficial wrapper of OpenRouter.
Project description
OpenRouter Provider
An unofficial Python wrapper for the OpenRouter API that provides a simple, intuitive interface for interacting with multiple LLM models. OpenRouter Provider supports chat conversations, image processing, tool integration, streaming responses, and structured output generation.
Features
- Conversation Memory: Automatic chat history management with easy memory control
- Image Processing: Built-in image resizing and base64 encoding for multimodal interactions
- Tool Integration: Decorator-based function calling with automatic tool execution
- Streaming Support: Real-time response streaming for both sync and async operations
- Structured Output: JSON schema-based response formatting using Pydantic models
- Async Support: Full async/await support for non-blocking operations
- Provider Configuration: You can select your favorite provoder easily
Quick start
Installation
pip install openrouter-provider
Set API key
Please get your API key from OpenRouter and set it as environment valuable.
OPENROUTER_API_KEY="your-api-key-here"
Basic Usage
from openrouter import *
from dotenv import load_dotenv
load_dotenv()
client = OpenRouterClient(system_prompt="You are a friendly AI assistant.")
model = LLMModel(name="openai/gpt-5")
query = Message(text="Hello, how are you?")
reply = client.invoke(model=model, query=query)
print(reply.text)
OpenAI-Compatible Endpoints
from openrouter import *
client = OpenRouterClient(
system_prompt="You are a helpful assistant.",
base_url="http://localhost:11434/v1",
)
model = LLMModel(name="llama3.1")
query = Message(text="Hello, how are you?")
reply = client.invoke(model=model, query=query)
print(reply.text)
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 openrouter_provider-1.0.12.tar.gz.
File metadata
- Download URL: openrouter_provider-1.0.12.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cdc963ae99315156b705d1ceb3a7014922734930c3e31972ff788ec9bcdc397
|
|
| MD5 |
7ef542e4e6c6155e87983b44d6bbcc0b
|
|
| BLAKE2b-256 |
7c64ec646bbdeb4e1cfdfc9718a3af3ef8fc07de9666edd08727a2357745d255
|
File details
Details for the file openrouter_provider-1.0.12-py3-none-any.whl.
File metadata
- Download URL: openrouter_provider-1.0.12-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
882136218ee03fd157280a082d8d819b879f8bba472e2407d0e2ceff6810d931
|
|
| MD5 |
acd06fe758f8be1c961c8eff20907a3d
|
|
| BLAKE2b-256 |
94d5d95ece671ae0f2dd935fda5812caf665f346780448abc8948195d00a5be4
|