Skip to content

Commit 6c5dfcf

Browse files
authored
chore: 🐝 Update SDK - Generate 0.0.16 (#16)
2 parents e824ca8 + afbf99e commit 6c5dfcf

22 files changed

+376
-54
lines changed

.devcontainer/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11

2+
<div align="center">
3+
<a href="https://codespaces.new/OpenRouterTeam/python-sdk.git/tree/main"><img src="https://github.com/codespaces/badge.svg" /></a>
4+
</div>
5+
<br>
6+
27
> **Remember to shutdown a GitHub Codespace when it is not in use!**
38
49
# Dev Containers Quick Start

.speakeasy/gen.lock

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ id: cfd52247-6a25-4c6d-bbce-fe6fce0cd69d
33
management:
44
docChecksum: b1b97e85c6e3464e1fd6e2163c4ebc87
55
docVersion: 1.0.0
6-
speakeasyVersion: 1.656.2
7-
generationVersion: 2.753.6
8-
releaseVersion: 0.0.15
9-
configChecksum: ef777b42ca5f6690075cb13d061364fd
6+
speakeasyVersion: 1.658.1
7+
generationVersion: 2.755.6
8+
releaseVersion: 0.0.16
9+
configChecksum: bccceb456c96a46bcbe65fdff6bd5e1f
10+
repoURL: https://github.com/OpenRouterTeam/python-sdk.git
11+
installationURL: https://github.com/OpenRouterTeam/python-sdk.git
1012
published: true
1113
features:
1214
python:
1315
acceptHeaders: 3.0.0
1416
additionalDependencies: 1.0.0
1517
constsAndDefaults: 1.0.5
16-
core: 5.23.6
18+
core: 5.23.8
1719
defaultEnabledRetries: 0.2.0
1820
deprecations: 3.0.2
1921
devContainers: 3.0.0
@@ -523,6 +525,7 @@ generatedFiles:
523525
- docs/sdks/responses/README.md
524526
- py.typed
525527
- pyproject.toml
528+
- scripts/prepare_readme.py
526529
- scripts/publish.sh
527530
- src/openrouter/__init__.py
528531
- src/openrouter/_hooks/__init__.py

.speakeasy/gen.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ generation:
3030
generateNewTests: true
3131
skipResponseBodyAssertions: false
3232
python:
33-
version: 0.0.15
33+
version: 0.0.16
3434
additionalDependencies:
3535
dev: {}
3636
main: {}
@@ -64,6 +64,7 @@ python:
6464
webhooks: ""
6565
inputModelSuffix: input
6666
legacyPyright: false
67+
license: ""
6768
maxMethodParams: 999
6869
methodArguments: infer-optional-args
6970
moduleName: ""

.speakeasy/workflow.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
speakeasyVersion: 1.656.2
1+
speakeasyVersion: 1.658.1
22
sources:
33
-OAS:
44
sourceNamespace: open-router-chat-completions-api
55
sourceRevisionDigest: sha256:08647b466c00989914e3a2436175152270f771f0a57d055f5bab14cc2d4be89e
66
sourceBlobDigest: sha256:53027ec57392d9617cc001ece83c2fe1aa6e5dbfd52d170381c34c33c6042c23
77
tags:
88
- latest
9+
- speakeasy-sdk-regen-1763230596
910
targets:
1011
open-router:
1112
source: -OAS

README-PYPI.md

Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
# OpenRouter SDK (Beta)
2+
3+
The [OpenRouter SDK](https://openrouter.ai/docs/sdks/python) is a Python toolkit designed to help you build AI-powered features and solutions. Giving you easy access to over 300 models across providers in an easy and type-safe way.
4+
5+
To learn more about how to use the OpenRouter SDK, check out our [API Reference](https://openrouter.ai/docs/sdks/python/reference) and [Documentation](https://openrouter.ai/docs/sdks/python).
6+
7+
<!-- No Summary [summary] -->
8+
9+
<!-- No Table of Contents [toc] -->
10+
11+
<!-- Start SDK Installation [installation] -->
12+
## SDK Installation
13+
14+
> [!NOTE]
15+
> **Python version upgrade policy**
16+
>
17+
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.
18+
19+
The SDK can be installed with *uv*, *pip*, or *poetry* package managers.
20+
21+
### uv
22+
23+
*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.
24+
25+
```bash
26+
uv add openrouter
27+
```
28+
29+
### PIP
30+
31+
*PIP* is the default package installer for Python, enabling easy installation and management of packages from PyPI via the command line.
32+
33+
```bash
34+
pip install openrouter
35+
```
36+
37+
### Poetry
38+
39+
*Poetry* is a modern tool that simplifies dependency management and package publishing by using a single `pyproject.toml` file to handle project metadata and dependencies.
40+
41+
```bash
42+
poetry add openrouter
43+
```
44+
45+
### Shell and script usage with `uv`
46+
47+
You can use this SDK in a Python shell with [uv](https://docs.astral.sh/uv/) and the `uvx` command that comes with it like so:
48+
49+
```shell
50+
uvx --from openrouter python
51+
```
52+
53+
It's also possible to write a standalone Python script without needing to set up a whole project like so:
54+
55+
```python
56+
#!/usr/bin/env -S uv run --script
57+
# /// script
58+
# requires-python = ">=3.9"
59+
# dependencies = [
60+
# "openrouter",
61+
# ]
62+
# ///
63+
64+
from openrouter import OpenRouter
65+
66+
sdk = OpenRouter(
67+
# SDK arguments
68+
)
69+
70+
# Rest of script here...
71+
```
72+
73+
Once that is saved to a file, you can run it with `uv run script.py` where
74+
`script.py` can be replaced with the actual file name.
75+
<!-- End SDK Installation [installation] -->
76+
77+
<!-- Start Requirements [requirements] -->
78+
## Requirements
79+
80+
This SDK requires Python 3.9 or higher. For Python version support policy, see the SDK Installation section above.
81+
<!-- End Requirements [requirements] -->
82+
83+
<!-- Start IDE Support [idesupport] -->
84+
## IDE Support
85+
86+
### PyCharm
87+
88+
Generally, the SDK will work well with most IDEs out of the box. However, when using PyCharm, you can enjoy much better integration with Pydantic by installing an additional plugin.
89+
90+
- [PyCharm Pydantic Plugin](https://docs.pydantic.dev/latest/integrations/pycharm/)
91+
<!-- End IDE Support [idesupport] -->
92+
93+
<!-- No SDK Example Usage [usage] -->
94+
## SDK Usage
95+
96+
```python
97+
# Synchronous Example
98+
from openrouter import OpenRouter
99+
import os
100+
101+
102+
with OpenRouter(
103+
api_key=os.getenv("OPENROUTER_API_KEY", ""),
104+
) as open_router:
105+
106+
res = open_router.chat.send(messages=[
107+
{
108+
"role": "user",
109+
"content": "Hello, how are you?",
110+
},
111+
], model="anthropic/claude-4.5-sonnet", provider={
112+
"zdr": True,
113+
"sort": "price",
114+
}, stream=True)
115+
116+
for event in event_stream:
117+
# handle event
118+
print(event, flush=True)
119+
```
120+
121+
</br>
122+
123+
The same SDK client can also be used to make asynchronous requests by importing asyncio.
124+
125+
```python
126+
# Asynchronous Example
127+
import asyncio
128+
from openrouter import OpenRouter
129+
import os
130+
131+
async def main():
132+
133+
async with OpenRouter(
134+
api_key=os.getenv("OPENROUTER_API_KEY", ""),
135+
) as open_router:
136+
137+
res = await open_router.chat.send_async(messages=[
138+
{
139+
"role": "user",
140+
"content": "Hello, how are you?",
141+
},
142+
], model="anthropic/claude-4.5-sonnet", provider={
143+
"zdr": True,
144+
"sort": "price",
145+
}, stream=True)
146+
147+
async for event in event_stream:
148+
# handle event
149+
print(event, flush=True)
150+
151+
asyncio.run(main())
152+
```
153+
154+
<!-- No Authentication [security] -->
155+
156+
<!-- No Available Resources and Operations [operations] -->
157+
158+
<!-- No Standalone functions [standalone-funcs] -->
159+
160+
<!-- No React hooks with TanStack Query [react-query] -->
161+
162+
<!-- No Server-sent event streaming [eventstream] -->
163+
164+
<!-- No Retries [retries] -->
165+
166+
<!-- No Error Handling [errors] -->
167+
168+
<!-- No Server Selection [server] -->
169+
170+
<!-- No Custom HTTP Client [http-client] -->
171+
172+
<!-- Start Resource Management [resource-management] -->
173+
## Resource Management
174+
175+
The `OpenRouter` class implements the context manager protocol and registers a finalizer function to close the underlying sync and async HTTPX clients it uses under the hood. This will close HTTP connections, release memory and free up other resources held by the SDK. In short-lived Python programs and notebooks that make a few SDK method calls, resource management may not be a concern. However, in longer-lived programs, it is beneficial to create a single SDK instance via a [context manager][context-manager] and reuse it across the application.
176+
177+
[context-manager]: https://docs.python.org/3/reference/datamodel.html#context-managers
178+
179+
```python
180+
from openrouter import OpenRouter
181+
import os
182+
def main():
183+
184+
with OpenRouter(
185+
api_key=os.getenv("OPENROUTER_API_KEY", ""),
186+
) as open_router:
187+
# Rest of application here...
188+
189+
190+
# Or when using async:
191+
async def amain():
192+
193+
async with OpenRouter(
194+
api_key=os.getenv("OPENROUTER_API_KEY", ""),
195+
) as open_router:
196+
# Rest of application here...
197+
```
198+
<!-- End Resource Management [resource-management] -->
199+
200+
<!-- Start Debugging [debug] -->
201+
## Debugging
202+
203+
You can setup your SDK to emit debug logs for SDK requests and responses.
204+
205+
You can pass your own logger class directly into your SDK.
206+
```python
207+
from openrouter import OpenRouter
208+
import logging
209+
210+
logging.basicConfig(level=logging.DEBUG)
211+
s = OpenRouter(debug_logger=logging.getLogger("openrouter"))
212+
```
213+
214+
You can also enable a default debug logger by setting an environment variable `OPENROUTER_DEBUG` to true.
215+
<!-- End Debugging [debug] -->
216+
217+
<!-- Placeholder for Future Speakeasy SDK Sections -->
218+
219+
# Development
220+
221+
## Running Tests
222+
223+
To run the test suite, you'll need to set up your environment with an OpenRouter API key.
224+
225+
### Local Development
226+
227+
1. Copy the example environment file:
228+
229+
```bash
230+
cp .env.example .env
231+
```
232+
233+
2. Edit `.env` and add your OpenRouter API key:
234+
235+
```bash
236+
OPENROUTER_API_KEY=your_api_key_here
237+
```
238+
239+
3. Run the tests:
240+
241+
```bash
242+
pytest
243+
```
244+
245+
## Maturity
246+
247+
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
248+
to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
249+
looking for the latest version.

RELEASES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
## 2025-11-15 18:16:18
4+
### Changes
5+
Based on:
6+
- OpenAPI Doc
7+
- Speakeasy CLI 1.658.1 (2.755.6) https://github.com/speakeasy-api/speakeasy
8+
### Generated
9+
- [python v0.0.16] .
10+
### Releases
11+
- [PyPI v0.0.16] https://pypi.org/project/openrouter/0.0.16 - .

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
[project]
22
name = "openrouter"
3-
version = "0.0.15"
3+
version = "0.0.16"
44
description = "Official Python Client SDK for OpenRouter."
55
authors = [{ name = "OpenRouter" },]
6-
readme = "README.md"
6+
readme = "README-PYPI.md"
77
requires-python = ">=3.9.2"
88
dependencies = [
99
"httpcore >=1.0.9",
1010
"httpx >=0.28.1",
1111
"pydantic >=2.11.2",
1212
]
13+
urls.repository = "https://github.com/OpenRouterTeam/python-sdk.git"
1314

1415
[dependency-groups]
1516
dev = [

scripts/prepare_readme.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2+
3+
import re
4+
import shutil
5+
6+
try:
7+
with open("README.md", "r", encoding="utf-8") as rh:
8+
readme_contents = rh.read()
9+
GITHUB_URL = "https://github.com/OpenRouterTeam/python-sdk.git"
10+
GITHUB_URL = (
11+
GITHUB_URL[: -len(".git")] if GITHUB_URL.endswith(".git") else GITHUB_URL
12+
)
13+
REPO_SUBDIR = ""
14+
# links on PyPI should have absolute URLs
15+
readme_contents = re.sub(
16+
r"(\[[^\]]+\]\()((?!https?:)[^\)]+)(\))",
17+
lambda m: m.group(1)
18+
+ GITHUB_URL
19+
+ "/blob/master/"
20+
+ REPO_SUBDIR
21+
+ m.group(2)
22+
+ m.group(3),
23+
readme_contents,
24+
)
25+
26+
with open("README-PYPI.md", "w", encoding="utf-8") as wh:
27+
wh.write(readme_contents)
28+
except Exception as e:
29+
try:
30+
print("Failed to rewrite README.md to README-PYPI.md, copying original instead")
31+
print(e)
32+
shutil.copyfile("README.md", "README-PYPI.md")
33+
except Exception as ie:
34+
print("Failed to copy README.md to README-PYPI.md")
35+
print(ie)

scripts/publish.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
22

3+
uv run python scripts/prepare_readme.py
4+
35
uv build
46
uv publish --token $PYPI_TOKEN

0 commit comments

Comments
 (0)