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.
Files changed (84) hide show
  1. openrouter/_version.py +2 -2
  2. openrouter/analytics.py +28 -2
  3. openrouter/api_keys.py +210 -14
  4. openrouter/chat.py +192 -200
  5. openrouter/components/__init__.py +229 -285
  6. openrouter/components/_schema10.py +39 -0
  7. openrouter/components/_schema14.py +11 -0
  8. openrouter/components/_schema17.py +154 -0
  9. openrouter/components/{_schema3.py → _schema19.py} +28 -22
  10. openrouter/components/{_schema0.py → _schema5.py} +7 -5
  11. openrouter/components/assistantmessage.py +32 -1
  12. openrouter/components/chatgenerationparams.py +57 -343
  13. openrouter/components/chatmessagecontentitemimage.py +4 -4
  14. openrouter/components/chatresponsechoice.py +1 -6
  15. openrouter/components/chatstreamingmessagechunk.py +3 -3
  16. openrouter/components/developermessage.py +41 -0
  17. openrouter/components/message.py +6 -39
  18. openrouter/components/model.py +7 -1
  19. openrouter/components/openresponsesrequest.py +31 -39
  20. openrouter/components/outputmodality.py +1 -0
  21. openrouter/components/providername.py +2 -0
  22. openrouter/components/providerpreferences.py +2 -10
  23. openrouter/components/publicendpoint.py +8 -24
  24. openrouter/components/publicpricing.py +3 -24
  25. openrouter/credits.py +86 -14
  26. openrouter/embeddings.py +92 -20
  27. openrouter/endpoints.py +62 -2
  28. openrouter/generations.py +26 -0
  29. openrouter/guardrails.py +3367 -0
  30. openrouter/models_.py +120 -12
  31. openrouter/oauth.py +90 -22
  32. openrouter/operations/__init__.py +601 -30
  33. openrouter/operations/bulkassignkeystoguardrail.py +116 -0
  34. openrouter/operations/bulkassignmemberstoguardrail.py +116 -0
  35. openrouter/operations/bulkunassignkeysfromguardrail.py +116 -0
  36. openrouter/operations/bulkunassignmembersfromguardrail.py +116 -0
  37. openrouter/operations/createauthkeyscode.py +81 -3
  38. openrouter/operations/createcoinbasecharge.py +82 -2
  39. openrouter/operations/createembeddings.py +82 -3
  40. openrouter/operations/createguardrail.py +325 -0
  41. openrouter/operations/createkeys.py +81 -3
  42. openrouter/operations/createresponses.py +84 -3
  43. openrouter/operations/deleteguardrail.py +104 -0
  44. openrouter/operations/deletekeys.py +69 -3
  45. openrouter/operations/exchangeauthcodeforapikey.py +81 -3
  46. openrouter/operations/getcredits.py +70 -1
  47. openrouter/operations/getcurrentkey.py +81 -3
  48. openrouter/operations/getgeneration.py +248 -3
  49. openrouter/operations/getguardrail.py +228 -0
  50. openrouter/operations/getkey.py +64 -1
  51. openrouter/operations/getmodels.py +95 -5
  52. openrouter/operations/getuseractivity.py +62 -1
  53. openrouter/operations/list.py +63 -1
  54. openrouter/operations/listembeddingsmodels.py +74 -0
  55. openrouter/operations/listendpoints.py +65 -2
  56. openrouter/operations/listendpointszdr.py +70 -2
  57. openrouter/operations/listguardrailkeyassignments.py +192 -0
  58. openrouter/operations/listguardrailmemberassignments.py +187 -0
  59. openrouter/operations/listguardrails.py +238 -0
  60. openrouter/operations/listkeyassignments.py +180 -0
  61. openrouter/operations/listmemberassignments.py +175 -0
  62. openrouter/operations/listmodelscount.py +74 -0
  63. openrouter/operations/listmodelsuser.py +70 -2
  64. openrouter/operations/listproviders.py +70 -2
  65. openrouter/operations/sendchatcompletionrequest.py +87 -3
  66. openrouter/operations/updateguardrail.py +334 -0
  67. openrouter/operations/updatekeys.py +63 -0
  68. openrouter/providers.py +36 -2
  69. openrouter/responses.py +178 -148
  70. openrouter/sdk.py +5 -8
  71. openrouter/types/models.py +378 -0
  72. {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/METADATA +5 -1
  73. {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/RECORD +76 -63
  74. {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/WHEEL +1 -1
  75. openrouter/completions.py +0 -361
  76. openrouter/components/completionchoice.py +0 -82
  77. openrouter/components/completioncreateparams.py +0 -277
  78. openrouter/components/completionlogprobs.py +0 -54
  79. openrouter/components/completionresponse.py +0 -46
  80. openrouter/components/completionusage.py +0 -19
  81. openrouter/operations/getparameters.py +0 -123
  82. openrouter/parameters.py +0 -237
  83. {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/licenses/LICENSE +0 -0
  84. {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/top_level.txt +0 -0
@@ -1,277 +0,0 @@
1
- """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
-
3
- from __future__ import annotations
4
- from .responseformatjsonschema import (
5
- ResponseFormatJSONSchema,
6
- ResponseFormatJSONSchemaTypedDict,
7
- )
8
- from .responseformattextgrammar import (
9
- ResponseFormatTextGrammar,
10
- ResponseFormatTextGrammarTypedDict,
11
- )
12
- from openrouter.types import (
13
- BaseModel,
14
- Nullable,
15
- OptionalNullable,
16
- UNSET,
17
- UNSET_SENTINEL,
18
- )
19
- from openrouter.utils import get_discriminator, validate_const
20
- import pydantic
21
- from pydantic import Discriminator, Tag, model_serializer
22
- from pydantic.functional_validators import AfterValidator
23
- from typing import Dict, List, Literal, Optional, Union
24
- from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
25
-
26
-
27
- PromptTypedDict = TypeAliasType(
28
- "PromptTypedDict", Union[str, List[str], List[float], List[List[float]]]
29
- )
30
-
31
-
32
- Prompt = TypeAliasType("Prompt", Union[str, List[str], List[float], List[List[float]]])
33
-
34
-
35
- CompletionCreateParamsStopTypedDict = TypeAliasType(
36
- "CompletionCreateParamsStopTypedDict", Union[str, List[str]]
37
- )
38
-
39
-
40
- CompletionCreateParamsStop = TypeAliasType(
41
- "CompletionCreateParamsStop", Union[str, List[str]]
42
- )
43
-
44
-
45
- class StreamOptionsTypedDict(TypedDict):
46
- include_usage: NotRequired[Nullable[bool]]
47
-
48
-
49
- class StreamOptions(BaseModel):
50
- include_usage: OptionalNullable[bool] = UNSET
51
-
52
- @model_serializer(mode="wrap")
53
- def serialize_model(self, handler):
54
- optional_fields = ["include_usage"]
55
- nullable_fields = ["include_usage"]
56
- null_default_fields = []
57
-
58
- serialized = handler(self)
59
-
60
- m = {}
61
-
62
- for n, f in type(self).model_fields.items():
63
- k = f.alias or n
64
- val = serialized.get(k)
65
- serialized.pop(k, None)
66
-
67
- optional_nullable = k in optional_fields and k in nullable_fields
68
- is_set = (
69
- self.__pydantic_fields_set__.intersection({n})
70
- or k in null_default_fields
71
- ) # pylint: disable=no-member
72
-
73
- if val is not None and val != UNSET_SENTINEL:
74
- m[k] = val
75
- elif val != UNSET_SENTINEL and (
76
- not k in optional_fields or (optional_nullable and is_set)
77
- ):
78
- m[k] = val
79
-
80
- return m
81
-
82
-
83
- class CompletionCreateParamsResponseFormatPythonTypedDict(TypedDict):
84
- type: Literal["python"]
85
-
86
-
87
- class CompletionCreateParamsResponseFormatPython(BaseModel):
88
- TYPE: Annotated[
89
- Annotated[Literal["python"], AfterValidator(validate_const("python"))],
90
- pydantic.Field(alias="type"),
91
- ] = "python"
92
-
93
-
94
- class CompletionCreateParamsResponseFormatJSONObjectTypedDict(TypedDict):
95
- type: Literal["json_object"]
96
-
97
-
98
- class CompletionCreateParamsResponseFormatJSONObject(BaseModel):
99
- TYPE: Annotated[
100
- Annotated[
101
- Literal["json_object"], AfterValidator(validate_const("json_object"))
102
- ],
103
- pydantic.Field(alias="type"),
104
- ] = "json_object"
105
-
106
-
107
- class CompletionCreateParamsResponseFormatTextTypedDict(TypedDict):
108
- type: Literal["text"]
109
-
110
-
111
- class CompletionCreateParamsResponseFormatText(BaseModel):
112
- TYPE: Annotated[
113
- Annotated[Literal["text"], AfterValidator(validate_const("text"))],
114
- pydantic.Field(alias="type"),
115
- ] = "text"
116
-
117
-
118
- CompletionCreateParamsResponseFormatUnionTypedDict = TypeAliasType(
119
- "CompletionCreateParamsResponseFormatUnionTypedDict",
120
- Union[
121
- CompletionCreateParamsResponseFormatTextTypedDict,
122
- CompletionCreateParamsResponseFormatJSONObjectTypedDict,
123
- CompletionCreateParamsResponseFormatPythonTypedDict,
124
- ResponseFormatJSONSchemaTypedDict,
125
- ResponseFormatTextGrammarTypedDict,
126
- ],
127
- )
128
-
129
-
130
- CompletionCreateParamsResponseFormatUnion = Annotated[
131
- Union[
132
- Annotated[CompletionCreateParamsResponseFormatText, Tag("text")],
133
- Annotated[CompletionCreateParamsResponseFormatJSONObject, Tag("json_object")],
134
- Annotated[ResponseFormatJSONSchema, Tag("json_schema")],
135
- Annotated[ResponseFormatTextGrammar, Tag("grammar")],
136
- Annotated[CompletionCreateParamsResponseFormatPython, Tag("python")],
137
- ],
138
- Discriminator(lambda m: get_discriminator(m, "type", "type")),
139
- ]
140
-
141
-
142
- class CompletionCreateParamsTypedDict(TypedDict):
143
- prompt: PromptTypedDict
144
- model: NotRequired[str]
145
- models: NotRequired[List[str]]
146
- best_of: NotRequired[Nullable[int]]
147
- echo: NotRequired[Nullable[bool]]
148
- frequency_penalty: NotRequired[Nullable[float]]
149
- logit_bias: NotRequired[Nullable[Dict[str, float]]]
150
- logprobs: NotRequired[Nullable[int]]
151
- max_tokens: NotRequired[Nullable[int]]
152
- n: NotRequired[Nullable[int]]
153
- presence_penalty: NotRequired[Nullable[float]]
154
- seed: NotRequired[Nullable[int]]
155
- stop: NotRequired[Nullable[CompletionCreateParamsStopTypedDict]]
156
- stream: NotRequired[bool]
157
- stream_options: NotRequired[Nullable[StreamOptionsTypedDict]]
158
- suffix: NotRequired[Nullable[str]]
159
- temperature: NotRequired[Nullable[float]]
160
- top_p: NotRequired[Nullable[float]]
161
- user: NotRequired[str]
162
- metadata: NotRequired[Nullable[Dict[str, str]]]
163
- response_format: NotRequired[
164
- Nullable[CompletionCreateParamsResponseFormatUnionTypedDict]
165
- ]
166
-
167
-
168
- class CompletionCreateParams(BaseModel):
169
- prompt: Prompt
170
-
171
- model: Optional[str] = None
172
-
173
- models: Optional[List[str]] = None
174
-
175
- best_of: OptionalNullable[int] = UNSET
176
-
177
- echo: OptionalNullable[bool] = UNSET
178
-
179
- frequency_penalty: OptionalNullable[float] = UNSET
180
-
181
- logit_bias: OptionalNullable[Dict[str, float]] = UNSET
182
-
183
- logprobs: OptionalNullable[int] = UNSET
184
-
185
- max_tokens: OptionalNullable[int] = UNSET
186
-
187
- n: OptionalNullable[int] = UNSET
188
-
189
- presence_penalty: OptionalNullable[float] = UNSET
190
-
191
- seed: OptionalNullable[int] = UNSET
192
-
193
- stop: OptionalNullable[CompletionCreateParamsStop] = UNSET
194
-
195
- stream: Optional[bool] = False
196
-
197
- stream_options: OptionalNullable[StreamOptions] = UNSET
198
-
199
- suffix: OptionalNullable[str] = UNSET
200
-
201
- temperature: OptionalNullable[float] = UNSET
202
-
203
- top_p: OptionalNullable[float] = UNSET
204
-
205
- user: Optional[str] = None
206
-
207
- metadata: OptionalNullable[Dict[str, str]] = UNSET
208
-
209
- response_format: OptionalNullable[CompletionCreateParamsResponseFormatUnion] = UNSET
210
-
211
- @model_serializer(mode="wrap")
212
- def serialize_model(self, handler):
213
- optional_fields = [
214
- "model",
215
- "models",
216
- "best_of",
217
- "echo",
218
- "frequency_penalty",
219
- "logit_bias",
220
- "logprobs",
221
- "max_tokens",
222
- "n",
223
- "presence_penalty",
224
- "seed",
225
- "stop",
226
- "stream",
227
- "stream_options",
228
- "suffix",
229
- "temperature",
230
- "top_p",
231
- "user",
232
- "metadata",
233
- "response_format",
234
- ]
235
- nullable_fields = [
236
- "best_of",
237
- "echo",
238
- "frequency_penalty",
239
- "logit_bias",
240
- "logprobs",
241
- "max_tokens",
242
- "n",
243
- "presence_penalty",
244
- "seed",
245
- "stop",
246
- "stream_options",
247
- "suffix",
248
- "temperature",
249
- "top_p",
250
- "metadata",
251
- "response_format",
252
- ]
253
- null_default_fields = []
254
-
255
- serialized = handler(self)
256
-
257
- m = {}
258
-
259
- for n, f in type(self).model_fields.items():
260
- k = f.alias or n
261
- val = serialized.get(k)
262
- serialized.pop(k, None)
263
-
264
- optional_nullable = k in optional_fields and k in nullable_fields
265
- is_set = (
266
- self.__pydantic_fields_set__.intersection({n})
267
- or k in null_default_fields
268
- ) # pylint: disable=no-member
269
-
270
- if val is not None and val != UNSET_SENTINEL:
271
- m[k] = val
272
- elif val != UNSET_SENTINEL and (
273
- not k in optional_fields or (optional_nullable and is_set)
274
- ):
275
- m[k] = val
276
-
277
- return m
@@ -1,54 +0,0 @@
1
- """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
-
3
- from __future__ import annotations
4
- from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL
5
- from pydantic import model_serializer
6
- from typing import Dict, List
7
- from typing_extensions import TypedDict
8
-
9
-
10
- class CompletionLogprobsTypedDict(TypedDict):
11
- tokens: List[str]
12
- token_logprobs: List[float]
13
- top_logprobs: Nullable[List[Dict[str, float]]]
14
- text_offset: List[float]
15
-
16
-
17
- class CompletionLogprobs(BaseModel):
18
- tokens: List[str]
19
-
20
- token_logprobs: List[float]
21
-
22
- top_logprobs: Nullable[List[Dict[str, float]]]
23
-
24
- text_offset: List[float]
25
-
26
- @model_serializer(mode="wrap")
27
- def serialize_model(self, handler):
28
- optional_fields = []
29
- nullable_fields = ["top_logprobs"]
30
- null_default_fields = []
31
-
32
- serialized = handler(self)
33
-
34
- m = {}
35
-
36
- for n, f in type(self).model_fields.items():
37
- k = f.alias or n
38
- val = serialized.get(k)
39
- serialized.pop(k, None)
40
-
41
- optional_nullable = k in optional_fields and k in nullable_fields
42
- is_set = (
43
- self.__pydantic_fields_set__.intersection({n})
44
- or k in null_default_fields
45
- ) # pylint: disable=no-member
46
-
47
- if val is not None and val != UNSET_SENTINEL:
48
- m[k] = val
49
- elif val != UNSET_SENTINEL and (
50
- not k in optional_fields or (optional_nullable and is_set)
51
- ):
52
- m[k] = val
53
-
54
- return m
@@ -1,46 +0,0 @@
1
- """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
-
3
- from __future__ import annotations
4
- from .completionchoice import CompletionChoice, CompletionChoiceTypedDict
5
- from .completionusage import CompletionUsage, CompletionUsageTypedDict
6
- from openrouter.types import BaseModel
7
- from openrouter.utils import validate_const
8
- import pydantic
9
- from pydantic.functional_validators import AfterValidator
10
- from typing import List, Literal, Optional
11
- from typing_extensions import Annotated, NotRequired, TypedDict
12
-
13
-
14
- class CompletionResponseTypedDict(TypedDict):
15
- id: str
16
- created: float
17
- model: str
18
- choices: List[CompletionChoiceTypedDict]
19
- object: Literal["text_completion"]
20
- provider: NotRequired[str]
21
- system_fingerprint: NotRequired[str]
22
- usage: NotRequired[CompletionUsageTypedDict]
23
-
24
-
25
- class CompletionResponse(BaseModel):
26
- id: str
27
-
28
- created: float
29
-
30
- model: str
31
-
32
- choices: List[CompletionChoice]
33
-
34
- OBJECT: Annotated[
35
- Annotated[
36
- Literal["text_completion"],
37
- AfterValidator(validate_const("text_completion")),
38
- ],
39
- pydantic.Field(alias="object"),
40
- ] = "text_completion"
41
-
42
- provider: Optional[str] = None
43
-
44
- system_fingerprint: Optional[str] = None
45
-
46
- usage: Optional[CompletionUsage] = None
@@ -1,19 +0,0 @@
1
- """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
-
3
- from __future__ import annotations
4
- from openrouter.types import BaseModel
5
- from typing_extensions import TypedDict
6
-
7
-
8
- class CompletionUsageTypedDict(TypedDict):
9
- prompt_tokens: float
10
- completion_tokens: float
11
- total_tokens: float
12
-
13
-
14
- class CompletionUsage(BaseModel):
15
- prompt_tokens: float
16
-
17
- completion_tokens: float
18
-
19
- total_tokens: float
@@ -1,123 +0,0 @@
1
- """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
-
3
- from __future__ import annotations
4
- from openrouter.components import providername as components_providername
5
- from openrouter.types import BaseModel, UnrecognizedStr
6
- from openrouter.utils import (
7
- FieldMetadata,
8
- PathParamMetadata,
9
- QueryParamMetadata,
10
- SecurityMetadata,
11
- validate_open_enum,
12
- )
13
- from pydantic.functional_validators import PlainValidator
14
- from typing import List, Literal, Optional, Union
15
- from typing_extensions import Annotated, NotRequired, TypedDict
16
-
17
-
18
- class GetParametersSecurityTypedDict(TypedDict):
19
- bearer: str
20
-
21
-
22
- class GetParametersSecurity(BaseModel):
23
- bearer: Annotated[
24
- str,
25
- FieldMetadata(
26
- security=SecurityMetadata(
27
- scheme=True,
28
- scheme_type="http",
29
- sub_type="bearer",
30
- field_name="Authorization",
31
- )
32
- ),
33
- ]
34
-
35
-
36
- class GetParametersRequestTypedDict(TypedDict):
37
- author: str
38
- slug: str
39
- provider: NotRequired[components_providername.ProviderName]
40
-
41
-
42
- class GetParametersRequest(BaseModel):
43
- author: Annotated[
44
- str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
45
- ]
46
-
47
- slug: Annotated[
48
- str, FieldMetadata(path=PathParamMetadata(style="simple", explode=False))
49
- ]
50
-
51
- provider: Annotated[
52
- Annotated[
53
- Optional[components_providername.ProviderName],
54
- PlainValidator(validate_open_enum(False)),
55
- ],
56
- FieldMetadata(query=QueryParamMetadata(style="form", explode=True)),
57
- ] = None
58
-
59
-
60
- SupportedParameter = Union[
61
- Literal[
62
- "temperature",
63
- "top_p",
64
- "top_k",
65
- "min_p",
66
- "top_a",
67
- "frequency_penalty",
68
- "presence_penalty",
69
- "repetition_penalty",
70
- "max_tokens",
71
- "logit_bias",
72
- "logprobs",
73
- "top_logprobs",
74
- "seed",
75
- "response_format",
76
- "structured_outputs",
77
- "stop",
78
- "tools",
79
- "tool_choice",
80
- "parallel_tool_calls",
81
- "include_reasoning",
82
- "reasoning",
83
- "reasoning_effort",
84
- "web_search_options",
85
- "verbosity",
86
- ],
87
- UnrecognizedStr,
88
- ]
89
-
90
-
91
- class GetParametersDataTypedDict(TypedDict):
92
- r"""Parameter analytics data"""
93
-
94
- model: str
95
- r"""Model identifier"""
96
- supported_parameters: List[SupportedParameter]
97
- r"""List of parameters supported by this model"""
98
-
99
-
100
- class GetParametersData(BaseModel):
101
- r"""Parameter analytics data"""
102
-
103
- model: str
104
- r"""Model identifier"""
105
-
106
- supported_parameters: List[
107
- Annotated[SupportedParameter, PlainValidator(validate_open_enum(False))]
108
- ]
109
- r"""List of parameters supported by this model"""
110
-
111
-
112
- class GetParametersResponseTypedDict(TypedDict):
113
- r"""Returns the parameters for the specified model"""
114
-
115
- data: GetParametersDataTypedDict
116
- r"""Parameter analytics data"""
117
-
118
-
119
- class GetParametersResponse(BaseModel):
120
- r"""Returns the parameters for the specified model"""
121
-
122
- data: GetParametersData
123
- r"""Parameter analytics data"""