This commit is contained in:
David Alberto Adler
2025-09-07 21:44:36 +01:00
parent f7f8677367
commit ed17d25183
17 changed files with 66 additions and 260 deletions
+3 -8
View File
@@ -1,17 +1,16 @@
lockVersion: 2.0.0
id: 232c6d4f-b0fd-4172-8f1b-e2421566e9b4
management:
docChecksum: f7eafe8edffbaf9ef5bb835b345c5a9e
docChecksum: 15ebbb27870a24f8f19c47eecc775af8
docVersion: 1.0.0
speakeasyVersion: 1.611.1
generationVersion: 2.694.1
releaseVersion: 0.4.1
configChecksum: 613707bdc6463db5dce971bc9cb430bb
releaseVersion: 0.5.1
configChecksum: 568679387340b2a17402ed3f9ffbf851
repoURL: https://github.com/speakeasy-sdks/openrouter-python-sdk.git
installationURL: https://github.com/speakeasy-sdks/openrouter-python-sdk.git
features:
python:
acceptHeaders: 3.0.0
additionalDependencies: 1.0.0
constsAndDefaults: 1.0.5
core: 5.20.3
@@ -58,7 +57,6 @@ generatedFiles:
- docs/models/chatcompletionchunkchoicedeltatoolcalltype.md
- docs/models/chatcompletionchunkchoicefinishreason.md
- docs/models/chatcompletionchunkobject.md
- docs/models/chatcompletionchunkwrapper.md
- docs/models/chatcompletioncontentpart.md
- docs/models/chatcompletioncontentpartaudio.md
- docs/models/chatcompletioncontentpartaudioformat.md
@@ -194,7 +192,6 @@ generatedFiles:
- docs/models/contenttext.md
- docs/models/contenttypeimageurl.md
- docs/models/contenttypetext.md
- docs/models/createchatcompletionresponse.md
- docs/models/detail.md
- docs/models/error.md
- docs/models/file.md
@@ -253,7 +250,6 @@ generatedFiles:
- src/openrouter/models/chatcompletionchunkchoice.py
- src/openrouter/models/chatcompletionchunkchoicedelta.py
- src/openrouter/models/chatcompletionchunkchoicedeltatoolcall.py
- src/openrouter/models/chatcompletionchunkwrapper.py
- src/openrouter/models/chatcompletioncontentpart.py
- src/openrouter/models/chatcompletioncontentpartaudio.py
- src/openrouter/models/chatcompletioncontentpartimage.py
@@ -273,7 +269,6 @@ generatedFiles:
- src/openrouter/models/chatcompletionusermessageparam.py
- src/openrouter/models/chatstreamcompletioncreateparams.py
- src/openrouter/models/completionusage.py
- src/openrouter/models/createchatcompletionop.py
- src/openrouter/models/fileannotationdetail.py
- src/openrouter/models/reasoningdetail.py
- src/openrouter/models/reasoningdetailencrypted.py
+1 -1
View File
@@ -25,7 +25,7 @@ generation:
generateNewTests: true
skipResponseBodyAssertions: false
python:
version: 0.4.1
version: 0.5.1
additionalDependencies:
dev: {}
main: {}
-4
View File
@@ -1534,10 +1534,6 @@ paths:
schema:
$ref: "#/components/schemas/ChatCompletion"
description: Non-streaming response when stream=false
text/event-stream:
x-speakeasy-sse-sentinel: "[DONE]"
schema:
$ref: "#/components/schemas/ChatCompletionChunkWrapper"
"400":
description: Bad request - invalid parameters
content:
+1 -1
View File
@@ -20,7 +20,7 @@ workflow:
sources:
OpenRouter Chat Completions API:
inputs:
- location: .speakeasy/input.openapi.yaml
- location: .speakeasy/in.openapi.yaml
output: .speakeasy/out.openapi.yaml
registry:
location: registry.speakeasyapi.dev/sheldon-vaughn-test/sandbox/open-router-chat-completions-api
+17 -33
View File
@@ -140,10 +140,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
</br>
@@ -168,10 +166,8 @@ async def main():
},
], stream=False, temperature=1, top_p=1)
async with res as event_stream:
async for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
asyncio.run(main())
```
@@ -205,10 +201,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
<!-- End Authentication [security] -->
@@ -249,7 +243,7 @@ with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
res = open_router.chat.complete_stream(messages=[
{
"role": "user",
"content": "Hello, how are you?",
@@ -292,10 +286,8 @@ with OpenRouter(
], stream=False, temperature=1, top_p=1,
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
@@ -318,10 +310,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
<!-- End Retries [retries] -->
@@ -359,10 +349,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
except errors.OpenRouterError as e:
@@ -429,10 +417,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
@@ -456,10 +442,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
<!-- End Server Selection [server] -->
+17 -33
View File
@@ -140,10 +140,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
</br>
@@ -168,10 +166,8 @@ async def main():
},
], stream=False, temperature=1, top_p=1)
async with res as event_stream:
async for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
asyncio.run(main())
```
@@ -205,10 +201,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
<!-- End Authentication [security] -->
@@ -249,7 +243,7 @@ with OpenRouter(
api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:
res = open_router.chat.complete(messages=[
res = open_router.chat.complete_stream(messages=[
{
"role": "user",
"content": "Hello, how are you?",
@@ -292,10 +286,8 @@ with OpenRouter(
], stream=False, temperature=1, top_p=1,
RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
@@ -318,10 +310,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
<!-- End Retries [retries] -->
@@ -359,10 +349,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
except errors.OpenRouterError as e:
@@ -429,10 +417,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
@@ -456,10 +442,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
<!-- End Server Selection [server] -->
+4 -8
View File
@@ -16,10 +16,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
</br>
@@ -44,10 +42,8 @@ async def main():
},
], stream=False, temperature=1, top_p=1)
async with res as event_stream:
async for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
asyncio.run(main())
```
@@ -1,8 +0,0 @@
# ChatCompletionChunkWrapper
## Fields
| Field | Type | Required | Description |
| -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- | -------------------------------------------------------------- |
| `data` | [models.ChatCompletionChunk](../models/chatcompletionchunk.md) | :heavy_check_mark: | Streaming chat completion chunk |
@@ -1,17 +0,0 @@
# CreateChatCompletionResponse
## Supported Types
### `models.ChatCompletion`
```python
value: models.ChatCompletion = /* values here */
```
### `Union[eventstreaming.EventStream[models.ChatCompletionChunkWrapper], eventstreaming.EventStreamAsync[models.ChatCompletionChunkWrapper]]`
```python
value: Union[eventstreaming.EventStream[models.ChatCompletionChunkWrapper], eventstreaming.EventStreamAsync[models.ChatCompletionChunkWrapper]] = /* values here */
```
+3 -5
View File
@@ -33,10 +33,8 @@ with OpenRouter(
},
], stream=False, temperature=1, top_p=1)
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
# Handle response
print(res)
```
@@ -73,7 +71,7 @@ with OpenRouter(
### Response
**[models.CreateChatCompletionResponse](../../models/createchatcompletionresponse.md)**
**[models.ChatCompletion](../../models/chatcompletion.md)**
### Errors
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "openrouter"
version = "0.4.1"
version = "0.5.1"
description = "Python Client SDK Generated by Speakeasy."
authors = [{ name = "Speakeasy" },]
readme = "README-PYPI.md"
+2 -2
View File
@@ -3,10 +3,10 @@
import importlib.metadata
__title__: str = "openrouter"
__version__: str = "0.4.1"
__version__: str = "0.5.1"
__openapi_doc_version__: str = "1.0.0"
__gen_version__: str = "2.694.1"
__user_agent__: str = "speakeasy-sdk/python 0.4.1 2.694.1 1.0.0 openrouter"
__user_agent__: str = "speakeasy-sdk/python 0.5.1 2.694.1 1.0.0 openrouter"
try:
if __package__ is not None:
+16 -71
View File
@@ -1,7 +1,6 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from .basesdk import BaseSDK
from enum import Enum
from openrouter import errors, models, utils
from openrouter._hooks import HookContext
from openrouter.types import OptionalNullable, UNSET
@@ -9,16 +8,6 @@ from openrouter.utils import eventstreaming, get_security_from_env
from openrouter.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, Dict, List, Mapping, Optional, Union
# region imports
from typing import overload
from typing_extensions import Literal
# endregion imports
class CompleteAcceptEnum(str, Enum):
APPLICATION_JSON = "application/json"
TEXT_EVENT_STREAM = "text/event-stream"
class Chat(BaseSDK):
r"""Chat completion operations"""
@@ -99,9 +88,8 @@ class Chat(BaseSDK):
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[CompleteAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.CreateChatCompletionResponse:
) -> models.ChatCompletion:
r"""Create a chat completion
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
@@ -134,7 +122,6 @@ class Chat(BaseSDK):
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param accept_header_override: Override the default accept header for this method
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
@@ -203,9 +190,7 @@ class Chat(BaseSDK):
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value=accept_header_override.value
if accept_header_override is not None
else "application/json;q=1, text/event-stream;q=0",
accept_header_value="application/json",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
@@ -234,37 +219,22 @@ class Chat(BaseSDK):
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
stream=True,
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
http_res_text = utils.stream_to_text(http_res)
return unmarshal_json_response(
models.ChatCompletion, http_res, http_res_text
)
if utils.match_response(http_res, "200", "text/event-stream"):
return eventstreaming.EventStream(
http_res,
lambda raw: utils.unmarshal_json(
raw, models.ChatCompletionChunkWrapper
),
sentinel="[DONE]",
client_ref=self,
)
return unmarshal_json_response(models.ChatCompletion, http_res)
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
http_res_text = utils.stream_to_text(http_res)
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res, http_res_text
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "500", "application/json"):
http_res_text = utils.stream_to_text(http_res)
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res, http_res_text
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "4XX", "*"):
http_res_text = utils.stream_to_text(http_res)
raise errors.OpenRouterDefaultError(
@@ -276,10 +246,7 @@ class Chat(BaseSDK):
"API error occurred", http_res, http_res_text
)
http_res_text = utils.stream_to_text(http_res)
raise errors.OpenRouterDefaultError(
"Unexpected response received", http_res, http_res_text
)
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
async def complete_async(
self,
@@ -357,9 +324,8 @@ class Chat(BaseSDK):
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[CompleteAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.CreateChatCompletionResponse:
) -> models.ChatCompletion:
r"""Create a chat completion
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
@@ -392,7 +358,6 @@ class Chat(BaseSDK):
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param accept_header_override: Override the default accept header for this method
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
@@ -461,9 +426,7 @@ class Chat(BaseSDK):
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value=accept_header_override.value
if accept_header_override is not None
else "application/json;q=1, text/event-stream;q=0",
accept_header_value="application/json",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
@@ -492,37 +455,22 @@ class Chat(BaseSDK):
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
stream=True,
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
http_res_text = await utils.stream_to_text_async(http_res)
return unmarshal_json_response(
models.ChatCompletion, http_res, http_res_text
)
if utils.match_response(http_res, "200", "text/event-stream"):
return eventstreaming.EventStreamAsync(
http_res,
lambda raw: utils.unmarshal_json(
raw, models.ChatCompletionChunkWrapper
),
sentinel="[DONE]",
client_ref=self,
)
return unmarshal_json_response(models.ChatCompletion, http_res)
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
http_res_text = await utils.stream_to_text_async(http_res)
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res, http_res_text
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "500", "application/json"):
http_res_text = await utils.stream_to_text_async(http_res)
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res, http_res_text
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res, http_res_text)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "4XX", "*"):
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.OpenRouterDefaultError(
@@ -534,10 +482,7 @@ class Chat(BaseSDK):
"API error occurred", http_res, http_res_text
)
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.OpenRouterDefaultError(
"Unexpected response received", http_res, http_res_text
)
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
def complete_stream(
self,
-16
View File
@@ -46,10 +46,6 @@ if TYPE_CHECKING:
ChatCompletionChunkChoiceDeltaToolCallType,
ChatCompletionChunkChoiceDeltaToolCallTypedDict,
)
from .chatcompletionchunkwrapper import (
ChatCompletionChunkWrapper,
ChatCompletionChunkWrapperTypedDict,
)
from .chatcompletioncontentpart import (
ChatCompletionContentPart,
ChatCompletionContentPartTypedDict,
@@ -304,10 +300,6 @@ if TYPE_CHECKING:
PromptTokensDetails,
PromptTokensDetailsTypedDict,
)
from .createchatcompletionop import (
CreateChatCompletionResponse,
CreateChatCompletionResponseTypedDict,
)
from .fileannotationdetail import (
ContentImageURL,
ContentImageURLTypedDict,
@@ -387,8 +379,6 @@ __all__ = [
"ChatCompletionChunkChoiceTypedDict",
"ChatCompletionChunkObject",
"ChatCompletionChunkTypedDict",
"ChatCompletionChunkWrapper",
"ChatCompletionChunkWrapperTypedDict",
"ChatCompletionContentPart",
"ChatCompletionContentPartAudio",
"ChatCompletionContentPartAudioFormat",
@@ -605,8 +595,6 @@ __all__ = [
"ContentTextTypedDict",
"ContentTypeImageURL",
"ContentTypeText",
"CreateChatCompletionResponse",
"CreateChatCompletionResponseTypedDict",
"Detail",
"Error",
"ErrorTypedDict",
@@ -682,8 +670,6 @@ _dynamic_imports: dict[str, str] = {
"ChatCompletionChunkChoiceDeltaToolCallFunctionTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
"ChatCompletionChunkChoiceDeltaToolCallType": ".chatcompletionchunkchoicedeltatoolcall",
"ChatCompletionChunkChoiceDeltaToolCallTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
"ChatCompletionChunkWrapper": ".chatcompletionchunkwrapper",
"ChatCompletionChunkWrapperTypedDict": ".chatcompletionchunkwrapper",
"ChatCompletionContentPart": ".chatcompletioncontentpart",
"ChatCompletionContentPartTypedDict": ".chatcompletioncontentpart",
"ChatCompletionContentPartAudio": ".chatcompletioncontentpartaudio",
@@ -903,8 +889,6 @@ _dynamic_imports: dict[str, str] = {
"CompletionUsageTypedDict": ".completionusage",
"PromptTokensDetails": ".completionusage",
"PromptTokensDetailsTypedDict": ".completionusage",
"CreateChatCompletionResponse": ".createchatcompletionop",
"CreateChatCompletionResponseTypedDict": ".createchatcompletionop",
"ContentImageURL": ".fileannotationdetail",
"ContentImageURLTypedDict": ".fileannotationdetail",
"ContentText": ".fileannotationdetail",
@@ -1,16 +0,0 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .chatcompletionchunk import ChatCompletionChunk, ChatCompletionChunkTypedDict
from openrouter.types import BaseModel
from typing_extensions import TypedDict
class ChatCompletionChunkWrapperTypedDict(TypedDict):
data: ChatCompletionChunkTypedDict
r"""Streaming chat completion chunk"""
class ChatCompletionChunkWrapper(BaseModel):
data: ChatCompletionChunk
r"""Streaming chat completion chunk"""
@@ -1,35 +0,0 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .chatcompletion import ChatCompletion, ChatCompletionTypedDict
from .chatcompletionchunkwrapper import (
ChatCompletionChunkWrapper,
ChatCompletionChunkWrapperTypedDict,
)
from openrouter.utils import eventstreaming
from typing import Union
from typing_extensions import TypeAliasType
CreateChatCompletionResponseTypedDict = TypeAliasType(
"CreateChatCompletionResponseTypedDict",
Union[
ChatCompletionTypedDict,
Union[
eventstreaming.EventStream[ChatCompletionChunkWrapperTypedDict],
eventstreaming.EventStreamAsync[ChatCompletionChunkWrapperTypedDict],
],
],
)
CreateChatCompletionResponse = TypeAliasType(
"CreateChatCompletionResponse",
Union[
ChatCompletion,
Union[
eventstreaming.EventStream[ChatCompletionChunkWrapper],
eventstreaming.EventStreamAsync[ChatCompletionChunkWrapper],
],
],
)
Generated
+1 -1
View File
@@ -201,7 +201,7 @@ wheels = [
[[package]]
name = "openrouter"
version = "0.4.1"
version = "0.5.1"
source = { editable = "." }
dependencies = [
{ name = "httpcore" },