openrouter 0.1.2__py3-none-any.whl → 0.6.0__py3-none-any.whl
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.
- openrouter/_version.py +2 -2
- openrouter/analytics.py +28 -2
- openrouter/api_keys.py +210 -14
- openrouter/chat.py +192 -200
- openrouter/components/__init__.py +229 -285
- openrouter/components/_schema10.py +39 -0
- openrouter/components/_schema14.py +11 -0
- openrouter/components/_schema17.py +154 -0
- openrouter/components/{_schema3.py → _schema19.py} +28 -22
- openrouter/components/{_schema0.py → _schema5.py} +7 -5
- openrouter/components/assistantmessage.py +32 -1
- openrouter/components/chatgenerationparams.py +57 -343
- openrouter/components/chatmessagecontentitemimage.py +4 -4
- openrouter/components/chatresponsechoice.py +1 -6
- openrouter/components/chatstreamingmessagechunk.py +3 -3
- openrouter/components/developermessage.py +41 -0
- openrouter/components/message.py +6 -39
- openrouter/components/model.py +7 -1
- openrouter/components/openresponsesrequest.py +31 -39
- openrouter/components/outputmodality.py +1 -0
- openrouter/components/providername.py +2 -0
- openrouter/components/providerpreferences.py +2 -10
- openrouter/components/publicendpoint.py +8 -24
- openrouter/components/publicpricing.py +3 -24
- openrouter/credits.py +86 -14
- openrouter/embeddings.py +92 -20
- openrouter/endpoints.py +62 -2
- openrouter/generations.py +26 -0
- openrouter/guardrails.py +3367 -0
- openrouter/models_.py +120 -12
- openrouter/oauth.py +90 -22
- openrouter/operations/__init__.py +601 -30
- openrouter/operations/bulkassignkeystoguardrail.py +116 -0
- openrouter/operations/bulkassignmemberstoguardrail.py +116 -0
- openrouter/operations/bulkunassignkeysfromguardrail.py +116 -0
- openrouter/operations/bulkunassignmembersfromguardrail.py +116 -0
- openrouter/operations/createauthkeyscode.py +81 -3
- openrouter/operations/createcoinbasecharge.py +82 -2
- openrouter/operations/createembeddings.py +82 -3
- openrouter/operations/createguardrail.py +325 -0
- openrouter/operations/createkeys.py +81 -3
- openrouter/operations/createresponses.py +84 -3
- openrouter/operations/deleteguardrail.py +104 -0
- openrouter/operations/deletekeys.py +69 -3
- openrouter/operations/exchangeauthcodeforapikey.py +81 -3
- openrouter/operations/getcredits.py +70 -1
- openrouter/operations/getcurrentkey.py +81 -3
- openrouter/operations/getgeneration.py +248 -3
- openrouter/operations/getguardrail.py +228 -0
- openrouter/operations/getkey.py +64 -1
- openrouter/operations/getmodels.py +95 -5
- openrouter/operations/getuseractivity.py +62 -1
- openrouter/operations/list.py +63 -1
- openrouter/operations/listembeddingsmodels.py +74 -0
- openrouter/operations/listendpoints.py +65 -2
- openrouter/operations/listendpointszdr.py +70 -2
- openrouter/operations/listguardrailkeyassignments.py +192 -0
- openrouter/operations/listguardrailmemberassignments.py +187 -0
- openrouter/operations/listguardrails.py +238 -0
- openrouter/operations/listkeyassignments.py +180 -0
- openrouter/operations/listmemberassignments.py +175 -0
- openrouter/operations/listmodelscount.py +74 -0
- openrouter/operations/listmodelsuser.py +70 -2
- openrouter/operations/listproviders.py +70 -2
- openrouter/operations/sendchatcompletionrequest.py +87 -3
- openrouter/operations/updateguardrail.py +334 -0
- openrouter/operations/updatekeys.py +63 -0
- openrouter/providers.py +36 -2
- openrouter/responses.py +178 -148
- openrouter/sdk.py +5 -8
- openrouter/types/models.py +378 -0
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/METADATA +5 -1
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/RECORD +76 -63
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/WHEEL +1 -1
- openrouter/completions.py +0 -361
- openrouter/components/completionchoice.py +0 -82
- openrouter/components/completioncreateparams.py +0 -277
- openrouter/components/completionlogprobs.py +0 -54
- openrouter/components/completionresponse.py +0 -46
- openrouter/components/completionusage.py +0 -19
- openrouter/operations/getparameters.py +0 -123
- openrouter/parameters.py +0 -237
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/licenses/LICENSE +0 -0
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/top_level.txt +0 -0
|
@@ -2,15 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedStr
|
|
5
|
-
from openrouter.utils import
|
|
5
|
+
from openrouter.utils import (
|
|
6
|
+
FieldMetadata,
|
|
7
|
+
HeaderMetadata,
|
|
8
|
+
QueryParamMetadata,
|
|
9
|
+
validate_open_enum,
|
|
10
|
+
)
|
|
11
|
+
import pydantic
|
|
6
12
|
from pydantic import model_serializer
|
|
7
13
|
from pydantic.functional_validators import PlainValidator
|
|
8
|
-
from typing import Literal, Union
|
|
9
|
-
from typing_extensions import Annotated, TypedDict
|
|
14
|
+
from typing import List, Literal, Optional, Union
|
|
15
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class GetGenerationGlobalsTypedDict(TypedDict):
|
|
19
|
+
http_referer: NotRequired[str]
|
|
20
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
21
|
+
This is used to track API usage per application.
|
|
22
|
+
|
|
23
|
+
"""
|
|
24
|
+
x_title: NotRequired[str]
|
|
25
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
26
|
+
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class GetGenerationGlobals(BaseModel):
|
|
31
|
+
http_referer: Annotated[
|
|
32
|
+
Optional[str],
|
|
33
|
+
pydantic.Field(alias="HTTP-Referer"),
|
|
34
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
35
|
+
] = None
|
|
36
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
37
|
+
This is used to track API usage per application.
|
|
38
|
+
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
x_title: Annotated[
|
|
42
|
+
Optional[str],
|
|
43
|
+
pydantic.Field(alias="X-Title"),
|
|
44
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
45
|
+
] = None
|
|
46
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
47
|
+
|
|
48
|
+
"""
|
|
10
49
|
|
|
11
50
|
|
|
12
51
|
class GetGenerationRequestTypedDict(TypedDict):
|
|
13
52
|
id: str
|
|
53
|
+
http_referer: NotRequired[str]
|
|
54
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
55
|
+
This is used to track API usage per application.
|
|
56
|
+
|
|
57
|
+
"""
|
|
58
|
+
x_title: NotRequired[str]
|
|
59
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
60
|
+
|
|
61
|
+
"""
|
|
14
62
|
|
|
15
63
|
|
|
16
64
|
class GetGenerationRequest(BaseModel):
|
|
@@ -18,6 +66,25 @@ class GetGenerationRequest(BaseModel):
|
|
|
18
66
|
str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
|
|
19
67
|
]
|
|
20
68
|
|
|
69
|
+
http_referer: Annotated[
|
|
70
|
+
Optional[str],
|
|
71
|
+
pydantic.Field(alias="HTTP-Referer"),
|
|
72
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
73
|
+
] = None
|
|
74
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
75
|
+
This is used to track API usage per application.
|
|
76
|
+
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
x_title: Annotated[
|
|
80
|
+
Optional[str],
|
|
81
|
+
pydantic.Field(alias="X-Title"),
|
|
82
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
83
|
+
] = None
|
|
84
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
|
|
21
88
|
|
|
22
89
|
APIType = Union[
|
|
23
90
|
Literal[
|
|
@@ -29,6 +96,178 @@ APIType = Union[
|
|
|
29
96
|
r"""Type of API used for the generation"""
|
|
30
97
|
|
|
31
98
|
|
|
99
|
+
ProviderName = Union[
|
|
100
|
+
Literal[
|
|
101
|
+
"AnyScale",
|
|
102
|
+
"Atoma",
|
|
103
|
+
"Cent-ML",
|
|
104
|
+
"CrofAI",
|
|
105
|
+
"Enfer",
|
|
106
|
+
"GoPomelo",
|
|
107
|
+
"HuggingFace",
|
|
108
|
+
"Hyperbolic 2",
|
|
109
|
+
"InoCloud",
|
|
110
|
+
"Kluster",
|
|
111
|
+
"Lambda",
|
|
112
|
+
"Lepton",
|
|
113
|
+
"Lynn 2",
|
|
114
|
+
"Lynn",
|
|
115
|
+
"Mancer",
|
|
116
|
+
"Meta",
|
|
117
|
+
"Modal",
|
|
118
|
+
"Nineteen",
|
|
119
|
+
"OctoAI",
|
|
120
|
+
"Recursal",
|
|
121
|
+
"Reflection",
|
|
122
|
+
"Replicate",
|
|
123
|
+
"SambaNova 2",
|
|
124
|
+
"SF Compute",
|
|
125
|
+
"Targon",
|
|
126
|
+
"Together 2",
|
|
127
|
+
"Ubicloud",
|
|
128
|
+
"01.AI",
|
|
129
|
+
"AI21",
|
|
130
|
+
"AionLabs",
|
|
131
|
+
"Alibaba",
|
|
132
|
+
"Ambient",
|
|
133
|
+
"Amazon Bedrock",
|
|
134
|
+
"Amazon Nova",
|
|
135
|
+
"Anthropic",
|
|
136
|
+
"Arcee AI",
|
|
137
|
+
"AtlasCloud",
|
|
138
|
+
"Avian",
|
|
139
|
+
"Azure",
|
|
140
|
+
"BaseTen",
|
|
141
|
+
"BytePlus",
|
|
142
|
+
"Black Forest Labs",
|
|
143
|
+
"Cerebras",
|
|
144
|
+
"Chutes",
|
|
145
|
+
"Cirrascale",
|
|
146
|
+
"Clarifai",
|
|
147
|
+
"Cloudflare",
|
|
148
|
+
"Cohere",
|
|
149
|
+
"Crusoe",
|
|
150
|
+
"DeepInfra",
|
|
151
|
+
"DeepSeek",
|
|
152
|
+
"Featherless",
|
|
153
|
+
"Fireworks",
|
|
154
|
+
"Friendli",
|
|
155
|
+
"GMICloud",
|
|
156
|
+
"Google",
|
|
157
|
+
"Google AI Studio",
|
|
158
|
+
"Groq",
|
|
159
|
+
"Hyperbolic",
|
|
160
|
+
"Inception",
|
|
161
|
+
"Inceptron",
|
|
162
|
+
"InferenceNet",
|
|
163
|
+
"Infermatic",
|
|
164
|
+
"Inflection",
|
|
165
|
+
"Liquid",
|
|
166
|
+
"Mara",
|
|
167
|
+
"Mancer 2",
|
|
168
|
+
"Minimax",
|
|
169
|
+
"ModelRun",
|
|
170
|
+
"Mistral",
|
|
171
|
+
"Modular",
|
|
172
|
+
"Moonshot AI",
|
|
173
|
+
"Morph",
|
|
174
|
+
"NCompass",
|
|
175
|
+
"Nebius",
|
|
176
|
+
"NextBit",
|
|
177
|
+
"Novita",
|
|
178
|
+
"Nvidia",
|
|
179
|
+
"OpenAI",
|
|
180
|
+
"OpenInference",
|
|
181
|
+
"Parasail",
|
|
182
|
+
"Perplexity",
|
|
183
|
+
"Phala",
|
|
184
|
+
"Relace",
|
|
185
|
+
"SambaNova",
|
|
186
|
+
"Seed",
|
|
187
|
+
"SiliconFlow",
|
|
188
|
+
"Sourceful",
|
|
189
|
+
"StepFun",
|
|
190
|
+
"Stealth",
|
|
191
|
+
"StreamLake",
|
|
192
|
+
"Switchpoint",
|
|
193
|
+
"Together",
|
|
194
|
+
"Upstage",
|
|
195
|
+
"Venice",
|
|
196
|
+
"WandB",
|
|
197
|
+
"Xiaomi",
|
|
198
|
+
"xAI",
|
|
199
|
+
"Z.AI",
|
|
200
|
+
"FakeProvider",
|
|
201
|
+
],
|
|
202
|
+
UnrecognizedStr,
|
|
203
|
+
]
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
class ProviderResponseTypedDict(TypedDict):
|
|
207
|
+
status: Nullable[float]
|
|
208
|
+
id: NotRequired[str]
|
|
209
|
+
endpoint_id: NotRequired[str]
|
|
210
|
+
model_permaslug: NotRequired[str]
|
|
211
|
+
provider_name: NotRequired[ProviderName]
|
|
212
|
+
latency: NotRequired[float]
|
|
213
|
+
is_byok: NotRequired[bool]
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class ProviderResponse(BaseModel):
|
|
217
|
+
status: Nullable[float]
|
|
218
|
+
|
|
219
|
+
id: Optional[str] = None
|
|
220
|
+
|
|
221
|
+
endpoint_id: Optional[str] = None
|
|
222
|
+
|
|
223
|
+
model_permaslug: Optional[str] = None
|
|
224
|
+
|
|
225
|
+
provider_name: Annotated[
|
|
226
|
+
Optional[ProviderName], PlainValidator(validate_open_enum(False))
|
|
227
|
+
] = None
|
|
228
|
+
|
|
229
|
+
latency: Optional[float] = None
|
|
230
|
+
|
|
231
|
+
is_byok: Optional[bool] = None
|
|
232
|
+
|
|
233
|
+
@model_serializer(mode="wrap")
|
|
234
|
+
def serialize_model(self, handler):
|
|
235
|
+
optional_fields = [
|
|
236
|
+
"id",
|
|
237
|
+
"endpoint_id",
|
|
238
|
+
"model_permaslug",
|
|
239
|
+
"provider_name",
|
|
240
|
+
"latency",
|
|
241
|
+
"is_byok",
|
|
242
|
+
]
|
|
243
|
+
nullable_fields = ["status"]
|
|
244
|
+
null_default_fields = []
|
|
245
|
+
|
|
246
|
+
serialized = handler(self)
|
|
247
|
+
|
|
248
|
+
m = {}
|
|
249
|
+
|
|
250
|
+
for n, f in type(self).model_fields.items():
|
|
251
|
+
k = f.alias or n
|
|
252
|
+
val = serialized.get(k)
|
|
253
|
+
serialized.pop(k, None)
|
|
254
|
+
|
|
255
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
256
|
+
is_set = (
|
|
257
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
258
|
+
or k in null_default_fields
|
|
259
|
+
) # pylint: disable=no-member
|
|
260
|
+
|
|
261
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
262
|
+
m[k] = val
|
|
263
|
+
elif val != UNSET_SENTINEL and (
|
|
264
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
265
|
+
):
|
|
266
|
+
m[k] = val
|
|
267
|
+
|
|
268
|
+
return m
|
|
269
|
+
|
|
270
|
+
|
|
32
271
|
class GetGenerationDataTypedDict(TypedDict):
|
|
33
272
|
r"""Generation data"""
|
|
34
273
|
|
|
@@ -98,6 +337,8 @@ class GetGenerationDataTypedDict(TypedDict):
|
|
|
98
337
|
r"""Type of API used for the generation"""
|
|
99
338
|
router: Nullable[str]
|
|
100
339
|
r"""Router used for the request (e.g., openrouter/auto)"""
|
|
340
|
+
provider_responses: Nullable[List[ProviderResponseTypedDict]]
|
|
341
|
+
r"""List of provider responses for this generation, including fallback attempts"""
|
|
101
342
|
|
|
102
343
|
|
|
103
344
|
class GetGenerationData(BaseModel):
|
|
@@ -202,6 +443,9 @@ class GetGenerationData(BaseModel):
|
|
|
202
443
|
router: Nullable[str]
|
|
203
444
|
r"""Router used for the request (e.g., openrouter/auto)"""
|
|
204
445
|
|
|
446
|
+
provider_responses: Nullable[List[ProviderResponse]]
|
|
447
|
+
r"""List of provider responses for this generation, including fallback attempts"""
|
|
448
|
+
|
|
205
449
|
@model_serializer(mode="wrap")
|
|
206
450
|
def serialize_model(self, handler):
|
|
207
451
|
optional_fields = []
|
|
@@ -232,6 +476,7 @@ class GetGenerationData(BaseModel):
|
|
|
232
476
|
"external_user",
|
|
233
477
|
"api_type",
|
|
234
478
|
"router",
|
|
479
|
+
"provider_responses",
|
|
235
480
|
]
|
|
236
481
|
null_default_fields = []
|
|
237
482
|
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from openrouter.types import (
|
|
5
|
+
BaseModel,
|
|
6
|
+
Nullable,
|
|
7
|
+
OptionalNullable,
|
|
8
|
+
UNSET,
|
|
9
|
+
UNSET_SENTINEL,
|
|
10
|
+
UnrecognizedStr,
|
|
11
|
+
)
|
|
12
|
+
from openrouter.utils import (
|
|
13
|
+
FieldMetadata,
|
|
14
|
+
HeaderMetadata,
|
|
15
|
+
PathParamMetadata,
|
|
16
|
+
validate_open_enum,
|
|
17
|
+
)
|
|
18
|
+
import pydantic
|
|
19
|
+
from pydantic import model_serializer
|
|
20
|
+
from pydantic.functional_validators import PlainValidator
|
|
21
|
+
from typing import List, Literal, Optional, Union
|
|
22
|
+
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class GetGuardrailGlobalsTypedDict(TypedDict):
|
|
26
|
+
http_referer: NotRequired[str]
|
|
27
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
28
|
+
This is used to track API usage per application.
|
|
29
|
+
|
|
30
|
+
"""
|
|
31
|
+
x_title: NotRequired[str]
|
|
32
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class GetGuardrailGlobals(BaseModel):
|
|
38
|
+
http_referer: Annotated[
|
|
39
|
+
Optional[str],
|
|
40
|
+
pydantic.Field(alias="HTTP-Referer"),
|
|
41
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
42
|
+
] = None
|
|
43
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
44
|
+
This is used to track API usage per application.
|
|
45
|
+
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
x_title: Annotated[
|
|
49
|
+
Optional[str],
|
|
50
|
+
pydantic.Field(alias="X-Title"),
|
|
51
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
52
|
+
] = None
|
|
53
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
54
|
+
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class GetGuardrailRequestTypedDict(TypedDict):
|
|
59
|
+
id: str
|
|
60
|
+
r"""The unique identifier of the guardrail to retrieve"""
|
|
61
|
+
http_referer: NotRequired[str]
|
|
62
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
63
|
+
This is used to track API usage per application.
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
x_title: NotRequired[str]
|
|
67
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
68
|
+
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class GetGuardrailRequest(BaseModel):
|
|
73
|
+
id: Annotated[
|
|
74
|
+
str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
|
|
75
|
+
]
|
|
76
|
+
r"""The unique identifier of the guardrail to retrieve"""
|
|
77
|
+
|
|
78
|
+
http_referer: Annotated[
|
|
79
|
+
Optional[str],
|
|
80
|
+
pydantic.Field(alias="HTTP-Referer"),
|
|
81
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
82
|
+
] = None
|
|
83
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
84
|
+
This is used to track API usage per application.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
x_title: Annotated[
|
|
89
|
+
Optional[str],
|
|
90
|
+
pydantic.Field(alias="X-Title"),
|
|
91
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
92
|
+
] = None
|
|
93
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
GetGuardrailResetInterval = Union[
|
|
99
|
+
Literal[
|
|
100
|
+
"daily",
|
|
101
|
+
"weekly",
|
|
102
|
+
"monthly",
|
|
103
|
+
],
|
|
104
|
+
UnrecognizedStr,
|
|
105
|
+
]
|
|
106
|
+
r"""Interval at which the limit resets (daily, weekly, monthly)"""
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
class GetGuardrailDataTypedDict(TypedDict):
|
|
110
|
+
r"""The guardrail"""
|
|
111
|
+
|
|
112
|
+
id: str
|
|
113
|
+
r"""Unique identifier for the guardrail"""
|
|
114
|
+
name: str
|
|
115
|
+
r"""Name of the guardrail"""
|
|
116
|
+
created_at: str
|
|
117
|
+
r"""ISO 8601 timestamp of when the guardrail was created"""
|
|
118
|
+
description: NotRequired[Nullable[str]]
|
|
119
|
+
r"""Description of the guardrail"""
|
|
120
|
+
limit_usd: NotRequired[Nullable[float]]
|
|
121
|
+
r"""Spending limit in USD"""
|
|
122
|
+
reset_interval: NotRequired[Nullable[GetGuardrailResetInterval]]
|
|
123
|
+
r"""Interval at which the limit resets (daily, weekly, monthly)"""
|
|
124
|
+
allowed_providers: NotRequired[Nullable[List[str]]]
|
|
125
|
+
r"""List of allowed provider IDs"""
|
|
126
|
+
allowed_models: NotRequired[Nullable[List[str]]]
|
|
127
|
+
r"""Array of model canonical_slugs (immutable identifiers)"""
|
|
128
|
+
enforce_zdr: NotRequired[Nullable[bool]]
|
|
129
|
+
r"""Whether to enforce zero data retention"""
|
|
130
|
+
updated_at: NotRequired[Nullable[str]]
|
|
131
|
+
r"""ISO 8601 timestamp of when the guardrail was last updated"""
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
class GetGuardrailData(BaseModel):
|
|
135
|
+
r"""The guardrail"""
|
|
136
|
+
|
|
137
|
+
id: str
|
|
138
|
+
r"""Unique identifier for the guardrail"""
|
|
139
|
+
|
|
140
|
+
name: str
|
|
141
|
+
r"""Name of the guardrail"""
|
|
142
|
+
|
|
143
|
+
created_at: str
|
|
144
|
+
r"""ISO 8601 timestamp of when the guardrail was created"""
|
|
145
|
+
|
|
146
|
+
description: OptionalNullable[str] = UNSET
|
|
147
|
+
r"""Description of the guardrail"""
|
|
148
|
+
|
|
149
|
+
limit_usd: OptionalNullable[float] = UNSET
|
|
150
|
+
r"""Spending limit in USD"""
|
|
151
|
+
|
|
152
|
+
reset_interval: Annotated[
|
|
153
|
+
OptionalNullable[GetGuardrailResetInterval],
|
|
154
|
+
PlainValidator(validate_open_enum(False)),
|
|
155
|
+
] = UNSET
|
|
156
|
+
r"""Interval at which the limit resets (daily, weekly, monthly)"""
|
|
157
|
+
|
|
158
|
+
allowed_providers: OptionalNullable[List[str]] = UNSET
|
|
159
|
+
r"""List of allowed provider IDs"""
|
|
160
|
+
|
|
161
|
+
allowed_models: OptionalNullable[List[str]] = UNSET
|
|
162
|
+
r"""Array of model canonical_slugs (immutable identifiers)"""
|
|
163
|
+
|
|
164
|
+
enforce_zdr: OptionalNullable[bool] = UNSET
|
|
165
|
+
r"""Whether to enforce zero data retention"""
|
|
166
|
+
|
|
167
|
+
updated_at: OptionalNullable[str] = UNSET
|
|
168
|
+
r"""ISO 8601 timestamp of when the guardrail was last updated"""
|
|
169
|
+
|
|
170
|
+
@model_serializer(mode="wrap")
|
|
171
|
+
def serialize_model(self, handler):
|
|
172
|
+
optional_fields = [
|
|
173
|
+
"description",
|
|
174
|
+
"limit_usd",
|
|
175
|
+
"reset_interval",
|
|
176
|
+
"allowed_providers",
|
|
177
|
+
"allowed_models",
|
|
178
|
+
"enforce_zdr",
|
|
179
|
+
"updated_at",
|
|
180
|
+
]
|
|
181
|
+
nullable_fields = [
|
|
182
|
+
"description",
|
|
183
|
+
"limit_usd",
|
|
184
|
+
"reset_interval",
|
|
185
|
+
"allowed_providers",
|
|
186
|
+
"allowed_models",
|
|
187
|
+
"enforce_zdr",
|
|
188
|
+
"updated_at",
|
|
189
|
+
]
|
|
190
|
+
null_default_fields = []
|
|
191
|
+
|
|
192
|
+
serialized = handler(self)
|
|
193
|
+
|
|
194
|
+
m = {}
|
|
195
|
+
|
|
196
|
+
for n, f in type(self).model_fields.items():
|
|
197
|
+
k = f.alias or n
|
|
198
|
+
val = serialized.get(k)
|
|
199
|
+
serialized.pop(k, None)
|
|
200
|
+
|
|
201
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
202
|
+
is_set = (
|
|
203
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
204
|
+
or k in null_default_fields
|
|
205
|
+
) # pylint: disable=no-member
|
|
206
|
+
|
|
207
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
208
|
+
m[k] = val
|
|
209
|
+
elif val != UNSET_SENTINEL and (
|
|
210
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
211
|
+
):
|
|
212
|
+
m[k] = val
|
|
213
|
+
|
|
214
|
+
return m
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
class GetGuardrailResponseTypedDict(TypedDict):
|
|
218
|
+
r"""Guardrail details"""
|
|
219
|
+
|
|
220
|
+
data: GetGuardrailDataTypedDict
|
|
221
|
+
r"""The guardrail"""
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
class GetGuardrailResponse(BaseModel):
|
|
225
|
+
r"""Guardrail details"""
|
|
226
|
+
|
|
227
|
+
data: GetGuardrailData
|
|
228
|
+
r"""The guardrail"""
|
openrouter/operations/getkey.py
CHANGED
|
@@ -9,14 +9,58 @@ from openrouter.types import (
|
|
|
9
9
|
UNSET,
|
|
10
10
|
UNSET_SENTINEL,
|
|
11
11
|
)
|
|
12
|
-
from openrouter.utils import FieldMetadata, PathParamMetadata
|
|
12
|
+
from openrouter.utils import FieldMetadata, HeaderMetadata, PathParamMetadata
|
|
13
|
+
import pydantic
|
|
13
14
|
from pydantic import model_serializer
|
|
15
|
+
from typing import Optional
|
|
14
16
|
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
15
17
|
|
|
16
18
|
|
|
19
|
+
class GetKeyGlobalsTypedDict(TypedDict):
|
|
20
|
+
http_referer: NotRequired[str]
|
|
21
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
22
|
+
This is used to track API usage per application.
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
x_title: NotRequired[str]
|
|
26
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class GetKeyGlobals(BaseModel):
|
|
32
|
+
http_referer: Annotated[
|
|
33
|
+
Optional[str],
|
|
34
|
+
pydantic.Field(alias="HTTP-Referer"),
|
|
35
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
36
|
+
] = None
|
|
37
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
38
|
+
This is used to track API usage per application.
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
x_title: Annotated[
|
|
43
|
+
Optional[str],
|
|
44
|
+
pydantic.Field(alias="X-Title"),
|
|
45
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
46
|
+
] = None
|
|
47
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
|
|
17
52
|
class GetKeyRequestTypedDict(TypedDict):
|
|
18
53
|
hash: str
|
|
19
54
|
r"""The hash identifier of the API key to retrieve"""
|
|
55
|
+
http_referer: NotRequired[str]
|
|
56
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
57
|
+
This is used to track API usage per application.
|
|
58
|
+
|
|
59
|
+
"""
|
|
60
|
+
x_title: NotRequired[str]
|
|
61
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
62
|
+
|
|
63
|
+
"""
|
|
20
64
|
|
|
21
65
|
|
|
22
66
|
class GetKeyRequest(BaseModel):
|
|
@@ -25,6 +69,25 @@ class GetKeyRequest(BaseModel):
|
|
|
25
69
|
]
|
|
26
70
|
r"""The hash identifier of the API key to retrieve"""
|
|
27
71
|
|
|
72
|
+
http_referer: Annotated[
|
|
73
|
+
Optional[str],
|
|
74
|
+
pydantic.Field(alias="HTTP-Referer"),
|
|
75
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
76
|
+
] = None
|
|
77
|
+
r"""The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
78
|
+
This is used to track API usage per application.
|
|
79
|
+
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
x_title: Annotated[
|
|
83
|
+
Optional[str],
|
|
84
|
+
pydantic.Field(alias="X-Title"),
|
|
85
|
+
FieldMetadata(header=HeaderMetadata(style="simple", explode=False)),
|
|
86
|
+
] = None
|
|
87
|
+
r"""The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
|
|
28
91
|
|
|
29
92
|
class GetKeyDataTypedDict(TypedDict):
|
|
30
93
|
r"""The API key information"""
|