swarmauri_provider_openrouter 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_provider_openrouter-0.1.0/LICENSE +13 -0
- swarmauri_provider_openrouter-0.1.0/NOTICE +7 -0
- swarmauri_provider_openrouter-0.1.0/PKG-INFO +361 -0
- swarmauri_provider_openrouter-0.1.0/README.md +339 -0
- swarmauri_provider_openrouter-0.1.0/pyproject.toml +97 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterAuthConfig.py +24 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterEndpoints.py +27 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterErrorMapper.py +12 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterModelCatalog.py +41 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterProvider.py +76 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterProviderPreferences.py +15 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterToolSchemaConverter.py +31 -0
- swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/__init__.py +24 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2024 Jacob Stewart
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_provider_openrouter
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OpenRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Keywords: swarmauri,provider,openrouter,model routing,model catalog,tool calling
|
|
9
|
+
Author: Jacob Stewart
|
|
10
|
+
Author-email: jacob@swarmauri.com
|
|
11
|
+
Requires-Python: >=3.10,<3.15
|
|
12
|
+
Classifier: Development Status :: 1 - Planning
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Requires-Dist: swarmauri_base (>=0.11.0,<0.12)
|
|
19
|
+
Requires-Dist: swarmauri_core (>=0.11.0,<0.12)
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# swarmauri_provider_openrouter
|
|
23
|
+
|
|
24
|
+
<!-- readme-standards:begin branding -->
|
|
25
|
+
<p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
|
|
26
|
+
<p align="center"><strong>swarmauri_provider_openrouter</strong></p>
|
|
27
|
+
<p align="center">OpenRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri.</p>
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="https://pypi.org/project/swarmauri_provider_openrouter/"><img alt="pypi: swarmauri_provider_openrouter" src="https://img.shields.io/pypi/v/swarmauri_provider_openrouter?labelColor=1E293B&color=1D4ED8"></a>
|
|
30
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml"><img alt="Source version: 0.1.0" src="https://img.shields.io/static/v1?label=Source%20version&message=0.1.0&labelColor=1E293B&color=4338CA"></a>
|
|
31
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml"><img alt="Python: >=3.10,<3.15" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.15&labelColor=1E293B&color=0F766E"></a>
|
|
32
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml"><img alt="Layer: community" src="https://img.shields.io/static/v1?label=Layer&message=community&labelColor=1E293B&color=6D28D9"></a>
|
|
33
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
34
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
35
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
36
|
+
</p>
|
|
37
|
+
<p align="center">
|
|
38
|
+
<a href="https://pypi.org/project/swarmauri_provider_openrouter/"><img alt="Monthly PyPI downloads: swarmauri_provider_openrouter" src="https://img.shields.io/pypi/dm/swarmauri_provider_openrouter?labelColor=1E293B&color=0E7490"></a>
|
|
39
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md"><img alt="README hits: swarmauri_provider_openrouter" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/50-community/swarmauri_provider_openrouter/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
40
|
+
</p>
|
|
41
|
+
<p align="center">
|
|
42
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
43
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
44
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
45
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
46
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
47
|
+
</p>
|
|
48
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
49
|
+
<!-- readme-standards:end branding -->
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Overview
|
|
54
|
+
|
|
55
|
+
### Summary
|
|
56
|
+
|
|
57
|
+
[](https://pypi.org/project/swarmauri_provider_openrouter/) [](https://pypi.org/project/swarmauri_provider_openrouter/) [](https://pepy.tech/project/swarmauri_provider_openrouter) [](https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/50-community/swarmauri_provider_openrouter/) [](https://pypi.org/project/swarmauri_provider_openrouter/)
|
|
58
|
+
|
|
59
|
+
`swarmauri_provider_openrouter` describes OpenRouter authentication, endpoints,
|
|
60
|
+
model metadata, routing preferences, provider errors, and tool schemas without
|
|
61
|
+
owning an HTTP implementation.
|
|
62
|
+
|
|
63
|
+
### Why This Package
|
|
64
|
+
|
|
65
|
+
`swarmauri_provider_openrouter` isolates this responsibility: OpenRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) exposes `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
|
|
66
|
+
|
|
67
|
+
### When to Use
|
|
68
|
+
|
|
69
|
+
Choose `swarmauri_provider_openrouter` when your integration needs openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Match the imports below to your application boundary and install its declared dependencies before using the example.
|
|
70
|
+
|
|
71
|
+
### Features
|
|
72
|
+
|
|
73
|
+
- Bearer authentication with optional application attribution headers.
|
|
74
|
+
- Capability-based resolution for chat, catalog, and image-generation APIs.
|
|
75
|
+
- Provider routing, fallback, data-collection, and ZDR preferences.
|
|
76
|
+
- Mutable provider catalog populated by an injected model client.
|
|
77
|
+
- OpenRouter-compatible function-tool schema conversion.
|
|
78
|
+
- Serializable connection configurations that exclude credentials.
|
|
79
|
+
|
|
80
|
+
### Non-Goals
|
|
81
|
+
|
|
82
|
+
`swarmauri_provider_openrouter` owns openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Its imports do not by themselves configure credentials, deploy a service, or certify the behavior of its consumers. Dependencies and neighboring packages retain their own documented responsibilities.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Getting Started
|
|
87
|
+
|
|
88
|
+
### Prerequisites
|
|
89
|
+
|
|
90
|
+
Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) declares runtime dependencies including `swarmauri-core`, `swarmauri-base`. Read the example’s inputs and service requirements before execution.
|
|
91
|
+
|
|
92
|
+
### Installation
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
uv add swarmauri_provider_openrouter
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install swarmauri_provider_openrouter
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### uv
|
|
103
|
+
|
|
104
|
+
<!-- readme-standards:begin installation.uv -->
|
|
105
|
+
```bash
|
|
106
|
+
uv add swarmauri_provider_openrouter
|
|
107
|
+
```
|
|
108
|
+
<!-- readme-standards:end installation.uv -->
|
|
109
|
+
|
|
110
|
+
#### pip
|
|
111
|
+
|
|
112
|
+
<!-- readme-standards:begin installation.pip -->
|
|
113
|
+
```bash
|
|
114
|
+
python -m pip install swarmauri_provider_openrouter
|
|
115
|
+
```
|
|
116
|
+
<!-- readme-standards:end installation.pip -->
|
|
117
|
+
|
|
118
|
+
#### Poetry
|
|
119
|
+
|
|
120
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
121
|
+
```bash
|
|
122
|
+
poetry add swarmauri_provider_openrouter
|
|
123
|
+
```
|
|
124
|
+
<!-- readme-standards:end installation.poetry -->
|
|
125
|
+
|
|
126
|
+
### Quick Start
|
|
127
|
+
|
|
128
|
+
#### Example
|
|
129
|
+
|
|
130
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
131
|
+
Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/docs/readme/quick_start.py).
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from swarmauri_provider_openrouter import (
|
|
135
|
+
OpenRouterProvider,
|
|
136
|
+
OpenRouterProviderPreferences,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
provider = OpenRouterProvider(
|
|
140
|
+
api_key="...",
|
|
141
|
+
site_url="https://example.com",
|
|
142
|
+
app_name="My application",
|
|
143
|
+
)
|
|
144
|
+
config = provider.connection_config(
|
|
145
|
+
"chat.completions",
|
|
146
|
+
model="openai/gpt-4o-mini",
|
|
147
|
+
)
|
|
148
|
+
headers = provider.authorize(config)
|
|
149
|
+
routing = OpenRouterProviderPreferences(order=["OpenAI"])
|
|
150
|
+
```
|
|
151
|
+
<!-- readme-standards:end example.quick-start -->
|
|
152
|
+
|
|
153
|
+
#### Expected Result
|
|
154
|
+
|
|
155
|
+
The example demonstrates the documented `swarmauri_provider_openrouter` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Usage
|
|
160
|
+
|
|
161
|
+
### Common Workflows
|
|
162
|
+
|
|
163
|
+
<!-- readme-standards:begin example.usage -->
|
|
164
|
+
Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/docs/readme/usage.py).
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from swarmauri_provider_openrouter import (
|
|
168
|
+
OpenRouterProvider,
|
|
169
|
+
OpenRouterProviderPreferences,
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
provider = OpenRouterProvider(
|
|
173
|
+
api_key="...",
|
|
174
|
+
site_url="https://example.com",
|
|
175
|
+
app_name="My application",
|
|
176
|
+
)
|
|
177
|
+
config = provider.connection_config(
|
|
178
|
+
"chat.completions",
|
|
179
|
+
model="openai/gpt-4o-mini",
|
|
180
|
+
)
|
|
181
|
+
headers = provider.authorize(config)
|
|
182
|
+
routing = OpenRouterProviderPreferences(order=["OpenAI"])
|
|
183
|
+
```
|
|
184
|
+
<!-- readme-standards:end example.usage -->
|
|
185
|
+
|
|
186
|
+
Pass the provider and routing preferences to a compatible model package. The
|
|
187
|
+
provider returns connection configuration; a Swarmauri transport such as
|
|
188
|
+
`swarmauri_transport_httpx` performs the request.
|
|
189
|
+
|
|
190
|
+
### Configuration
|
|
191
|
+
|
|
192
|
+
Configure `swarmauri_provider_openrouter` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
|
|
193
|
+
|
|
194
|
+
### Error Handling
|
|
195
|
+
|
|
196
|
+
The inspected `swarmauri_provider_openrouter` source raises `TypeError`, `ValueError`. Handle these at the calling boundary and consult the implementation for the triggering conditions.
|
|
197
|
+
|
|
198
|
+
### Best Practices
|
|
199
|
+
|
|
200
|
+
Use the explicit `swarmauri_provider_openrouter` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`; an import or successful installation alone does not establish its runtime guarantees.
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Package Boundary
|
|
205
|
+
|
|
206
|
+
### What It Owns
|
|
207
|
+
|
|
208
|
+
`swarmauri_provider_openrouter` is located in `community` and owns openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Source-declared APIs include `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) records its direct dependency boundary.
|
|
209
|
+
|
|
210
|
+
### Public API and Import Surfaces
|
|
211
|
+
|
|
212
|
+
Import namespace: `swarmauri_provider_openrouter`.
|
|
213
|
+
|
|
214
|
+
Source-declared exports or types: `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`.
|
|
215
|
+
|
|
216
|
+
Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
|
|
217
|
+
|
|
218
|
+
### Entry Points
|
|
219
|
+
|
|
220
|
+
<!-- readme-standards:begin entry-points -->
|
|
221
|
+
- `swarmauri.model_providers` → `OpenRouterProvider` → `swarmauri_provider_openrouter:OpenRouterProvider`
|
|
222
|
+
<!-- readme-standards:end entry-points -->
|
|
223
|
+
|
|
224
|
+
### Injected Dependencies
|
|
225
|
+
|
|
226
|
+
The direct installation dependencies of `swarmauri_provider_openrouter` are `swarmauri-core`, `swarmauri-base`. These declarations do not imply automatic provider selection. Pass collaborators through the explicit constructors or call signatures in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py).
|
|
227
|
+
|
|
228
|
+
### Protocol Consumers
|
|
229
|
+
|
|
230
|
+
Direct consumers in this checkout’s package manifests include `swarmauri_llm_openrouter`. These edges describe declared dependencies, not protocol-conformance evidence.
|
|
231
|
+
|
|
232
|
+
### Extensions
|
|
233
|
+
|
|
234
|
+
For `swarmauri_provider_openrouter`, use the source-declared public interfaces (`OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`) when composing or extending behavior. Its entry-point section below is authoritative for registered plugins; no additional extension loader is inferred from the package name.
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## Operations and Readiness
|
|
239
|
+
|
|
240
|
+
### Operational Requirements
|
|
241
|
+
|
|
242
|
+
Operate `swarmauri_provider_openrouter` according to its actual entry points and collaborators. The dependency and Python requirements in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
|
|
243
|
+
|
|
244
|
+
### Health and Observability
|
|
245
|
+
|
|
246
|
+
This README does not establish a standalone health endpoint for `swarmauri_provider_openrouter`. Observe the concrete caller’s results, exceptions, and existing test reports. An application that embeds this package must define its own health and telemetry contract.
|
|
247
|
+
|
|
248
|
+
### Security and Resource Limits
|
|
249
|
+
|
|
250
|
+
Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py). The `swarmauri_provider_openrouter` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
|
|
251
|
+
|
|
252
|
+
### Compatibility
|
|
253
|
+
|
|
254
|
+
This source version of `swarmauri_provider_openrouter` declares Python `>=3.10,<3.15`. Consult its dependency constraints before upgrading. Source-version and registry-version badges have separate meanings; this migration makes no additional platform or interoperability certification claim.
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Verification
|
|
259
|
+
|
|
260
|
+
### Tests
|
|
261
|
+
|
|
262
|
+
Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_provider_openrouter` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
|
|
263
|
+
|
|
264
|
+
- [tests/unit/test_openrouter_provider.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/tests/unit/test_openrouter_provider.py)
|
|
265
|
+
|
|
266
|
+
The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
|
|
267
|
+
|
|
268
|
+
### Certification Status
|
|
269
|
+
|
|
270
|
+
No external certification is asserted for `swarmauri_provider_openrouter` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
|
|
271
|
+
|
|
272
|
+
### Evidence
|
|
273
|
+
|
|
274
|
+
The [README standards CI](https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml) records mechanical documentation results for its tested commit. The [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## FAQ
|
|
279
|
+
|
|
280
|
+
### Why
|
|
281
|
+
|
|
282
|
+
**Why select this package?** `swarmauri_provider_openrouter` provides openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
|
|
283
|
+
|
|
284
|
+
### How
|
|
285
|
+
|
|
286
|
+
**How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_provider_openrouter`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) for the exact types and signatures involved.
|
|
287
|
+
|
|
288
|
+
### When
|
|
289
|
+
|
|
290
|
+
**When should I validate an upgrade?** Recheck `swarmauri_provider_openrouter` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## Documentation and Related Packages
|
|
295
|
+
|
|
296
|
+
### More Documentation
|
|
297
|
+
|
|
298
|
+
The [repository contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md), [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) provide the supporting context for `swarmauri_provider_openrouter`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
|
|
299
|
+
|
|
300
|
+
### Related Packages
|
|
301
|
+
|
|
302
|
+
- [swarmauri_base](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/20-bases/swarmauri_base/README.md): Reusable Swarmauri base classes, mixins, and dynamic Pydantic component models for composable intelligence infrastructure.
|
|
303
|
+
- [swarmauri_core](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/10-interfaces/swarmauri_core/README.md): Core interface contracts and shared types for Swarmauri composable intelligence infrastructure components.
|
|
304
|
+
|
|
305
|
+
### Project Links
|
|
306
|
+
|
|
307
|
+
<!-- readme-standards:begin project-links -->
|
|
308
|
+
- [pypi: swarmauri_provider_openrouter](https://pypi.org/project/swarmauri_provider_openrouter/)
|
|
309
|
+
<!-- readme-standards:end project-links -->
|
|
310
|
+
|
|
311
|
+
- [Swarmauri SDK](https://github.com/swarmauri/swarmauri-sdk)
|
|
312
|
+
- [OpenRouter documentation](https://openrouter.ai/docs)
|
|
313
|
+
|
|
314
|
+
---
|
|
315
|
+
|
|
316
|
+
## Contributing
|
|
317
|
+
|
|
318
|
+
### How to Contribute
|
|
319
|
+
|
|
320
|
+
Follow the [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) and include a focused example or regression for changes to `swarmauri_provider_openrouter`. Keep package behavior, its documented boundary, and its tests aligned.
|
|
321
|
+
|
|
322
|
+
### Development Setup
|
|
323
|
+
|
|
324
|
+
Work from the `pkgs/50-community/swarmauri_provider_openrouter` checkout. Synchronize its declared development environment with uv, then run the relevant package tests and `python -m pytest tests/unit/test_readme_sources.py`. The repository’s dedicated README job installs `readme-standards==0.1.3` without resolving unrelated runtime packages.
|
|
325
|
+
|
|
326
|
+
### Notes for Maintainers
|
|
327
|
+
|
|
328
|
+
Edit authored prose directly in this `swarmauri_provider_openrouter` README. Update source examples in `docs/readme/`, then run `readme-standards render --root . --write` from the package directory and review the diff. Required headings and generated blocks come from package-guide-v1.
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Governance
|
|
333
|
+
|
|
334
|
+
### Ownership and Decision Making
|
|
335
|
+
|
|
336
|
+
Changes to `swarmauri_provider_openrouter` follow the maintainer review process of [swarmauri/swarmauri-sdk](https://github.com/swarmauri/swarmauri-sdk) and its contribution guide. Author attribution remains in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml); this README does not assign new publishing or administrative authority.
|
|
337
|
+
|
|
338
|
+
### Standards and Policies
|
|
339
|
+
|
|
340
|
+
`swarmauri_provider_openrouter` follows the versioned [package-guide-v1 outline](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md). All fixed headings, hierarchy, order, separators, and package-specific branding are checked by CI; reviewers assess the accuracy and usefulness of authored claims.
|
|
341
|
+
|
|
342
|
+
### Lifecycle and Migration
|
|
343
|
+
|
|
344
|
+
The `swarmauri_provider_openrouter` source version is `0.1.0`.
|
|
345
|
+
|
|
346
|
+
---
|
|
347
|
+
|
|
348
|
+
## License and Attribution
|
|
349
|
+
|
|
350
|
+
### License
|
|
351
|
+
|
|
352
|
+
<!-- readme-standards:begin license -->
|
|
353
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/LICENSE).
|
|
354
|
+
<!-- readme-standards:end license -->
|
|
355
|
+
|
|
356
|
+
### Notices
|
|
357
|
+
|
|
358
|
+
<!-- readme-standards:begin notices -->
|
|
359
|
+
See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/NOTICE) for attribution.
|
|
360
|
+
<!-- readme-standards:end notices -->
|
|
361
|
+
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# swarmauri_provider_openrouter
|
|
2
|
+
|
|
3
|
+
<!-- readme-standards:begin branding -->
|
|
4
|
+
<p align="center"><a href="https://github.com/swarmauri/swarmauri-sdk"><img src="https://raw.githubusercontent.com/swarmauri/swarmauri-sdk/master/assets/swarmauri.brand.theme.svg" alt="Swarmauri SDK" width="300"></a></p>
|
|
5
|
+
<p align="center"><strong>swarmauri_provider_openrouter</strong></p>
|
|
6
|
+
<p align="center">OpenRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri.</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_provider_openrouter/"><img alt="pypi: swarmauri_provider_openrouter" src="https://img.shields.io/pypi/v/swarmauri_provider_openrouter?labelColor=1E293B&color=1D4ED8"></a>
|
|
9
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml"><img alt="Source version: 0.1.0" src="https://img.shields.io/static/v1?label=Source%20version&message=0.1.0&labelColor=1E293B&color=4338CA"></a>
|
|
10
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml"><img alt="Python: >=3.10,<3.15" src="https://img.shields.io/static/v1?label=Python&message=%3E%3D3.10%2C%3C3.15&labelColor=1E293B&color=0F766E"></a>
|
|
11
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml"><img alt="Layer: community" src="https://img.shields.io/static/v1?label=Layer&message=community&labelColor=1E293B&color=6D28D9"></a>
|
|
12
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md#lifecycle-and-migration"><img alt="Lifecycle: active" src="https://img.shields.io/static/v1?label=Lifecycle&message=active&labelColor=1E293B&color=166534"></a>
|
|
13
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/LICENSE"><img alt="License: Apache-2.0" src="https://img.shields.io/static/v1?label=License&message=Apache-2.0&labelColor=1E293B&color=86198F"></a>
|
|
14
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/NOTICE"><img alt="Notice: attribution" src="https://img.shields.io/static/v1?label=Notice&message=attribution&labelColor=1E293B&color=86198F"></a>
|
|
15
|
+
</p>
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://pypi.org/project/swarmauri_provider_openrouter/"><img alt="Monthly PyPI downloads: swarmauri_provider_openrouter" src="https://img.shields.io/pypi/dm/swarmauri_provider_openrouter?labelColor=1E293B&color=0E7490"></a>
|
|
18
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md"><img alt="README hits: swarmauri_provider_openrouter" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/pkgs/50-community/swarmauri_provider_openrouter/README.md.svg?label=README%20hits&labelColor=1E293B&color=0E7490"></a>
|
|
19
|
+
</p>
|
|
20
|
+
<p align="center">
|
|
21
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="README standards: CI gate" src="https://img.shields.io/static/v1?label=README%20standards&message=CI%20gate&labelColor=1E293B&color=1D4ED8"></a>
|
|
22
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/tests/unit/test_readme_sources.py"><img alt="Tests: example source" src="https://img.shields.io/static/v1?label=Tests&message=example%20source&labelColor=1E293B&color=0F766E"></a>
|
|
23
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md#certification-status"><img alt="Certification: not certified" src="https://img.shields.io/static/v1?label=Certification&message=not%20certified&labelColor=1E293B&color=92400E"></a>
|
|
24
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"><img alt="Governance: repository policy" src="https://img.shields.io/static/v1?label=Governance&message=repository%20policy&labelColor=1E293B&color=4338CA"></a>
|
|
25
|
+
<a href="https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"><img alt="Evidence: source and CI" src="https://img.shields.io/static/v1?label=Evidence&message=source%20and%20CI&labelColor=1E293B&color=6D28D9"></a>
|
|
26
|
+
</p>
|
|
27
|
+
<p align="center"><a href="#overview">Overview</a> · <a href="#installation">Installation</a> · <a href="#quick-start">Quick Start</a> · <a href="#usage">Usage</a> · <a href="#public-api-and-import-surfaces">API</a> · <a href="#contributing">Contributing</a> · <a href="#governance">Governance</a> · <a href="#license">License</a></p>
|
|
28
|
+
<!-- readme-standards:end branding -->
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Overview
|
|
33
|
+
|
|
34
|
+
### Summary
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/swarmauri_provider_openrouter/) [](https://pypi.org/project/swarmauri_provider_openrouter/) [](https://pepy.tech/project/swarmauri_provider_openrouter) [](https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/50-community/swarmauri_provider_openrouter/) [](https://pypi.org/project/swarmauri_provider_openrouter/)
|
|
37
|
+
|
|
38
|
+
`swarmauri_provider_openrouter` describes OpenRouter authentication, endpoints,
|
|
39
|
+
model metadata, routing preferences, provider errors, and tool schemas without
|
|
40
|
+
owning an HTTP implementation.
|
|
41
|
+
|
|
42
|
+
### Why This Package
|
|
43
|
+
|
|
44
|
+
`swarmauri_provider_openrouter` isolates this responsibility: OpenRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Its [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) exposes `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`, allowing consumers to select this package without treating adjacent packages as part of its public contract.
|
|
45
|
+
|
|
46
|
+
### When to Use
|
|
47
|
+
|
|
48
|
+
Choose `swarmauri_provider_openrouter` when your integration needs openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Match the imports below to your application boundary and install its declared dependencies before using the example.
|
|
49
|
+
|
|
50
|
+
### Features
|
|
51
|
+
|
|
52
|
+
- Bearer authentication with optional application attribution headers.
|
|
53
|
+
- Capability-based resolution for chat, catalog, and image-generation APIs.
|
|
54
|
+
- Provider routing, fallback, data-collection, and ZDR preferences.
|
|
55
|
+
- Mutable provider catalog populated by an injected model client.
|
|
56
|
+
- OpenRouter-compatible function-tool schema conversion.
|
|
57
|
+
- Serializable connection configurations that exclude credentials.
|
|
58
|
+
|
|
59
|
+
### Non-Goals
|
|
60
|
+
|
|
61
|
+
`swarmauri_provider_openrouter` owns openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Its imports do not by themselves configure credentials, deploy a service, or certify the behavior of its consumers. Dependencies and neighboring packages retain their own documented responsibilities.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Getting Started
|
|
66
|
+
|
|
67
|
+
### Prerequisites
|
|
68
|
+
|
|
69
|
+
Python `>=3.10,<3.15` is required. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) declares runtime dependencies including `swarmauri-core`, `swarmauri-base`. Read the example’s inputs and service requirements before execution.
|
|
70
|
+
|
|
71
|
+
### Installation
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
uv add swarmauri_provider_openrouter
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install swarmauri_provider_openrouter
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
#### uv
|
|
82
|
+
|
|
83
|
+
<!-- readme-standards:begin installation.uv -->
|
|
84
|
+
```bash
|
|
85
|
+
uv add swarmauri_provider_openrouter
|
|
86
|
+
```
|
|
87
|
+
<!-- readme-standards:end installation.uv -->
|
|
88
|
+
|
|
89
|
+
#### pip
|
|
90
|
+
|
|
91
|
+
<!-- readme-standards:begin installation.pip -->
|
|
92
|
+
```bash
|
|
93
|
+
python -m pip install swarmauri_provider_openrouter
|
|
94
|
+
```
|
|
95
|
+
<!-- readme-standards:end installation.pip -->
|
|
96
|
+
|
|
97
|
+
#### Poetry
|
|
98
|
+
|
|
99
|
+
<!-- readme-standards:begin installation.poetry -->
|
|
100
|
+
```bash
|
|
101
|
+
poetry add swarmauri_provider_openrouter
|
|
102
|
+
```
|
|
103
|
+
<!-- readme-standards:end installation.poetry -->
|
|
104
|
+
|
|
105
|
+
### Quick Start
|
|
106
|
+
|
|
107
|
+
#### Example
|
|
108
|
+
|
|
109
|
+
<!-- readme-standards:begin example.quick-start -->
|
|
110
|
+
Source: [docs/readme/quick_start.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/docs/readme/quick_start.py).
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from swarmauri_provider_openrouter import (
|
|
114
|
+
OpenRouterProvider,
|
|
115
|
+
OpenRouterProviderPreferences,
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
provider = OpenRouterProvider(
|
|
119
|
+
api_key="...",
|
|
120
|
+
site_url="https://example.com",
|
|
121
|
+
app_name="My application",
|
|
122
|
+
)
|
|
123
|
+
config = provider.connection_config(
|
|
124
|
+
"chat.completions",
|
|
125
|
+
model="openai/gpt-4o-mini",
|
|
126
|
+
)
|
|
127
|
+
headers = provider.authorize(config)
|
|
128
|
+
routing = OpenRouterProviderPreferences(order=["OpenAI"])
|
|
129
|
+
```
|
|
130
|
+
<!-- readme-standards:end example.quick-start -->
|
|
131
|
+
|
|
132
|
+
#### Expected Result
|
|
133
|
+
|
|
134
|
+
The example demonstrates the documented `swarmauri_provider_openrouter` source boundary or workflow. Complete its required configuration first. README CI checks the maintained source’s syntax and declarations; it does not claim that external services or the application workflow were exercised.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## Usage
|
|
139
|
+
|
|
140
|
+
### Common Workflows
|
|
141
|
+
|
|
142
|
+
<!-- readme-standards:begin example.usage -->
|
|
143
|
+
Source: [docs/readme/usage.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/docs/readme/usage.py).
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from swarmauri_provider_openrouter import (
|
|
147
|
+
OpenRouterProvider,
|
|
148
|
+
OpenRouterProviderPreferences,
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
provider = OpenRouterProvider(
|
|
152
|
+
api_key="...",
|
|
153
|
+
site_url="https://example.com",
|
|
154
|
+
app_name="My application",
|
|
155
|
+
)
|
|
156
|
+
config = provider.connection_config(
|
|
157
|
+
"chat.completions",
|
|
158
|
+
model="openai/gpt-4o-mini",
|
|
159
|
+
)
|
|
160
|
+
headers = provider.authorize(config)
|
|
161
|
+
routing = OpenRouterProviderPreferences(order=["OpenAI"])
|
|
162
|
+
```
|
|
163
|
+
<!-- readme-standards:end example.usage -->
|
|
164
|
+
|
|
165
|
+
Pass the provider and routing preferences to a compatible model package. The
|
|
166
|
+
provider returns connection configuration; a Swarmauri transport such as
|
|
167
|
+
`swarmauri_transport_httpx` performs the request.
|
|
168
|
+
|
|
169
|
+
### Configuration
|
|
170
|
+
|
|
171
|
+
Configure `swarmauri_provider_openrouter` through the APIs in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py); its [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) describes installation requirements, not an implicit service configuration. No additional package-global configuration contract is inferred from dependencies.
|
|
172
|
+
|
|
173
|
+
### Error Handling
|
|
174
|
+
|
|
175
|
+
The inspected `swarmauri_provider_openrouter` source raises `TypeError`, `ValueError`. Handle these at the calling boundary and consult the implementation for the triggering conditions.
|
|
176
|
+
|
|
177
|
+
### Best Practices
|
|
178
|
+
|
|
179
|
+
Use the explicit `swarmauri_provider_openrouter` imports documented below and keep collaborator configuration with the caller. Run the package’s relevant tests after changing `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`; an import or successful installation alone does not establish its runtime guarantees.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Package Boundary
|
|
184
|
+
|
|
185
|
+
### What It Owns
|
|
186
|
+
|
|
187
|
+
`swarmauri_provider_openrouter` is located in `community` and owns openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri. Source-declared APIs include `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`. The [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) records its direct dependency boundary.
|
|
188
|
+
|
|
189
|
+
### Public API and Import Surfaces
|
|
190
|
+
|
|
191
|
+
Import namespace: `swarmauri_provider_openrouter`.
|
|
192
|
+
|
|
193
|
+
Source-declared exports or types: `OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`.
|
|
194
|
+
|
|
195
|
+
Inspect [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) for exact signatures; this inventory does not designate every internal module as stable.
|
|
196
|
+
|
|
197
|
+
### Entry Points
|
|
198
|
+
|
|
199
|
+
<!-- readme-standards:begin entry-points -->
|
|
200
|
+
- `swarmauri.model_providers` → `OpenRouterProvider` → `swarmauri_provider_openrouter:OpenRouterProvider`
|
|
201
|
+
<!-- readme-standards:end entry-points -->
|
|
202
|
+
|
|
203
|
+
### Injected Dependencies
|
|
204
|
+
|
|
205
|
+
The direct installation dependencies of `swarmauri_provider_openrouter` are `swarmauri-core`, `swarmauri-base`. These declarations do not imply automatic provider selection. Pass collaborators through the explicit constructors or call signatures in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py).
|
|
206
|
+
|
|
207
|
+
### Protocol Consumers
|
|
208
|
+
|
|
209
|
+
Direct consumers in this checkout’s package manifests include `swarmauri_llm_openrouter`. These edges describe declared dependencies, not protocol-conformance evidence.
|
|
210
|
+
|
|
211
|
+
### Extensions
|
|
212
|
+
|
|
213
|
+
For `swarmauri_provider_openrouter`, use the source-declared public interfaces (`OpenRouterAuthConfig`, `OpenRouterEndpoints`, `OpenRouterErrorMapper`, `OpenRouterModelCatalog`, `OpenRouterProvider`, `OpenRouterProviderPreferences`, `OpenRouterToolSchemaConverter`) when composing or extending behavior. Its entry-point section below is authoritative for registered plugins; no additional extension loader is inferred from the package name.
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Operations and Readiness
|
|
218
|
+
|
|
219
|
+
### Operational Requirements
|
|
220
|
+
|
|
221
|
+
Operate `swarmauri_provider_openrouter` according to its actual entry points and collaborators. The dependency and Python requirements in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) are prerequisites; deployment topology, credentials, and readiness remain the responsibility of the consuming application unless explicitly documented above.
|
|
222
|
+
|
|
223
|
+
### Health and Observability
|
|
224
|
+
|
|
225
|
+
This README does not establish a standalone health endpoint for `swarmauri_provider_openrouter`. Observe the concrete caller’s results, exceptions, and existing test reports. An application that embeds this package must define its own health and telemetry contract.
|
|
226
|
+
|
|
227
|
+
### Security and Resource Limits
|
|
228
|
+
|
|
229
|
+
Apply the input, credential, and resource constraints implemented in [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py). The `swarmauri_provider_openrouter` README gate is a documentation check, not a security review or a substitute for the implementation’s limits and caller authorization.
|
|
230
|
+
|
|
231
|
+
### Compatibility
|
|
232
|
+
|
|
233
|
+
This source version of `swarmauri_provider_openrouter` declares Python `>=3.10,<3.15`. Consult its dependency constraints before upgrading. Source-version and registry-version badges have separate meanings; this migration makes no additional platform or interoperability certification claim.
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Verification
|
|
238
|
+
|
|
239
|
+
### Tests
|
|
240
|
+
|
|
241
|
+
Run `python -m pytest tests/unit/test_readme_sources.py` from the `swarmauri_provider_openrouter` package directory for the maintained example source checks (Python compilation and non-Python file presence). Existing package tests include:
|
|
242
|
+
|
|
243
|
+
- [tests/unit/test_openrouter_provider.py](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/tests/unit/test_openrouter_provider.py)
|
|
244
|
+
|
|
245
|
+
The repository README gate also checks the required heading tree, metadata, managed fragments, and referenced files.
|
|
246
|
+
|
|
247
|
+
### Certification Status
|
|
248
|
+
|
|
249
|
+
No external certification is asserted for `swarmauri_provider_openrouter` by this documentation migration. README conformance, example syntax, runtime tests, and protocol or security certification are distinct evidence scopes.
|
|
250
|
+
|
|
251
|
+
### Evidence
|
|
252
|
+
|
|
253
|
+
The [README standards CI](https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml) records mechanical documentation results for its tested commit. The [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) and example sources support the package-boundary description; external runtime behavior requires its own test evidence.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
## FAQ
|
|
258
|
+
|
|
259
|
+
### Why
|
|
260
|
+
|
|
261
|
+
**Why select this package?** `swarmauri_provider_openrouter` provides openRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri; use its own API boundary rather than assuming neighboring packages are bundled or configured automatically.
|
|
262
|
+
|
|
263
|
+
### How
|
|
264
|
+
|
|
265
|
+
**How do I start?** Install or synchronize the environment under Getting Started, follow the maintained example for `swarmauri_provider_openrouter`, and consult [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py) for the exact types and signatures involved.
|
|
266
|
+
|
|
267
|
+
### When
|
|
268
|
+
|
|
269
|
+
**When should I validate an upgrade?** Recheck `swarmauri_provider_openrouter` whenever its source version, declared collaborators, configuration, or caller changes. Run relevant behavioral tests in addition to the README gate before promotion.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Documentation and Related Packages
|
|
274
|
+
|
|
275
|
+
### More Documentation
|
|
276
|
+
|
|
277
|
+
The [repository contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md), [package source](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/swarmauri_provider_openrouter/__init__.py), and [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml) provide the supporting context for `swarmauri_provider_openrouter`. The [README policy](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md) defines the common document structure.
|
|
278
|
+
|
|
279
|
+
### Related Packages
|
|
280
|
+
|
|
281
|
+
- [swarmauri_base](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/20-bases/swarmauri_base/README.md): Reusable Swarmauri base classes, mixins, and dynamic Pydantic component models for composable intelligence infrastructure.
|
|
282
|
+
- [swarmauri_core](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/10-interfaces/swarmauri_core/README.md): Core interface contracts and shared types for Swarmauri composable intelligence infrastructure components.
|
|
283
|
+
|
|
284
|
+
### Project Links
|
|
285
|
+
|
|
286
|
+
<!-- readme-standards:begin project-links -->
|
|
287
|
+
- [pypi: swarmauri_provider_openrouter](https://pypi.org/project/swarmauri_provider_openrouter/)
|
|
288
|
+
<!-- readme-standards:end project-links -->
|
|
289
|
+
|
|
290
|
+
- [Swarmauri SDK](https://github.com/swarmauri/swarmauri-sdk)
|
|
291
|
+
- [OpenRouter documentation](https://openrouter.ai/docs)
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Contributing
|
|
296
|
+
|
|
297
|
+
### How to Contribute
|
|
298
|
+
|
|
299
|
+
Follow the [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md) and include a focused example or regression for changes to `swarmauri_provider_openrouter`. Keep package behavior, its documented boundary, and its tests aligned.
|
|
300
|
+
|
|
301
|
+
### Development Setup
|
|
302
|
+
|
|
303
|
+
Work from the `pkgs/50-community/swarmauri_provider_openrouter` checkout. Synchronize its declared development environment with uv, then run the relevant package tests and `python -m pytest tests/unit/test_readme_sources.py`. The repository’s dedicated README job installs `readme-standards==0.1.3` without resolving unrelated runtime packages.
|
|
304
|
+
|
|
305
|
+
### Notes for Maintainers
|
|
306
|
+
|
|
307
|
+
Edit authored prose directly in this `swarmauri_provider_openrouter` README. Update source examples in `docs/readme/`, then run `readme-standards render --root . --write` from the package directory and review the diff. Required headings and generated blocks come from package-guide-v1.
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Governance
|
|
312
|
+
|
|
313
|
+
### Ownership and Decision Making
|
|
314
|
+
|
|
315
|
+
Changes to `swarmauri_provider_openrouter` follow the maintainer review process of [swarmauri/swarmauri-sdk](https://github.com/swarmauri/swarmauri-sdk) and its contribution guide. Author attribution remains in the [manifest](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/pyproject.toml); this README does not assign new publishing or administrative authority.
|
|
316
|
+
|
|
317
|
+
### Standards and Policies
|
|
318
|
+
|
|
319
|
+
`swarmauri_provider_openrouter` follows the versioned [package-guide-v1 outline](https://github.com/groupsum/readme-standards/blob/master/docs/outline.md). All fixed headings, hierarchy, order, separators, and package-specific branding are checked by CI; reviewers assess the accuracy and usefulness of authored claims.
|
|
320
|
+
|
|
321
|
+
### Lifecycle and Migration
|
|
322
|
+
|
|
323
|
+
The `swarmauri_provider_openrouter` source version is `0.1.0`.
|
|
324
|
+
|
|
325
|
+
---
|
|
326
|
+
|
|
327
|
+
## License and Attribution
|
|
328
|
+
|
|
329
|
+
### License
|
|
330
|
+
|
|
331
|
+
<!-- readme-standards:begin license -->
|
|
332
|
+
Licensed under `Apache-2.0`. See [LICENSE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/LICENSE).
|
|
333
|
+
<!-- readme-standards:end license -->
|
|
334
|
+
|
|
335
|
+
### Notices
|
|
336
|
+
|
|
337
|
+
<!-- readme-standards:begin notices -->
|
|
338
|
+
See [NOTICE](https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/NOTICE) for attribution.
|
|
339
|
+
<!-- readme-standards:end notices -->
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "swarmauri_provider_openrouter"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "OpenRouter provider configuration, routing, catalogs, errors, and tool schemas for Swarmauri."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<3.15"
|
|
7
|
+
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
8
|
+
license = "Apache-2.0"
|
|
9
|
+
dependencies = ["swarmauri_core<0.12,>=0.11.0", "swarmauri_base<0.12,>=0.11.0"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 1 - Planning",
|
|
12
|
+
"Programming Language :: Python :: 3.10",
|
|
13
|
+
"Programming Language :: Python :: 3.11",
|
|
14
|
+
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Programming Language :: Python :: 3.13",
|
|
16
|
+
"Programming Language :: Python :: 3.14",
|
|
17
|
+
]
|
|
18
|
+
keywords = [
|
|
19
|
+
"swarmauri",
|
|
20
|
+
"provider",
|
|
21
|
+
"openrouter",
|
|
22
|
+
"model routing",
|
|
23
|
+
"model catalog",
|
|
24
|
+
"tool calling",
|
|
25
|
+
]
|
|
26
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
27
|
+
|
|
28
|
+
[tool.uv.sources]
|
|
29
|
+
swarmauri_core = { workspace = true }
|
|
30
|
+
swarmauri_base = { workspace = true }
|
|
31
|
+
|
|
32
|
+
[tool.readme_standards]
|
|
33
|
+
policy = "package-guide-v1"
|
|
34
|
+
readme = "README.md"
|
|
35
|
+
brand = "swarmauri"
|
|
36
|
+
brand_catalog = "../../../tools/readme/brands.toml"
|
|
37
|
+
repository = "https://github.com/swarmauri/swarmauri-sdk"
|
|
38
|
+
ref = "master"
|
|
39
|
+
package_path = "pkgs/50-community/swarmauri_provider_openrouter"
|
|
40
|
+
layer = "community"
|
|
41
|
+
lifecycle = "active"
|
|
42
|
+
license_file = "LICENSE"
|
|
43
|
+
notice_file = "NOTICE"
|
|
44
|
+
|
|
45
|
+
[tool.readme_standards.distributions.pypi]
|
|
46
|
+
name = "swarmauri_provider_openrouter"
|
|
47
|
+
published = true
|
|
48
|
+
|
|
49
|
+
[tool.readme_standards.examples.quick_start]
|
|
50
|
+
source = "docs/readme/quick_start.py"
|
|
51
|
+
test = "tests/unit/test_readme_sources.py"
|
|
52
|
+
language = "python"
|
|
53
|
+
expected_exit_code = 0
|
|
54
|
+
|
|
55
|
+
[tool.readme_standards.examples.usage]
|
|
56
|
+
source = "docs/readme/usage.py"
|
|
57
|
+
test = "tests/unit/test_readme_sources.py"
|
|
58
|
+
language = "python"
|
|
59
|
+
expected_exit_code = 0
|
|
60
|
+
|
|
61
|
+
[tool.readme_standards.statuses.readme]
|
|
62
|
+
label = "CI gate"
|
|
63
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
|
|
64
|
+
|
|
65
|
+
[tool.readme_standards.statuses.tests]
|
|
66
|
+
label = "example source"
|
|
67
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/tests/unit/test_readme_sources.py"
|
|
68
|
+
|
|
69
|
+
[tool.readme_standards.statuses.certification]
|
|
70
|
+
label = "not certified"
|
|
71
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/pkgs/50-community/swarmauri_provider_openrouter/README.md#certification-status"
|
|
72
|
+
|
|
73
|
+
[tool.readme_standards.statuses.governance]
|
|
74
|
+
label = "repository policy"
|
|
75
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/blob/master/tools/readme/POLICY.md"
|
|
76
|
+
|
|
77
|
+
[tool.readme_standards.statuses.evidence]
|
|
78
|
+
label = "source and CI"
|
|
79
|
+
url = "https://github.com/swarmauri/swarmauri-sdk/actions/workflows/readme-standards.yml"
|
|
80
|
+
[project.entry-points."swarmauri.model_providers"]
|
|
81
|
+
OpenRouterProvider = "swarmauri_provider_openrouter:OpenRouterProvider"
|
|
82
|
+
|
|
83
|
+
[build-system]
|
|
84
|
+
requires = ["poetry-core>=1.8.0"]
|
|
85
|
+
build-backend = "poetry.core.masonry.api"
|
|
86
|
+
|
|
87
|
+
[dependency-groups]
|
|
88
|
+
dev = ["pytest>=8.0", "ruff>=0.9.9", "readme-standards==0.1.3; python_version >= \"3.11\""]
|
|
89
|
+
|
|
90
|
+
[tool.pytest.ini_options]
|
|
91
|
+
markers = ["unit: Unit tests"]
|
|
92
|
+
|
|
93
|
+
[tool.ruff]
|
|
94
|
+
extend = "../../pyproject.toml"
|
|
95
|
+
|
|
96
|
+
[tool.ruff.lint]
|
|
97
|
+
ignore = ["N999", "RUF012"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from collections.abc import Mapping
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
from pydantic import SecretStr
|
|
5
|
+
from swarmauri_base.model_providers.ProviderAuthBase import ProviderAuthBase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OpenRouterAuthConfig(ProviderAuthBase):
|
|
9
|
+
api_key: SecretStr | None = None
|
|
10
|
+
site_url: str | None = None
|
|
11
|
+
app_name: str | None = None
|
|
12
|
+
type: Literal["OpenRouterAuthConfig"] = "OpenRouterAuthConfig"
|
|
13
|
+
|
|
14
|
+
def apply(self, headers: Mapping[str, str]) -> dict[str, str]:
|
|
15
|
+
authorized = dict(headers)
|
|
16
|
+
if self.api_key is not None:
|
|
17
|
+
authorized["Authorization"] = (
|
|
18
|
+
f"Bearer {self.api_key.get_secret_value()}"
|
|
19
|
+
)
|
|
20
|
+
if self.site_url:
|
|
21
|
+
authorized["HTTP-Referer"] = self.site_url
|
|
22
|
+
if self.app_name:
|
|
23
|
+
authorized["X-OpenRouter-Title"] = self.app_name
|
|
24
|
+
return authorized
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
from swarmauri_base.model_providers.ProviderEndpointBase import (
|
|
4
|
+
ProviderEndpointBase,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OpenRouterEndpoints(ProviderEndpointBase):
|
|
9
|
+
base_url: str = "https://openrouter.ai/api/v1"
|
|
10
|
+
chat_completions_path: str = "/chat/completions"
|
|
11
|
+
models_path: str = "/models"
|
|
12
|
+
image_generations_path: str = "/images/generations"
|
|
13
|
+
type: Literal["OpenRouterEndpoints"] = "OpenRouterEndpoints"
|
|
14
|
+
|
|
15
|
+
def resolve(self, capability: str) -> str:
|
|
16
|
+
paths = {
|
|
17
|
+
"chat.completions": self.chat_completions_path,
|
|
18
|
+
"models.list": self.models_path,
|
|
19
|
+
"images.generate": self.image_generations_path,
|
|
20
|
+
}
|
|
21
|
+
try:
|
|
22
|
+
path = paths[capability]
|
|
23
|
+
except KeyError as error:
|
|
24
|
+
raise ValueError(
|
|
25
|
+
f"OpenRouter does not support capability {capability!r}"
|
|
26
|
+
) from error
|
|
27
|
+
return f"{self.base_url.rstrip('/')}/{path.lstrip('/')}"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from typing import Any, Literal
|
|
2
|
+
|
|
3
|
+
from swarmauri_base.model_providers.ProviderErrorMapperBase import (
|
|
4
|
+
ProviderErrorMapperBase,
|
|
5
|
+
)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OpenRouterErrorMapper(ProviderErrorMapperBase):
|
|
9
|
+
type: Literal["OpenRouterErrorMapper"] = "OpenRouterErrorMapper"
|
|
10
|
+
|
|
11
|
+
def map_error(self, error: BaseException | Any) -> BaseException:
|
|
12
|
+
return RuntimeError(f"OpenRouter provider error: {error}")
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from collections.abc import Iterable
|
|
2
|
+
from typing import Any, Literal
|
|
3
|
+
|
|
4
|
+
from swarmauri_base.model_providers.ModelCatalogBase import ModelCatalogBase
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class OpenRouterModelCatalog(ModelCatalogBase):
|
|
8
|
+
models: dict[str, Any] = {
|
|
9
|
+
"openrouter/auto": {
|
|
10
|
+
"id": "openrouter/auto",
|
|
11
|
+
"name": "openrouter/auto",
|
|
12
|
+
"capabilities": ["chat_completions", "streaming", "tools"],
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
type: Literal["OpenRouterModelCatalog"] = "OpenRouterModelCatalog"
|
|
16
|
+
|
|
17
|
+
def load_response(self, payload: dict[str, Any]) -> list[dict[str, Any]]:
|
|
18
|
+
models = [item for item in payload.get("data", []) if item.get("id")]
|
|
19
|
+
self.models = {item["id"]: dict(item) for item in models}
|
|
20
|
+
return models
|
|
21
|
+
|
|
22
|
+
def list_models(
|
|
23
|
+
self, *, output_modalities: str | None = None
|
|
24
|
+
) -> Iterable[Any]:
|
|
25
|
+
models = list(self.models.values())
|
|
26
|
+
if output_modalities is None:
|
|
27
|
+
return models
|
|
28
|
+
return [
|
|
29
|
+
model
|
|
30
|
+
for model in models
|
|
31
|
+
if output_modalities
|
|
32
|
+
in (model.get("architecture", {}).get("output_modalities") or [])
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
def list_model_ids(
|
|
36
|
+
self, *, output_modalities: str | None = None
|
|
37
|
+
) -> list[str]:
|
|
38
|
+
return [
|
|
39
|
+
model.get("id") or model["name"]
|
|
40
|
+
for model in self.list_models(output_modalities=output_modalities)
|
|
41
|
+
]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
from typing import Any, Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import Field, model_validator
|
|
4
|
+
from swarmauri_base.model_providers.ModelProviderBase import ModelProviderBase
|
|
5
|
+
from swarmauri_base.model_providers.ProviderConnectionConfig import (
|
|
6
|
+
ProviderConnectionConfig,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
from .OpenRouterAuthConfig import OpenRouterAuthConfig
|
|
10
|
+
from .OpenRouterEndpoints import OpenRouterEndpoints
|
|
11
|
+
from .OpenRouterErrorMapper import OpenRouterErrorMapper
|
|
12
|
+
from .OpenRouterModelCatalog import OpenRouterModelCatalog
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class OpenRouterProvider(ModelProviderBase):
|
|
16
|
+
provider_name: Literal["openrouter"] = "openrouter"
|
|
17
|
+
endpoints: OpenRouterEndpoints = Field(default_factory=OpenRouterEndpoints)
|
|
18
|
+
catalog: OpenRouterModelCatalog = Field(
|
|
19
|
+
default_factory=OpenRouterModelCatalog
|
|
20
|
+
)
|
|
21
|
+
error_mapper: OpenRouterErrorMapper = Field(
|
|
22
|
+
default_factory=OpenRouterErrorMapper
|
|
23
|
+
)
|
|
24
|
+
auth: OpenRouterAuthConfig = Field(
|
|
25
|
+
default_factory=OpenRouterAuthConfig, exclude=True
|
|
26
|
+
)
|
|
27
|
+
site_url: str | None = None
|
|
28
|
+
app_name: str | None = None
|
|
29
|
+
type: Literal["OpenRouterProvider"] = "OpenRouterProvider"
|
|
30
|
+
|
|
31
|
+
@model_validator(mode="after")
|
|
32
|
+
def configure(self) -> "OpenRouterProvider":
|
|
33
|
+
self.base_url = self.base_url or self.endpoints.base_url
|
|
34
|
+
self.endpoints.base_url = self.base_url
|
|
35
|
+
if self.api_key is not None:
|
|
36
|
+
self.auth.api_key = self.api_key
|
|
37
|
+
elif self.auth.api_key is not None:
|
|
38
|
+
self.api_key = self.auth.api_key
|
|
39
|
+
if self.site_url is not None:
|
|
40
|
+
self.auth.site_url = self.site_url
|
|
41
|
+
elif self.auth.site_url is not None:
|
|
42
|
+
self.site_url = self.auth.site_url
|
|
43
|
+
if self.app_name is not None:
|
|
44
|
+
self.auth.app_name = self.app_name
|
|
45
|
+
elif self.auth.app_name is not None:
|
|
46
|
+
self.app_name = self.auth.app_name
|
|
47
|
+
return self
|
|
48
|
+
|
|
49
|
+
def connection_config(
|
|
50
|
+
self,
|
|
51
|
+
capability: str,
|
|
52
|
+
model: str | None = None,
|
|
53
|
+
) -> ProviderConnectionConfig:
|
|
54
|
+
endpoint = self.endpoints.resolve(capability)
|
|
55
|
+
options: dict[str, Any] = super().connection_options()
|
|
56
|
+
if model is not None:
|
|
57
|
+
options["model"] = model
|
|
58
|
+
return ProviderConnectionConfig(
|
|
59
|
+
endpoint=endpoint,
|
|
60
|
+
headers={
|
|
61
|
+
**self.default_headers,
|
|
62
|
+
"Accept": "application/json",
|
|
63
|
+
"Content-Type": "application/json",
|
|
64
|
+
},
|
|
65
|
+
transport_options=options,
|
|
66
|
+
auth_context=self.auth,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
@staticmethod
|
|
70
|
+
def authorize(config: ProviderConnectionConfig) -> dict[str, str]:
|
|
71
|
+
auth = config.auth_context
|
|
72
|
+
if not isinstance(auth, OpenRouterAuthConfig):
|
|
73
|
+
raise TypeError(
|
|
74
|
+
"OpenRouter connection configuration has no auth context"
|
|
75
|
+
)
|
|
76
|
+
return auth.apply(config.headers)
|
swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterProviderPreferences.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from typing import Any, Literal
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, ConfigDict
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class OpenRouterProviderPreferences(BaseModel):
|
|
7
|
+
"""Configure OpenRouter upstream-provider selection and data handling."""
|
|
8
|
+
|
|
9
|
+
order: list[str] | None = None
|
|
10
|
+
allow_fallbacks: bool = True
|
|
11
|
+
require_parameters: bool = False
|
|
12
|
+
data_collection: Literal["allow", "deny"] | None = None
|
|
13
|
+
zdr: bool | None = None
|
|
14
|
+
options: dict[str, Any] | None = None
|
|
15
|
+
model_config = ConfigDict(extra="forbid")
|
swarmauri_provider_openrouter-0.1.0/swarmauri_provider_openrouter/OpenRouterToolSchemaConverter.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class OpenRouterToolSchemaConverter:
|
|
5
|
+
def convert(self, tool: Any) -> dict[str, Any]:
|
|
6
|
+
properties: dict[str, Any] = {}
|
|
7
|
+
required: list[str] = []
|
|
8
|
+
for parameter in getattr(tool, "parameters", []):
|
|
9
|
+
schema: dict[str, Any] = {
|
|
10
|
+
"type": getattr(parameter, "input_type", "string"),
|
|
11
|
+
"description": getattr(parameter, "description", None),
|
|
12
|
+
}
|
|
13
|
+
enum = getattr(parameter, "enum", None)
|
|
14
|
+
if enum:
|
|
15
|
+
schema["enum"] = enum
|
|
16
|
+
properties[parameter.name] = schema
|
|
17
|
+
if getattr(parameter, "required", False):
|
|
18
|
+
required.append(parameter.name)
|
|
19
|
+
return {
|
|
20
|
+
"type": "function",
|
|
21
|
+
"function": {
|
|
22
|
+
"name": tool.name,
|
|
23
|
+
"description": getattr(tool, "description", None),
|
|
24
|
+
"parameters": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"properties": properties,
|
|
27
|
+
"required": required,
|
|
28
|
+
"additionalProperties": False,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
2
|
+
|
|
3
|
+
from .OpenRouterAuthConfig import OpenRouterAuthConfig
|
|
4
|
+
from .OpenRouterEndpoints import OpenRouterEndpoints
|
|
5
|
+
from .OpenRouterErrorMapper import OpenRouterErrorMapper
|
|
6
|
+
from .OpenRouterModelCatalog import OpenRouterModelCatalog
|
|
7
|
+
from .OpenRouterProvider import OpenRouterProvider
|
|
8
|
+
from .OpenRouterProviderPreferences import OpenRouterProviderPreferences
|
|
9
|
+
from .OpenRouterToolSchemaConverter import OpenRouterToolSchemaConverter
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"OpenRouterAuthConfig",
|
|
13
|
+
"OpenRouterEndpoints",
|
|
14
|
+
"OpenRouterErrorMapper",
|
|
15
|
+
"OpenRouterModelCatalog",
|
|
16
|
+
"OpenRouterProvider",
|
|
17
|
+
"OpenRouterProviderPreferences",
|
|
18
|
+
"OpenRouterToolSchemaConverter",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
try:
|
|
22
|
+
__version__ = version("swarmauri_provider_openrouter")
|
|
23
|
+
except PackageNotFoundError:
|
|
24
|
+
__version__ = "0.0.0"
|