Skip to main content

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)

Timeout and retries

from openrouter import *

client = OpenRouterClient(
    system_prompt="You are a friendly AI assistant.",
    timeout=30,
    max_retries=0,
)

reply = client.invoke(
    model=LLMModel(name="openai/gpt-5"),
    query=Message(text="Hello"),
    max_completion_tokens=1000,
    timeout=10,
    max_retries=2,
)
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)

Metadata

Release files for openrouter-provider 1.0.17

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-provider 1.0.17
File Size Uploaded Provenance Actions
openrouter_provider-1.0.17.tar.gz 12.9 kB Without provenance Details for openrouter_provider-1.0.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for openrouter-provider 1.0.17
File Interpreter ABI Platform Actions
openrouter_provider-1.0.17-py3-none-any.whl Python 3 none any Details for openrouter_provider-1.0.17-py3-none-any.whl

Total release size: 23.6 kB

Release files / openrouter_provider-1.0.17.tar.gz

Download URL openrouter_provider-1.0.17.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6089da364f62c46284c8ecc815ebc88b280e85cedb7e0520bfdcf3ece7745cbc
BLAKE2b-256 checksum
How to use checksums
360978c355fbda9895d306d3392bd831276511b81c57216a3f960197e8e87450
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / openrouter_provider-1.0.17-py3-none-any.whl

Download URL openrouter_provider-1.0.17-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7eb41f2626ffa5dcc4a3a8a074ca93818cadc6a3ec565d4099823da1235d4a9c
BLAKE2b-256 checksum
How to use checksums
8049e61db840e66b075028fec7346772af508655d077c4ad646e1f968fdbff47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Security for openrouter-provider 1.0.17

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.

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