Skip to content

Commit 0771300

Browse files
committed
chore: update documentation and improve code comments for clarity
1 parent 0678f64 commit 0771300

4 files changed

Lines changed: 85 additions & 173 deletions

File tree

CHANGELOG.md

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,45 +8,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [0.2.0] - 2026-02-13
99

1010
### Added
11-
12-
#### Provider Routing
13-
- **Provider sort** — route by `price`, `throughput`, or `latency`
14-
- **Provider order** — prioritize specific providers (e.g. `anthropic,openai`)
15-
- **Provider ignore** — exclude providers from routing
16-
- **Require parameters** — only use providers supporting all request params
17-
- **Data collection policy**`allow` or `deny` data collection by providers
18-
19-
#### Model Capabilities
20-
- **Model fallbacks** — automatic failover to backup models via `models` array
21-
- **Middle-out compression**`transforms: ["middle-out"]` for long prompts
22-
- **Cache control** — Anthropic-style `cache_control` injection on longest message chunk
23-
24-
#### Reasoning
25-
- **Reasoning effort** — configurable `low`, `medium`, `high` effort levels
26-
- **Include reasoning**`<think>` tag support with proper open/close management
27-
28-
#### Robustness
29-
- **Payload sanitization** — strips Open WebUI internal keys (`chat_id`, `title`, `task`, `task_id`, `features`, `citations`) and dict-type `user` field
30-
- **Mid-stream error handling** — detects `"error"` in SSE chunks, cleanly closes reasoning blocks
31-
- **Auto-close `<think>` tags** — if stream ends during reasoning, the tag is properly closed
32-
- **API body error detection** — checks for `"error"` key in non-stream JSON responses
33-
- **Retry logic** — configurable auto-retry on timeout and connection errors
34-
35-
#### Display
36-
- **Provider icons** — 22 provider logos (OpenAI, Anthropic, Google, Meta, Mistral, DeepSeek, xAI, and more)
37-
- **Citation injection**`[n]` references replaced with markdown links, citation list appended
38-
39-
#### Testing
40-
- **Comprehensive test suite** — 131 tests covering all functions, edge cases, and error paths
11+
- Provider routing: sort by `price`/`throughput`/`latency`, preferred and ignored providers, `require_parameters`, data collection policy
12+
- Model fallbacks via `models` array for automatic failover
13+
- Middle-out compression (`transforms: ["middle-out"]`) for long prompts
14+
- Anthropic-style `cache_control` injection on the longest message chunk
15+
- Configurable reasoning effort (`low`, `medium`, `high`) and `<think>` tag support
16+
- Payload sanitization — strips Open WebUI internal keys and dict-type `user` field
17+
- Mid-stream SSE error handling with clean `<think>` block closure
18+
- Auto-retry on timeout and connection errors (configurable `MAX_RETRIES`)
19+
- 22 provider icons (OpenAI, Anthropic, Google, Meta, Mistral, DeepSeek, xAI, etc.)
20+
- Citation injection — `[n]` references replaced with markdown links
21+
- Comprehensive test suite covering all functions and error paths
4122

4223
### Changed
43-
- `pipe()` method is now `async` with `__user__` parameter (Open WebUI v0.4+ compliance)
44-
- `FREE_ONLY` filter now checks for `:free` suffix instead of substring match
45-
- Model ID prefix stripping uses `.split(".", 1)[-1]` for correct manifold prefix removal
24+
- `pipe()` is now `async` with `__user__` parameter (Open WebUI v0.4+)
25+
- `FREE_ONLY` checks for `:free` suffix instead of substring match
26+
- Model ID prefix stripping uses `.split(".", 1)[-1]`
4627

4728
### Fixed
4829
- Open WebUI internal keys no longer forwarded to OpenRouter API
49-
- `user` field sent as dict no longer causes OpenRouter validation errors
30+
- `user` field sent as dict no longer causes validation errors
5031
- Stream parser no longer crashes on malformed JSON chunks
5132
- HTTP error handler no longer crashes when response body is not JSON
5233

CONTRIBUTING.md

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,17 @@
22

33
> **Maintained by [Sena Labs](https://github.com/sena-labs)** · [GitHub](https://github.com/sena-labs/Open-Router-Pipe)
44
5-
Thanks for your interest in contributing! 🎉
5+
Thanks for your interest in contributing.
66

7-
## 🚀 Quick Start
7+
## Quick Start
88

99
```bash
10-
# Clone the repo
1110
git clone https://github.com/sena-labs/Open-Router-Pipe.git
1211
cd Open-Router-Pipe
13-
14-
# Run the test suite
1512
python test_pipe.py
1613
```
1714

18-
## 📁 Project Structure
19-
20-
```
21-
Open-Router-Pipe/
22-
├── openrouter_pipe.py # Main pipe source — this is what gets installed in Open WebUI
23-
├── test_pipe.py # Test suite (131 tests, run with: python test_pipe.py)
24-
├── README.md # Project documentation
25-
├── CHANGELOG.md # Version history (Keep a Changelog format)
26-
├── CONTRIBUTING.md # This file
27-
├── LICENSE # MIT License
28-
└── .gitignore # Git ignore rules
29-
```
30-
31-
## 🔧 Development
15+
## Development
3216

3317
### Prerequisites
3418

@@ -42,7 +26,7 @@ Open-Router-Pipe/
4226
python test_pipe.py
4327
```
4428

45-
All 131 tests should pass. If adding new functionality, add corresponding tests.
29+
All tests should pass. If adding new functionality, add corresponding tests.
4630

4731
### Code Style
4832

@@ -52,7 +36,7 @@ All 131 tests should pass. If adding new functionality, add corresponding tests.
5236
- Add docstrings for public methods
5337
- Use `print(f"[OpenRouter Pipe] ...")` for debug logging
5438

55-
## 🔀 Pull Request Process
39+
## Pull Request Process
5640

5741
1. **Fork** the repository
5842
2. Create a **feature branch** (`git checkout -b feature/my-feature`)
@@ -83,7 +67,7 @@ We use [Conventional Commits](https://www.conventionalcommits.org/):
8367
- [ ] Code follows existing style conventions
8468
- [ ] No OpenRouter API keys or secrets committed
8569

86-
## 🐛 Reporting Issues
70+
## Reporting Issues
8771

8872
When reporting a bug, please include:
8973

@@ -93,14 +77,14 @@ When reporting a bug, please include:
9377
4. **Expected vs actual behavior**
9478
5. **Error logs** (check Open WebUI server logs for `[OpenRouter Pipe]` messages)
9579

96-
## 📋 Feature Requests
80+
## Feature Requests
9781

9882
Before requesting a feature:
9983

10084
1. Check [OpenRouter API docs](https://openrouter.ai/docs) to confirm the feature exists upstream
10185
2. Check [Open WebUI Pipe docs](https://docs.openwebui.com/features/plugin/functions/pipe) for compatibility
10286
3. Open an issue describing the feature and its use case
10387

104-
## 📄 License
88+
## License
10589

10690
By contributing, you agree that your contributions will be licensed under the [MIT License](LICENSE).

README.md

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
11
<div align="center">
22

3-
<img src="https://capsule-render.vercel.app/api?type=waving&color=0:0d1117,50:1a1b2e,100:2d1b69&height=180&section=header&text=OpenRouter%20Pipe&fontColor=a78bfa&fontSize=42&animation=fadeIn&fontAlignY=36&desc=Open%20WebUI%20%E2%86%94%20OpenRouter%20Integration&descAlignY=56&descColor=8b5cf6" width="100%"/>
4-
5-
<br>
6-
7-
[![Typing SVG](https://readme-typing-svg.demolab.com?font=JetBrains+Mono&weight=500&size=20&duration=3000&pause=1000&color=A78BFA&center=true&vCenter=true&multiline=true&repeat=true&width=600&height=60&lines=Manifold+Pipe+for+Open+WebUI;All+OpenRouter+models+%E2%80%A2+one+integration)](https://openrouter.ai)
8-
9-
<br>
10-
113
<a href="https://github.com/sena-labs/Open-Router-Pipe"><img src="https://img.shields.io/badge/version-0.2.0-0d1117?style=for-the-badge&labelColor=7c3aed&color=0d1117" alt="version"></a>&nbsp;
124
<a href="https://www.python.org/"><img src="https://img.shields.io/badge/python-≥3.10-0d1117?style=for-the-badge&logo=python&logoColor=white&labelColor=3776AB" alt="python"></a>&nbsp;
135
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-0d1117?style=for-the-badge&labelColor=blue" alt="license"></a>&nbsp;
146
<a href="https://docs.openwebui.com"><img src="https://img.shields.io/badge/Open%20WebUI-compatible-0d1117?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNCAyNCIgZmlsbD0id2hpdGUiPjxwYXRoIGQ9Ik0xMiAyQzYuNDggMiAyIDYuNDggMiAxMnM0LjQ4IDEwIDEwIDEwIDEwLTQuNDggMTAtMTBTMTcuNTIgMiAxMiAyem0wIDE4Yy00LjQyIDAtOC0zLjU4LTgtOHMzLjU4LTggOC04IDggMy41OCA4IDgtMy41OCA0LTggOHoiLz48L3N2Zz4=&logoColor=white&labelColor=1a1a2e" alt="openwebui"></a>
157

16-
<br><br>
17-
18-
**Access 300+ AI models through OpenRouter directly inside Open WebUI.**
19-
<br>
20-
**Provider routing • Reasoning tokens • Streaming • Fallbacks • Cache control**
21-
22-
<br>
8+
</div>
239

24-
<kbd>[⚡ Quick Start](#-quick-start)</kbd>&nbsp;&nbsp;
25-
<kbd>[⚙️ Configuration](#%EF%B8%8F-configuration)</kbd>&nbsp;&nbsp;
26-
<kbd>[🧠 Features](#-features)</kbd>&nbsp;&nbsp;
27-
<kbd>[📖 API Reference](#-api-reference)</kbd>&nbsp;&nbsp;
28-
<kbd>[🤝 Contributing](#-contributing)</kbd>
10+
# OpenRouter Pipe
2911

30-
</div>
12+
**Access 300+ AI models through OpenRouter directly inside Open WebUI.**
3113

32-
<br>
14+
Provider routing · Reasoning tokens · Streaming · Fallbacks · Cache control
3315

3416
---
3517

36-
## Quick Start
18+
## Quick Start
3719

3820
### Prerequisites
3921

@@ -48,13 +30,15 @@
4830
4. Paste the entire contents of [`openrouter_pipe.py`](openrouter_pipe.py)
4931
5. Save and **enable** the function
5032
6. Go to **Valves** (⚙️ icon) and enter your `OPENROUTER_API_KEY`
51-
7. All OpenRouter models will appear in your model selector 🎉
33+
7. All OpenRouter models will appear in your model selector
5234

5335
> **Tip:** You can also set the API key via environment variable `OPENROUTER_API_KEY` on the server.
5436
37+
Alternatively, search for **"OpenRouter Pipe"** on [openwebui.com](https://openwebui.com) and install it directly from the community hub.
38+
5539
---
5640

57-
## 🧠 Features
41+
## Features
5842

5943
| Feature | Description |
6044
|---------|-------------|
@@ -72,7 +56,7 @@
7256

7357
---
7458

75-
## ⚙️ Configuration
59+
## Configuration
7660

7761
All settings are configurable via **Valves** in the Open WebUI admin panel. Every valve also accepts an environment variable fallback.
7862

@@ -126,7 +110,7 @@ All settings are configurable via **Valves** in the Open WebUI admin panel. Ever
126110

127111
---
128112

129-
## 📖 API Reference
113+
## API Reference
130114

131115
### Architecture
132116

@@ -161,13 +145,13 @@ It also removes `user` when sent as a dict (OWUI format) since OpenRouter expect
161145

162146
---
163147

164-
## 🏗️ Project Structure
148+
## Project Structure
165149

166150
```
167151
Open-Router-Pipe/
168152
├── openrouter_pipe.py # Main pipe source (install this in Open WebUI)
169153
├── function.json # Open WebUI community manifest (metadata, tags, categories)
170-
├── test_pipe.py # Comprehensive test suite (131 tests)
154+
├── test_pipe.py # Test suite
171155
├── README.md # This file
172156
├── CHANGELOG.md # Version history
173157
├── CONTRIBUTING.md # Contribution guidelines
@@ -177,22 +161,15 @@ Open-Router-Pipe/
177161

178162
---
179163

180-
## 🧪 Testing
181-
182-
The project includes a comprehensive test suite covering all functionality:
164+
## Testing
183165

184166
```bash
185167
python test_pipe.py
186168
```
187169

188-
```
189-
Total: 131 | ✓ Passed: 131 | ✗ Failed: 0
190-
All tests passed! ✓
191-
```
192-
193170
Tests cover:
194171
- Helper functions (`_insert_citations`, `_format_citation_list`, `_parse_csv`)
195-
- All 17 Valve defaults and validation
172+
- Valve defaults and validation
196173
- Payload preparation (key stripping, model ID fix, provider routing, fallbacks)
197174
- Stream response (reasoning tags, mid-stream errors, auto-close, citations)
198175
- Non-stream response (API errors, empty choices, timeout handling)
@@ -202,25 +179,13 @@ Tests cover:
202179

203180
---
204181

205-
## 🌐 Open WebUI Community
206-
207-
This pipe is available on the **[Open WebUI Community](https://openwebui.com)** site.
208-
209-
### Install from Community
210-
211-
1. Go to [openwebui.com](https://openwebui.com) and search for **"OpenRouter Pipe"**
212-
2. Click **Install** to add it directly to your Open WebUI instance
213-
3. Configure your `OPENROUTER_API_KEY` in the Valves settings
214-
215-
---
216-
217-
## 🤝 Contributing
182+
## Contributing
218183

219184
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
220185

221186
---
222187

223-
## 📄 License
188+
## License
224189

225190
This project is licensed under the **MIT License** — see the [LICENSE](LICENSE) file for details.
226191

@@ -232,8 +197,6 @@ Copyright (c) 2026 Sena Labs
232197

233198
<div align="center">
234199

235-
<img src="https://capsule-render.vercel.app/api?type=waving&color=0:2d1b69,50:1a1b2e,100:0d1117&height=100&section=footer" width="100%"/>
236-
237-
**Built with 💜 by [Sena Labs](https://github.com/sena-labs)**
200+
[Sena Labs](https://github.com/sena-labs)
238201

239202
</div>

0 commit comments

Comments
 (0)