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)

Timeout

from openrouter import *

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

reply = client.invoke(model=LLMModel(name="openai/gpt-5"), query=Message(text="Hello"), timeout=10)
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.13.tar.gz (11.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.13-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openrouter_provider-1.0.13.tar.gz
  • Upload date:
  • Size: 11.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.13.tar.gz
Algorithm Hash digest
SHA256 e095695fa8a3d95f472471daac4f2d61e10df2e9992690501a137c940b86ccc7
MD5 31c3e087ffe5c3342c6ba70f657465d0
BLAKE2b-256 e3e74eff2178d53f2769848230cf37082bfd55a0093f102754c27a6d50256f31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrouter_provider-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 caea7440c0c80d9f7bfb54d9d80eed637283963cb59e932a5d7e7b0811b79a4d
MD5 d882266fcd4c648a2caaa7a29aab6743
BLAKE2b-256 e014a5065e35a8a7c15d9a59d942b8dc0d430f63c93913caf45bce898937406c

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