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"),
    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)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openrouter_provider-1.0.15.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

openrouter_provider-1.0.15-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file openrouter_provider-1.0.15.tar.gz.

File metadata

  • Download URL: openrouter_provider-1.0.15.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for openrouter_provider-1.0.15.tar.gz
Algorithm Hash digest
SHA256 fb0b31f3c96e642cb3051236ff5c8cb5e2fffde85ec09aaf64d86c2d1f02efe9
MD5 ccf2ddcf82ce99df12026a92eb330922
BLAKE2b-256 e87a681297cd4f49cb38976a20385b237fdbdfdbadb098ff9fcdbf334986164d

See more details on using hashes here.

File details

Details for the file openrouter_provider-1.0.15-py3-none-any.whl.

File metadata

File hashes

Hashes for openrouter_provider-1.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 15c8003034ff820cbe947292a7591f613539be8026636567741612b9388dee2f
MD5 f47acb00fc748503cbbae033ee02c49c
BLAKE2b-256 295321c3aa50eb2bd7bde7a34af7f66b637dfe37c0090b1c8a426b2b8ba4b1dd

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.17

2 files

This release

1.0.15 This release

2 files

1.0.14

2 files

1.0.13

2 files

1.0.12

2 files

1.0.11

2 files

1.0.10

2 files

1.0.9

2 files

1.0.8

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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