openrouter 0.0.16__py3-none-any.whl → 0.0.18__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.
Files changed (85) hide show
  1. openrouter/_version.py +3 -3
  2. openrouter/analytics.py +2 -0
  3. openrouter/api_keys.py +24 -4
  4. openrouter/basesdk.py +6 -0
  5. openrouter/chat.py +212 -14
  6. openrouter/completions.py +2 -0
  7. openrouter/components/__init__.py +470 -106
  8. openrouter/components/_schema0.py +94 -0
  9. openrouter/components/_schema3.py +229 -0
  10. openrouter/components/chatgenerationparams.py +559 -16
  11. openrouter/components/chatgenerationtokenusage.py +3 -0
  12. openrouter/components/chatmessagecontentitem.py +2 -1
  13. openrouter/components/chatmessagecontentitemaudio.py +6 -25
  14. openrouter/components/chatmessagecontentitemcachecontrol.py +32 -0
  15. openrouter/components/chatmessagecontentitemtext.py +9 -2
  16. openrouter/components/chatmessagecontentitemvideo.py +50 -9
  17. openrouter/components/chatmessagetokenlogprob.py +4 -4
  18. openrouter/components/chatresponsechoice.py +6 -1
  19. openrouter/components/chatstreamingmessagechunk.py +12 -1
  20. openrouter/components/completionchoice.py +18 -5
  21. openrouter/components/completioncreateparams.py +10 -10
  22. openrouter/components/completionresponse.py +3 -0
  23. openrouter/components/datacollection.py +19 -0
  24. openrouter/components/message.py +10 -9
  25. openrouter/components/openairesponsesannotation.py +11 -4
  26. openrouter/components/openairesponsesreasoningeffort.py +2 -0
  27. openrouter/components/openresponseseasyinputmessage.py +93 -20
  28. openrouter/components/openresponsesinput.py +2 -2
  29. openrouter/components/openresponsesinputmessageitem.py +87 -14
  30. openrouter/components/openresponsesnonstreamingresponse.py +33 -19
  31. openrouter/components/openresponsesreasoning.py +2 -0
  32. openrouter/components/openresponsesrequest.py +246 -142
  33. openrouter/components/openresponsesstreamevent.py +110 -39
  34. openrouter/components/outputmessage.py +10 -4
  35. openrouter/components/parameter.py +1 -0
  36. openrouter/components/pdfparserengine.py +16 -0
  37. openrouter/components/pdfparseroptions.py +25 -0
  38. openrouter/components/percentilelatencycutoffs.py +71 -0
  39. openrouter/components/percentilestats.py +34 -0
  40. openrouter/components/percentilethroughputcutoffs.py +71 -0
  41. openrouter/components/preferredmaxlatency.py +21 -0
  42. openrouter/components/preferredminthroughput.py +22 -0
  43. openrouter/components/providername.py +11 -27
  44. openrouter/components/providerpreferences.py +355 -0
  45. openrouter/components/providersort.py +15 -0
  46. openrouter/components/providersortconfig.py +71 -0
  47. openrouter/components/providersortunion.py +23 -0
  48. openrouter/components/publicendpoint.py +61 -45
  49. openrouter/components/publicpricing.py +50 -45
  50. openrouter/components/responseformattextconfig.py +9 -7
  51. openrouter/components/responseinputvideo.py +26 -0
  52. openrouter/components/responseoutputtext.py +36 -1
  53. openrouter/components/responsesoutputitem.py +13 -11
  54. openrouter/components/responsesoutputitemreasoning.py +43 -3
  55. openrouter/components/responsesoutputmessage.py +10 -5
  56. openrouter/components/responsesoutputmodality.py +14 -0
  57. openrouter/components/websearchengine.py +15 -0
  58. openrouter/credits.py +4 -0
  59. openrouter/embeddings.py +34 -24
  60. openrouter/endpoints.py +4 -0
  61. openrouter/generations.py +2 -0
  62. openrouter/models/__init__.py +3 -0
  63. openrouter/models/internal/__init__.py +54 -0
  64. openrouter/models/internal/globals.py +41 -0
  65. openrouter/models_.py +6 -0
  66. openrouter/oauth.py +4 -0
  67. openrouter/operations/__init__.py +46 -49
  68. openrouter/operations/createembeddings.py +68 -264
  69. openrouter/operations/getcredits.py +19 -0
  70. openrouter/operations/getgeneration.py +6 -0
  71. openrouter/operations/getparameters.py +5 -77
  72. openrouter/operations/updatekeys.py +2 -2
  73. openrouter/parameters.py +4 -2
  74. openrouter/providers.py +2 -0
  75. openrouter/responses.py +188 -36
  76. openrouter/sdk.py +13 -0
  77. openrouter/sdkconfiguration.py +2 -0
  78. openrouter/utils/forms.py +21 -10
  79. openrouter/utils/queryparams.py +14 -2
  80. openrouter/utils/retries.py +69 -5
  81. {openrouter-0.0.16.dist-info → openrouter-0.0.18.dist-info}/METADATA +2 -1
  82. {openrouter-0.0.16.dist-info → openrouter-0.0.18.dist-info}/RECORD +85 -64
  83. {openrouter-0.0.16.dist-info → openrouter-0.0.18.dist-info}/WHEEL +0 -0
  84. {openrouter-0.0.16.dist-info → openrouter-0.0.18.dist-info}/licenses/LICENSE +0 -0
  85. {openrouter-0.0.16.dist-info → openrouter-0.0.18.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,355 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .datacollection import DataCollection
5
+ from .preferredmaxlatency import PreferredMaxLatency, PreferredMaxLatencyTypedDict
6
+ from .preferredminthroughput import (
7
+ PreferredMinThroughput,
8
+ PreferredMinThroughputTypedDict,
9
+ )
10
+ from .providername import ProviderName
11
+ from .providersort import ProviderSort
12
+ from .quantization import Quantization
13
+ from openrouter.types import (
14
+ BaseModel,
15
+ Nullable,
16
+ OptionalNullable,
17
+ UNSET,
18
+ UNSET_SENTINEL,
19
+ UnrecognizedStr,
20
+ )
21
+ from openrouter.utils import validate_open_enum
22
+ from pydantic import model_serializer
23
+ from pydantic.functional_validators import PlainValidator
24
+ from typing import List, Literal, Optional, Union
25
+ from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
26
+
27
+
28
+ ProviderPreferencesOrderTypedDict = TypeAliasType(
29
+ "ProviderPreferencesOrderTypedDict", Union[ProviderName, str]
30
+ )
31
+
32
+
33
+ ProviderPreferencesOrder = TypeAliasType(
34
+ "ProviderPreferencesOrder",
35
+ Union[Annotated[ProviderName, PlainValidator(validate_open_enum(False))], str],
36
+ )
37
+
38
+
39
+ ProviderPreferencesOnlyTypedDict = TypeAliasType(
40
+ "ProviderPreferencesOnlyTypedDict", Union[ProviderName, str]
41
+ )
42
+
43
+
44
+ ProviderPreferencesOnly = TypeAliasType(
45
+ "ProviderPreferencesOnly",
46
+ Union[Annotated[ProviderName, PlainValidator(validate_open_enum(False))], str],
47
+ )
48
+
49
+
50
+ ProviderPreferencesIgnoreTypedDict = TypeAliasType(
51
+ "ProviderPreferencesIgnoreTypedDict", Union[ProviderName, str]
52
+ )
53
+
54
+
55
+ ProviderPreferencesIgnore = TypeAliasType(
56
+ "ProviderPreferencesIgnore",
57
+ Union[Annotated[ProviderName, PlainValidator(validate_open_enum(False))], str],
58
+ )
59
+
60
+
61
+ SortEnum = Union[
62
+ Literal[
63
+ "price",
64
+ "throughput",
65
+ "latency",
66
+ ],
67
+ UnrecognizedStr,
68
+ ]
69
+
70
+
71
+ ProviderSortConfigEnum = Literal[
72
+ "price",
73
+ "throughput",
74
+ "latency",
75
+ ]
76
+
77
+
78
+ ProviderPreferencesPartition = Union[
79
+ Literal[
80
+ "model",
81
+ "none",
82
+ ],
83
+ UnrecognizedStr,
84
+ ]
85
+
86
+
87
+ class ProviderPreferencesProviderSortConfigTypedDict(TypedDict):
88
+ by: NotRequired[Nullable[ProviderSort]]
89
+ partition: NotRequired[Nullable[ProviderPreferencesPartition]]
90
+
91
+
92
+ class ProviderPreferencesProviderSortConfig(BaseModel):
93
+ by: Annotated[
94
+ OptionalNullable[ProviderSort], PlainValidator(validate_open_enum(False))
95
+ ] = UNSET
96
+
97
+ partition: Annotated[
98
+ OptionalNullable[ProviderPreferencesPartition],
99
+ PlainValidator(validate_open_enum(False)),
100
+ ] = UNSET
101
+
102
+ @model_serializer(mode="wrap")
103
+ def serialize_model(self, handler):
104
+ optional_fields = ["by", "partition"]
105
+ nullable_fields = ["by", "partition"]
106
+ null_default_fields = []
107
+
108
+ serialized = handler(self)
109
+
110
+ m = {}
111
+
112
+ for n, f in type(self).model_fields.items():
113
+ k = f.alias or n
114
+ val = serialized.get(k)
115
+ serialized.pop(k, None)
116
+
117
+ optional_nullable = k in optional_fields and k in nullable_fields
118
+ is_set = (
119
+ self.__pydantic_fields_set__.intersection({n})
120
+ or k in null_default_fields
121
+ ) # pylint: disable=no-member
122
+
123
+ if val is not None and val != UNSET_SENTINEL:
124
+ m[k] = val
125
+ elif val != UNSET_SENTINEL and (
126
+ not k in optional_fields or (optional_nullable and is_set)
127
+ ):
128
+ m[k] = val
129
+
130
+ return m
131
+
132
+
133
+ ProviderSortConfigUnionTypedDict = TypeAliasType(
134
+ "ProviderSortConfigUnionTypedDict",
135
+ Union[ProviderPreferencesProviderSortConfigTypedDict, ProviderSortConfigEnum],
136
+ )
137
+
138
+
139
+ ProviderSortConfigUnion = TypeAliasType(
140
+ "ProviderSortConfigUnion",
141
+ Union[ProviderPreferencesProviderSortConfig, ProviderSortConfigEnum],
142
+ )
143
+
144
+
145
+ ProviderPreferencesProviderSort = Union[
146
+ Literal[
147
+ "price",
148
+ "throughput",
149
+ "latency",
150
+ ],
151
+ UnrecognizedStr,
152
+ ]
153
+
154
+
155
+ ProviderPreferencesSortUnionTypedDict = TypeAliasType(
156
+ "ProviderPreferencesSortUnionTypedDict",
157
+ Union[ProviderPreferencesProviderSort, ProviderSortConfigUnionTypedDict, SortEnum],
158
+ )
159
+ r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
160
+
161
+
162
+ ProviderPreferencesSortUnion = TypeAliasType(
163
+ "ProviderPreferencesSortUnion",
164
+ Union[
165
+ Annotated[
166
+ ProviderPreferencesProviderSort, PlainValidator(validate_open_enum(False))
167
+ ],
168
+ ProviderSortConfigUnion,
169
+ Annotated[SortEnum, PlainValidator(validate_open_enum(False))],
170
+ ],
171
+ )
172
+ r"""The sorting strategy to use for this request, if \"order\" is not specified. When set, no load balancing is performed."""
173
+
174
+
175
+ class ProviderPreferencesMaxPriceTypedDict(TypedDict):
176
+ r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
177
+
178
+ prompt: NotRequired[str]
179
+ r"""A value in string format that is a large number"""
180
+ completion: NotRequired[str]
181
+ r"""A value in string format that is a large number"""
182
+ image: NotRequired[str]
183
+ r"""A value in string format that is a large number"""
184
+ audio: NotRequired[str]
185
+ r"""A value in string format that is a large number"""
186
+ request: NotRequired[str]
187
+ r"""A value in string format that is a large number"""
188
+
189
+
190
+ class ProviderPreferencesMaxPrice(BaseModel):
191
+ r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
192
+
193
+ prompt: Optional[str] = None
194
+ r"""A value in string format that is a large number"""
195
+
196
+ completion: Optional[str] = None
197
+ r"""A value in string format that is a large number"""
198
+
199
+ image: Optional[str] = None
200
+ r"""A value in string format that is a large number"""
201
+
202
+ audio: Optional[str] = None
203
+ r"""A value in string format that is a large number"""
204
+
205
+ request: Optional[str] = None
206
+ r"""A value in string format that is a large number"""
207
+
208
+
209
+ class ProviderPreferencesTypedDict(TypedDict):
210
+ r"""Provider routing preferences for the request."""
211
+
212
+ allow_fallbacks: NotRequired[Nullable[bool]]
213
+ r"""Whether to allow backup providers to serve requests
214
+ - true: (default) when the primary provider (or your custom providers in \"order\") is unavailable, use the next best provider.
215
+ - false: use only the primary/custom provider, and return the upstream error if it's unavailable.
216
+
217
+ """
218
+ require_parameters: NotRequired[Nullable[bool]]
219
+ r"""Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest."""
220
+ data_collection: NotRequired[Nullable[DataCollection]]
221
+ r"""Data collection setting. If no available model provider meets the requirement, your request will return an error.
222
+ - allow: (default) allow providers which store user data non-transiently and may train on it
223
+
224
+ - deny: use only providers which do not collect user data.
225
+ """
226
+ zdr: NotRequired[Nullable[bool]]
227
+ r"""Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used."""
228
+ enforce_distillable_text: NotRequired[Nullable[bool]]
229
+ r"""Whether to restrict routing to only models that allow text distillation. When true, only models where the author has allowed distillation will be used."""
230
+ order: NotRequired[Nullable[List[ProviderPreferencesOrderTypedDict]]]
231
+ r"""An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message."""
232
+ only: NotRequired[Nullable[List[ProviderPreferencesOnlyTypedDict]]]
233
+ r"""List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request."""
234
+ ignore: NotRequired[Nullable[List[ProviderPreferencesIgnoreTypedDict]]]
235
+ r"""List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request."""
236
+ quantizations: NotRequired[Nullable[List[Quantization]]]
237
+ r"""A list of quantization levels to filter the provider by."""
238
+ sort: NotRequired[Nullable[ProviderPreferencesSortUnionTypedDict]]
239
+ max_price: NotRequired[ProviderPreferencesMaxPriceTypedDict]
240
+ r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
241
+ preferred_min_throughput: NotRequired[Nullable[PreferredMinThroughputTypedDict]]
242
+ r"""Preferred minimum throughput (in tokens per second). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints below the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
243
+ preferred_max_latency: NotRequired[Nullable[PreferredMaxLatencyTypedDict]]
244
+ r"""Preferred maximum latency (in seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints above the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
245
+
246
+
247
+ class ProviderPreferences(BaseModel):
248
+ r"""Provider routing preferences for the request."""
249
+
250
+ allow_fallbacks: OptionalNullable[bool] = UNSET
251
+ r"""Whether to allow backup providers to serve requests
252
+ - true: (default) when the primary provider (or your custom providers in \"order\") is unavailable, use the next best provider.
253
+ - false: use only the primary/custom provider, and return the upstream error if it's unavailable.
254
+
255
+ """
256
+
257
+ require_parameters: OptionalNullable[bool] = UNSET
258
+ r"""Whether to filter providers to only those that support the parameters you've provided. If this setting is omitted or set to false, then providers will receive only the parameters they support, and ignore the rest."""
259
+
260
+ data_collection: Annotated[
261
+ OptionalNullable[DataCollection], PlainValidator(validate_open_enum(False))
262
+ ] = UNSET
263
+ r"""Data collection setting. If no available model provider meets the requirement, your request will return an error.
264
+ - allow: (default) allow providers which store user data non-transiently and may train on it
265
+
266
+ - deny: use only providers which do not collect user data.
267
+ """
268
+
269
+ zdr: OptionalNullable[bool] = UNSET
270
+ r"""Whether to restrict routing to only ZDR (Zero Data Retention) endpoints. When true, only endpoints that do not retain prompts will be used."""
271
+
272
+ enforce_distillable_text: OptionalNullable[bool] = UNSET
273
+ r"""Whether to restrict routing to only models that allow text distillation. When true, only models where the author has allowed distillation will be used."""
274
+
275
+ order: OptionalNullable[List[ProviderPreferencesOrder]] = UNSET
276
+ r"""An ordered list of provider slugs. The router will attempt to use the first provider in the subset of this list that supports your requested model, and fall back to the next if it is unavailable. If no providers are available, the request will fail with an error message."""
277
+
278
+ only: OptionalNullable[List[ProviderPreferencesOnly]] = UNSET
279
+ r"""List of provider slugs to allow. If provided, this list is merged with your account-wide allowed provider settings for this request."""
280
+
281
+ ignore: OptionalNullable[List[ProviderPreferencesIgnore]] = UNSET
282
+ r"""List of provider slugs to ignore. If provided, this list is merged with your account-wide ignored provider settings for this request."""
283
+
284
+ quantizations: OptionalNullable[
285
+ List[Annotated[Quantization, PlainValidator(validate_open_enum(False))]]
286
+ ] = UNSET
287
+ r"""A list of quantization levels to filter the provider by."""
288
+
289
+ sort: OptionalNullable[ProviderPreferencesSortUnion] = UNSET
290
+
291
+ max_price: Optional[ProviderPreferencesMaxPrice] = None
292
+ r"""The object specifying the maximum price you want to pay for this request. USD price per million tokens, for prompt and completion."""
293
+
294
+ preferred_min_throughput: OptionalNullable[PreferredMinThroughput] = UNSET
295
+ r"""Preferred minimum throughput (in tokens per second). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints below the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
296
+
297
+ preferred_max_latency: OptionalNullable[PreferredMaxLatency] = UNSET
298
+ r"""Preferred maximum latency (in seconds). Can be a number (applies to p50) or an object with percentile-specific cutoffs. Endpoints above the threshold(s) may still be used, but are deprioritized in routing. When using fallback models, this may cause a fallback model to be used instead of the primary model if it meets the threshold."""
299
+
300
+ @model_serializer(mode="wrap")
301
+ def serialize_model(self, handler):
302
+ optional_fields = [
303
+ "allow_fallbacks",
304
+ "require_parameters",
305
+ "data_collection",
306
+ "zdr",
307
+ "enforce_distillable_text",
308
+ "order",
309
+ "only",
310
+ "ignore",
311
+ "quantizations",
312
+ "sort",
313
+ "max_price",
314
+ "preferred_min_throughput",
315
+ "preferred_max_latency",
316
+ ]
317
+ nullable_fields = [
318
+ "allow_fallbacks",
319
+ "require_parameters",
320
+ "data_collection",
321
+ "zdr",
322
+ "enforce_distillable_text",
323
+ "order",
324
+ "only",
325
+ "ignore",
326
+ "quantizations",
327
+ "sort",
328
+ "preferred_min_throughput",
329
+ "preferred_max_latency",
330
+ ]
331
+ null_default_fields = []
332
+
333
+ serialized = handler(self)
334
+
335
+ m = {}
336
+
337
+ for n, f in type(self).model_fields.items():
338
+ k = f.alias or n
339
+ val = serialized.get(k)
340
+ serialized.pop(k, None)
341
+
342
+ optional_nullable = k in optional_fields and k in nullable_fields
343
+ is_set = (
344
+ self.__pydantic_fields_set__.intersection({n})
345
+ or k in null_default_fields
346
+ ) # pylint: disable=no-member
347
+
348
+ if val is not None and val != UNSET_SENTINEL:
349
+ m[k] = val
350
+ elif val != UNSET_SENTINEL and (
351
+ not k in optional_fields or (optional_nullable and is_set)
352
+ ):
353
+ m[k] = val
354
+
355
+ return m
@@ -0,0 +1,15 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from openrouter.types import UnrecognizedStr
5
+ from typing import Literal, Union
6
+
7
+
8
+ ProviderSort = Union[
9
+ Literal[
10
+ "price",
11
+ "throughput",
12
+ "latency",
13
+ ],
14
+ UnrecognizedStr,
15
+ ]
@@ -0,0 +1,71 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .providersort import ProviderSort
5
+ from openrouter.types import (
6
+ BaseModel,
7
+ Nullable,
8
+ OptionalNullable,
9
+ UNSET,
10
+ UNSET_SENTINEL,
11
+ UnrecognizedStr,
12
+ )
13
+ from openrouter.utils import validate_open_enum
14
+ from pydantic import model_serializer
15
+ from pydantic.functional_validators import PlainValidator
16
+ from typing import Literal, Union
17
+ from typing_extensions import Annotated, NotRequired, TypedDict
18
+
19
+
20
+ Partition = Union[
21
+ Literal[
22
+ "model",
23
+ "none",
24
+ ],
25
+ UnrecognizedStr,
26
+ ]
27
+
28
+
29
+ class ProviderSortConfigTypedDict(TypedDict):
30
+ by: NotRequired[Nullable[ProviderSort]]
31
+ partition: NotRequired[Nullable[Partition]]
32
+
33
+
34
+ class ProviderSortConfig(BaseModel):
35
+ by: Annotated[
36
+ OptionalNullable[ProviderSort], PlainValidator(validate_open_enum(False))
37
+ ] = UNSET
38
+
39
+ partition: Annotated[
40
+ OptionalNullable[Partition], PlainValidator(validate_open_enum(False))
41
+ ] = UNSET
42
+
43
+ @model_serializer(mode="wrap")
44
+ def serialize_model(self, handler):
45
+ optional_fields = ["by", "partition"]
46
+ nullable_fields = ["by", "partition"]
47
+ null_default_fields = []
48
+
49
+ serialized = handler(self)
50
+
51
+ m = {}
52
+
53
+ for n, f in type(self).model_fields.items():
54
+ k = f.alias or n
55
+ val = serialized.get(k)
56
+ serialized.pop(k, None)
57
+
58
+ optional_nullable = k in optional_fields and k in nullable_fields
59
+ is_set = (
60
+ self.__pydantic_fields_set__.intersection({n})
61
+ or k in null_default_fields
62
+ ) # pylint: disable=no-member
63
+
64
+ if val is not None and val != UNSET_SENTINEL:
65
+ m[k] = val
66
+ elif val != UNSET_SENTINEL and (
67
+ not k in optional_fields or (optional_nullable and is_set)
68
+ ):
69
+ m[k] = val
70
+
71
+ return m
@@ -0,0 +1,23 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from __future__ import annotations
4
+ from .providersort import ProviderSort
5
+ from .providersortconfig import ProviderSortConfig, ProviderSortConfigTypedDict
6
+ from openrouter.utils import validate_open_enum
7
+ from pydantic.functional_validators import PlainValidator
8
+ from typing import Union
9
+ from typing_extensions import Annotated, TypeAliasType
10
+
11
+
12
+ ProviderSortUnionTypedDict = TypeAliasType(
13
+ "ProviderSortUnionTypedDict", Union[ProviderSortConfigTypedDict, ProviderSort]
14
+ )
15
+
16
+
17
+ ProviderSortUnion = TypeAliasType(
18
+ "ProviderSortUnion",
19
+ Union[
20
+ ProviderSortConfig,
21
+ Annotated[ProviderSort, PlainValidator(validate_open_enum(False))],
22
+ ],
23
+ )
@@ -3,74 +3,80 @@
3
3
  from __future__ import annotations
4
4
  from .endpointstatus import EndpointStatus
5
5
  from .parameter import Parameter
6
+ from .percentilestats import PercentileStats, PercentileStatsTypedDict
6
7
  from .providername import ProviderName
7
8
  from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedStr
8
9
  from openrouter.utils import validate_open_enum
9
10
  from pydantic import model_serializer
10
11
  from pydantic.functional_validators import PlainValidator
11
- from typing import Any, List, Literal, Optional, Union
12
+ from typing import List, Literal, Optional, Union
12
13
  from typing_extensions import Annotated, NotRequired, TypedDict
13
14
 
14
15
 
15
16
  class PricingTypedDict(TypedDict):
16
- prompt: Any
17
- r"""A value in string or number format that is a large number"""
18
- completion: Any
19
- r"""A value in string or number format that is a large number"""
20
- request: NotRequired[Any]
21
- r"""A value in string or number format that is a large number"""
22
- image: NotRequired[Any]
23
- r"""A value in string or number format that is a large number"""
24
- image_output: NotRequired[Any]
25
- r"""A value in string or number format that is a large number"""
26
- audio: NotRequired[Any]
27
- r"""A value in string or number format that is a large number"""
28
- input_audio_cache: NotRequired[Any]
29
- r"""A value in string or number format that is a large number"""
30
- web_search: NotRequired[Any]
31
- r"""A value in string or number format that is a large number"""
32
- internal_reasoning: NotRequired[Any]
33
- r"""A value in string or number format that is a large number"""
34
- input_cache_read: NotRequired[Any]
35
- r"""A value in string or number format that is a large number"""
36
- input_cache_write: NotRequired[Any]
37
- r"""A value in string or number format that is a large number"""
17
+ prompt: str
18
+ r"""A value in string format that is a large number"""
19
+ completion: str
20
+ r"""A value in string format that is a large number"""
21
+ request: NotRequired[str]
22
+ r"""A value in string format that is a large number"""
23
+ image: NotRequired[str]
24
+ r"""A value in string format that is a large number"""
25
+ image_token: NotRequired[str]
26
+ r"""A value in string format that is a large number"""
27
+ image_output: NotRequired[str]
28
+ r"""A value in string format that is a large number"""
29
+ audio: NotRequired[str]
30
+ r"""A value in string format that is a large number"""
31
+ input_audio_cache: NotRequired[str]
32
+ r"""A value in string format that is a large number"""
33
+ web_search: NotRequired[str]
34
+ r"""A value in string format that is a large number"""
35
+ internal_reasoning: NotRequired[str]
36
+ r"""A value in string format that is a large number"""
37
+ input_cache_read: NotRequired[str]
38
+ r"""A value in string format that is a large number"""
39
+ input_cache_write: NotRequired[str]
40
+ r"""A value in string format that is a large number"""
38
41
  discount: NotRequired[float]
39
42
 
40
43
 
41
44
  class Pricing(BaseModel):
42
- prompt: Any
43
- r"""A value in string or number format that is a large number"""
45
+ prompt: str
46
+ r"""A value in string format that is a large number"""
44
47
 
45
- completion: Any
46
- r"""A value in string or number format that is a large number"""
48
+ completion: str
49
+ r"""A value in string format that is a large number"""
47
50
 
48
- request: Optional[Any] = None
49
- r"""A value in string or number format that is a large number"""
51
+ request: Optional[str] = None
52
+ r"""A value in string format that is a large number"""
50
53
 
51
- image: Optional[Any] = None
52
- r"""A value in string or number format that is a large number"""
54
+ image: Optional[str] = None
55
+ r"""A value in string format that is a large number"""
53
56
 
54
- image_output: Optional[Any] = None
55
- r"""A value in string or number format that is a large number"""
57
+ image_token: Optional[str] = None
58
+ r"""A value in string format that is a large number"""
56
59
 
57
- audio: Optional[Any] = None
58
- r"""A value in string or number format that is a large number"""
60
+ image_output: Optional[str] = None
61
+ r"""A value in string format that is a large number"""
59
62
 
60
- input_audio_cache: Optional[Any] = None
61
- r"""A value in string or number format that is a large number"""
63
+ audio: Optional[str] = None
64
+ r"""A value in string format that is a large number"""
62
65
 
63
- web_search: Optional[Any] = None
64
- r"""A value in string or number format that is a large number"""
66
+ input_audio_cache: Optional[str] = None
67
+ r"""A value in string format that is a large number"""
65
68
 
66
- internal_reasoning: Optional[Any] = None
67
- r"""A value in string or number format that is a large number"""
69
+ web_search: Optional[str] = None
70
+ r"""A value in string format that is a large number"""
68
71
 
69
- input_cache_read: Optional[Any] = None
70
- r"""A value in string or number format that is a large number"""
72
+ internal_reasoning: Optional[str] = None
73
+ r"""A value in string format that is a large number"""
71
74
 
72
- input_cache_write: Optional[Any] = None
73
- r"""A value in string or number format that is a large number"""
75
+ input_cache_read: Optional[str] = None
76
+ r"""A value in string format that is a large number"""
77
+
78
+ input_cache_write: Optional[str] = None
79
+ r"""A value in string format that is a large number"""
74
80
 
75
81
  discount: Optional[float] = None
76
82
 
@@ -106,6 +112,9 @@ class PublicEndpointTypedDict(TypedDict):
106
112
  supported_parameters: List[Parameter]
107
113
  uptime_last_30m: Nullable[float]
108
114
  supports_implicit_caching: bool
115
+ latency_last_30m: Nullable[PercentileStatsTypedDict]
116
+ r"""Latency percentiles in milliseconds over the last 30 minutes. Latency measures time to first token. Only visible when authenticated with an API key or cookie; returns null for unauthenticated requests."""
117
+ throughput_last_30m: Nullable[PercentileStatsTypedDict]
109
118
  status: NotRequired[EndpointStatus]
110
119
 
111
120
 
@@ -140,6 +149,11 @@ class PublicEndpoint(BaseModel):
140
149
 
141
150
  supports_implicit_caching: bool
142
151
 
152
+ latency_last_30m: Nullable[PercentileStats]
153
+ r"""Latency percentiles in milliseconds over the last 30 minutes. Latency measures time to first token. Only visible when authenticated with an API key or cookie; returns null for unauthenticated requests."""
154
+
155
+ throughput_last_30m: Nullable[PercentileStats]
156
+
143
157
  status: Annotated[
144
158
  Optional[EndpointStatus], PlainValidator(validate_open_enum(True))
145
159
  ] = None
@@ -152,6 +166,8 @@ class PublicEndpoint(BaseModel):
152
166
  "max_completion_tokens",
153
167
  "max_prompt_tokens",
154
168
  "uptime_last_30m",
169
+ "latency_last_30m",
170
+ "throughput_last_30m",
155
171
  ]
156
172
  null_default_fields = []
157
173