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)

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.17.tar.gz (12.9 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.17-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for openrouter_provider-1.0.17.tar.gz
Algorithm Hash digest
SHA256 6089da364f62c46284c8ecc815ebc88b280e85cedb7e0520bfdcf3ece7745cbc
MD5 e96cd44e606f48342a0f42feb42851e5
BLAKE2b-256 360978c355fbda9895d306d3392bd831276511b81c57216a3f960197e8e87450

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrouter_provider-1.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 7eb41f2626ffa5dcc4a3a8a074ca93818cadc6a3ec565d4099823da1235d4a9c
MD5 a71fab81753ca4eb39ab843734ae9c79
BLAKE2b-256 8049e61db840e66b075028fec7346772af508655d077c4ad646e1f968fdbff47

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.17 This release

2 files

1.0.15

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