Skip to main content

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


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.12.tar.gz (10.3 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.12-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

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

Hashes for openrouter_provider-1.0.12.tar.gz
Algorithm Hash digest
SHA256 6cdc963ae99315156b705d1ceb3a7014922734930c3e31972ff788ec9bcdc397
MD5 7ef542e4e6c6155e87983b44d6bbcc0b
BLAKE2b-256 7c64ec646bbdeb4e1cfdfc9718a3af3ef8fc07de9666edd08727a2357745d255

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrouter_provider-1.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 882136218ee03fd157280a082d8d819b879f8bba472e2407d0e2ceff6810d931
MD5 acd06fe758f8be1c961c8eff20907a3d
BLAKE2b-256 94d5d95ece671ae0f2dd935fda5812caf665f346780448abc8948195d00a5be4

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