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
openrouter/models_.py
CHANGED
|
@@ -15,6 +15,8 @@ class Models(BaseSDK):
|
|
|
15
15
|
def count(
|
|
16
16
|
self,
|
|
17
17
|
*,
|
|
18
|
+
http_referer: Optional[str] = None,
|
|
19
|
+
x_title: Optional[str] = None,
|
|
18
20
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
19
21
|
server_url: Optional[str] = None,
|
|
20
22
|
timeout_ms: Optional[int] = None,
|
|
@@ -22,6 +24,11 @@ class Models(BaseSDK):
|
|
|
22
24
|
) -> components.ModelsCountResponse:
|
|
23
25
|
r"""Get total count of available models
|
|
24
26
|
|
|
27
|
+
:param http_referer: 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
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
31
|
+
|
|
25
32
|
:param retries: Override the default retry configuration for this method
|
|
26
33
|
:param server_url: Override the default server URL for this method
|
|
27
34
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -36,18 +43,28 @@ class Models(BaseSDK):
|
|
|
36
43
|
base_url = server_url
|
|
37
44
|
else:
|
|
38
45
|
base_url = self._get_url(base_url, url_variables)
|
|
46
|
+
|
|
47
|
+
request = operations.ListModelsCountRequest(
|
|
48
|
+
http_referer=http_referer,
|
|
49
|
+
x_title=x_title,
|
|
50
|
+
)
|
|
51
|
+
|
|
39
52
|
req = self._build_request(
|
|
40
53
|
method="GET",
|
|
41
54
|
path="/models/count",
|
|
42
55
|
base_url=base_url,
|
|
43
56
|
url_variables=url_variables,
|
|
44
|
-
request=
|
|
57
|
+
request=request,
|
|
45
58
|
request_body_required=False,
|
|
46
59
|
request_has_path_params=False,
|
|
47
60
|
request_has_query_params=True,
|
|
48
61
|
user_agent_header="user-agent",
|
|
49
62
|
accept_header_value="application/json",
|
|
50
63
|
http_headers=http_headers,
|
|
64
|
+
_globals=operations.ListModelsCountGlobals(
|
|
65
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
66
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
67
|
+
),
|
|
51
68
|
security=self.sdk_configuration.security,
|
|
52
69
|
allow_empty_value=None,
|
|
53
70
|
timeout_ms=timeout_ms,
|
|
@@ -100,6 +117,8 @@ class Models(BaseSDK):
|
|
|
100
117
|
async def count_async(
|
|
101
118
|
self,
|
|
102
119
|
*,
|
|
120
|
+
http_referer: Optional[str] = None,
|
|
121
|
+
x_title: Optional[str] = None,
|
|
103
122
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
104
123
|
server_url: Optional[str] = None,
|
|
105
124
|
timeout_ms: Optional[int] = None,
|
|
@@ -107,6 +126,11 @@ class Models(BaseSDK):
|
|
|
107
126
|
) -> components.ModelsCountResponse:
|
|
108
127
|
r"""Get total count of available models
|
|
109
128
|
|
|
129
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
130
|
+
This is used to track API usage per application.
|
|
131
|
+
|
|
132
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
133
|
+
|
|
110
134
|
:param retries: Override the default retry configuration for this method
|
|
111
135
|
:param server_url: Override the default server URL for this method
|
|
112
136
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -121,18 +145,28 @@ class Models(BaseSDK):
|
|
|
121
145
|
base_url = server_url
|
|
122
146
|
else:
|
|
123
147
|
base_url = self._get_url(base_url, url_variables)
|
|
148
|
+
|
|
149
|
+
request = operations.ListModelsCountRequest(
|
|
150
|
+
http_referer=http_referer,
|
|
151
|
+
x_title=x_title,
|
|
152
|
+
)
|
|
153
|
+
|
|
124
154
|
req = self._build_request_async(
|
|
125
155
|
method="GET",
|
|
126
156
|
path="/models/count",
|
|
127
157
|
base_url=base_url,
|
|
128
158
|
url_variables=url_variables,
|
|
129
|
-
request=
|
|
159
|
+
request=request,
|
|
130
160
|
request_body_required=False,
|
|
131
161
|
request_has_path_params=False,
|
|
132
162
|
request_has_query_params=True,
|
|
133
163
|
user_agent_header="user-agent",
|
|
134
164
|
accept_header_value="application/json",
|
|
135
165
|
http_headers=http_headers,
|
|
166
|
+
_globals=operations.ListModelsCountGlobals(
|
|
167
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
168
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
169
|
+
),
|
|
136
170
|
security=self.sdk_configuration.security,
|
|
137
171
|
allow_empty_value=None,
|
|
138
172
|
timeout_ms=timeout_ms,
|
|
@@ -185,7 +219,9 @@ class Models(BaseSDK):
|
|
|
185
219
|
def list(
|
|
186
220
|
self,
|
|
187
221
|
*,
|
|
188
|
-
|
|
222
|
+
http_referer: Optional[str] = None,
|
|
223
|
+
x_title: Optional[str] = None,
|
|
224
|
+
category: Optional[operations.Category] = None,
|
|
189
225
|
supported_parameters: Optional[str] = None,
|
|
190
226
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
191
227
|
server_url: Optional[str] = None,
|
|
@@ -194,7 +230,12 @@ class Models(BaseSDK):
|
|
|
194
230
|
) -> components.ModelsListResponse:
|
|
195
231
|
r"""List all models and their properties
|
|
196
232
|
|
|
197
|
-
:param
|
|
233
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
234
|
+
This is used to track API usage per application.
|
|
235
|
+
|
|
236
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
237
|
+
|
|
238
|
+
:param category: Filter models by use case category
|
|
198
239
|
:param supported_parameters:
|
|
199
240
|
:param retries: Override the default retry configuration for this method
|
|
200
241
|
:param server_url: Override the default server URL for this method
|
|
@@ -212,6 +253,8 @@ class Models(BaseSDK):
|
|
|
212
253
|
base_url = self._get_url(base_url, url_variables)
|
|
213
254
|
|
|
214
255
|
request = operations.GetModelsRequest(
|
|
256
|
+
http_referer=http_referer,
|
|
257
|
+
x_title=x_title,
|
|
215
258
|
category=category,
|
|
216
259
|
supported_parameters=supported_parameters,
|
|
217
260
|
)
|
|
@@ -228,6 +271,10 @@ class Models(BaseSDK):
|
|
|
228
271
|
user_agent_header="user-agent",
|
|
229
272
|
accept_header_value="application/json",
|
|
230
273
|
http_headers=http_headers,
|
|
274
|
+
_globals=operations.GetModelsGlobals(
|
|
275
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
276
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
277
|
+
),
|
|
231
278
|
security=self.sdk_configuration.security,
|
|
232
279
|
allow_empty_value=None,
|
|
233
280
|
timeout_ms=timeout_ms,
|
|
@@ -285,7 +332,9 @@ class Models(BaseSDK):
|
|
|
285
332
|
async def list_async(
|
|
286
333
|
self,
|
|
287
334
|
*,
|
|
288
|
-
|
|
335
|
+
http_referer: Optional[str] = None,
|
|
336
|
+
x_title: Optional[str] = None,
|
|
337
|
+
category: Optional[operations.Category] = None,
|
|
289
338
|
supported_parameters: Optional[str] = None,
|
|
290
339
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
291
340
|
server_url: Optional[str] = None,
|
|
@@ -294,7 +343,12 @@ class Models(BaseSDK):
|
|
|
294
343
|
) -> components.ModelsListResponse:
|
|
295
344
|
r"""List all models and their properties
|
|
296
345
|
|
|
297
|
-
:param
|
|
346
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
347
|
+
This is used to track API usage per application.
|
|
348
|
+
|
|
349
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
350
|
+
|
|
351
|
+
:param category: Filter models by use case category
|
|
298
352
|
:param supported_parameters:
|
|
299
353
|
:param retries: Override the default retry configuration for this method
|
|
300
354
|
:param server_url: Override the default server URL for this method
|
|
@@ -312,6 +366,8 @@ class Models(BaseSDK):
|
|
|
312
366
|
base_url = self._get_url(base_url, url_variables)
|
|
313
367
|
|
|
314
368
|
request = operations.GetModelsRequest(
|
|
369
|
+
http_referer=http_referer,
|
|
370
|
+
x_title=x_title,
|
|
315
371
|
category=category,
|
|
316
372
|
supported_parameters=supported_parameters,
|
|
317
373
|
)
|
|
@@ -328,6 +384,10 @@ class Models(BaseSDK):
|
|
|
328
384
|
user_agent_header="user-agent",
|
|
329
385
|
accept_header_value="application/json",
|
|
330
386
|
http_headers=http_headers,
|
|
387
|
+
_globals=operations.GetModelsGlobals(
|
|
388
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
389
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
390
|
+
),
|
|
331
391
|
security=self.sdk_configuration.security,
|
|
332
392
|
allow_empty_value=None,
|
|
333
393
|
timeout_ms=timeout_ms,
|
|
@@ -389,14 +449,23 @@ class Models(BaseSDK):
|
|
|
389
449
|
operations.ListModelsUserSecurity,
|
|
390
450
|
operations.ListModelsUserSecurityTypedDict,
|
|
391
451
|
],
|
|
452
|
+
http_referer: Optional[str] = None,
|
|
453
|
+
x_title: Optional[str] = None,
|
|
392
454
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
393
455
|
server_url: Optional[str] = None,
|
|
394
456
|
timeout_ms: Optional[int] = None,
|
|
395
457
|
http_headers: Optional[Mapping[str, str]] = None,
|
|
396
458
|
) -> components.ModelsListResponse:
|
|
397
|
-
r"""List models filtered by user provider preferences
|
|
459
|
+
r"""List models filtered by user provider preferences, privacy settings, and guardrails
|
|
460
|
+
|
|
461
|
+
List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing).
|
|
398
462
|
|
|
399
463
|
:param security:
|
|
464
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
465
|
+
This is used to track API usage per application.
|
|
466
|
+
|
|
467
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
468
|
+
|
|
400
469
|
:param retries: Override the default retry configuration for this method
|
|
401
470
|
:param server_url: Override the default server URL for this method
|
|
402
471
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -411,18 +480,28 @@ class Models(BaseSDK):
|
|
|
411
480
|
base_url = server_url
|
|
412
481
|
else:
|
|
413
482
|
base_url = self._get_url(base_url, url_variables)
|
|
483
|
+
|
|
484
|
+
request = operations.ListModelsUserRequest(
|
|
485
|
+
http_referer=http_referer,
|
|
486
|
+
x_title=x_title,
|
|
487
|
+
)
|
|
488
|
+
|
|
414
489
|
req = self._build_request(
|
|
415
490
|
method="GET",
|
|
416
491
|
path="/models/user",
|
|
417
492
|
base_url=base_url,
|
|
418
493
|
url_variables=url_variables,
|
|
419
|
-
request=
|
|
494
|
+
request=request,
|
|
420
495
|
request_body_required=False,
|
|
421
496
|
request_has_path_params=False,
|
|
422
497
|
request_has_query_params=True,
|
|
423
498
|
user_agent_header="user-agent",
|
|
424
499
|
accept_header_value="application/json",
|
|
425
500
|
http_headers=http_headers,
|
|
501
|
+
_globals=operations.ListModelsUserGlobals(
|
|
502
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
503
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
504
|
+
),
|
|
426
505
|
security=utils.get_pydantic_model(
|
|
427
506
|
security, operations.ListModelsUserSecurity
|
|
428
507
|
),
|
|
@@ -447,7 +526,7 @@ class Models(BaseSDK):
|
|
|
447
526
|
security_source=get_security_from_env(security, components.Security),
|
|
448
527
|
),
|
|
449
528
|
request=req,
|
|
450
|
-
error_status_codes=["401", "4XX", "500", "5XX"],
|
|
529
|
+
error_status_codes=["401", "404", "4XX", "500", "5XX"],
|
|
451
530
|
retry_config=retry_config,
|
|
452
531
|
)
|
|
453
532
|
|
|
@@ -459,6 +538,11 @@ class Models(BaseSDK):
|
|
|
459
538
|
errors.UnauthorizedResponseErrorData, http_res
|
|
460
539
|
)
|
|
461
540
|
raise errors.UnauthorizedResponseError(response_data, http_res)
|
|
541
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
542
|
+
response_data = unmarshal_json_response(
|
|
543
|
+
errors.NotFoundResponseErrorData, http_res
|
|
544
|
+
)
|
|
545
|
+
raise errors.NotFoundResponseError(response_data, http_res)
|
|
462
546
|
if utils.match_response(http_res, "500", "application/json"):
|
|
463
547
|
response_data = unmarshal_json_response(
|
|
464
548
|
errors.InternalServerResponseErrorData, http_res
|
|
@@ -484,14 +568,23 @@ class Models(BaseSDK):
|
|
|
484
568
|
operations.ListModelsUserSecurity,
|
|
485
569
|
operations.ListModelsUserSecurityTypedDict,
|
|
486
570
|
],
|
|
571
|
+
http_referer: Optional[str] = None,
|
|
572
|
+
x_title: Optional[str] = None,
|
|
487
573
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
488
574
|
server_url: Optional[str] = None,
|
|
489
575
|
timeout_ms: Optional[int] = None,
|
|
490
576
|
http_headers: Optional[Mapping[str, str]] = None,
|
|
491
577
|
) -> components.ModelsListResponse:
|
|
492
|
-
r"""List models filtered by user provider preferences
|
|
578
|
+
r"""List models filtered by user provider preferences, privacy settings, and guardrails
|
|
579
|
+
|
|
580
|
+
List models filtered by user provider preferences, [privacy settings](https://openrouter.ai/docs/guides/privacy/logging), and [guardrails](https://openrouter.ai/docs/guides/features/guardrails). If requesting through `eu.openrouter.ai/api/v1/...` the results will be filtered to models that satisfy [EU in-region routing](https://openrouter.ai/docs/guides/privacy/logging#enterprise-eu-in-region-routing).
|
|
493
581
|
|
|
494
582
|
:param security:
|
|
583
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
584
|
+
This is used to track API usage per application.
|
|
585
|
+
|
|
586
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
587
|
+
|
|
495
588
|
:param retries: Override the default retry configuration for this method
|
|
496
589
|
:param server_url: Override the default server URL for this method
|
|
497
590
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -506,18 +599,28 @@ class Models(BaseSDK):
|
|
|
506
599
|
base_url = server_url
|
|
507
600
|
else:
|
|
508
601
|
base_url = self._get_url(base_url, url_variables)
|
|
602
|
+
|
|
603
|
+
request = operations.ListModelsUserRequest(
|
|
604
|
+
http_referer=http_referer,
|
|
605
|
+
x_title=x_title,
|
|
606
|
+
)
|
|
607
|
+
|
|
509
608
|
req = self._build_request_async(
|
|
510
609
|
method="GET",
|
|
511
610
|
path="/models/user",
|
|
512
611
|
base_url=base_url,
|
|
513
612
|
url_variables=url_variables,
|
|
514
|
-
request=
|
|
613
|
+
request=request,
|
|
515
614
|
request_body_required=False,
|
|
516
615
|
request_has_path_params=False,
|
|
517
616
|
request_has_query_params=True,
|
|
518
617
|
user_agent_header="user-agent",
|
|
519
618
|
accept_header_value="application/json",
|
|
520
619
|
http_headers=http_headers,
|
|
620
|
+
_globals=operations.ListModelsUserGlobals(
|
|
621
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
622
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
623
|
+
),
|
|
521
624
|
security=utils.get_pydantic_model(
|
|
522
625
|
security, operations.ListModelsUserSecurity
|
|
523
626
|
),
|
|
@@ -542,7 +645,7 @@ class Models(BaseSDK):
|
|
|
542
645
|
security_source=get_security_from_env(security, components.Security),
|
|
543
646
|
),
|
|
544
647
|
request=req,
|
|
545
|
-
error_status_codes=["401", "4XX", "500", "5XX"],
|
|
648
|
+
error_status_codes=["401", "404", "4XX", "500", "5XX"],
|
|
546
649
|
retry_config=retry_config,
|
|
547
650
|
)
|
|
548
651
|
|
|
@@ -554,6 +657,11 @@ class Models(BaseSDK):
|
|
|
554
657
|
errors.UnauthorizedResponseErrorData, http_res
|
|
555
658
|
)
|
|
556
659
|
raise errors.UnauthorizedResponseError(response_data, http_res)
|
|
660
|
+
if utils.match_response(http_res, "404", "application/json"):
|
|
661
|
+
response_data = unmarshal_json_response(
|
|
662
|
+
errors.NotFoundResponseErrorData, http_res
|
|
663
|
+
)
|
|
664
|
+
raise errors.NotFoundResponseError(response_data, http_res)
|
|
557
665
|
if utils.match_response(http_res, "500", "application/json"):
|
|
558
666
|
response_data = unmarshal_json_response(
|
|
559
667
|
errors.InternalServerResponseErrorData, http_res
|
openrouter/oauth.py
CHANGED
|
@@ -17,6 +17,8 @@ class OAuth(BaseSDK):
|
|
|
17
17
|
self,
|
|
18
18
|
*,
|
|
19
19
|
code: str,
|
|
20
|
+
http_referer: Optional[str] = None,
|
|
21
|
+
x_title: Optional[str] = None,
|
|
20
22
|
code_verifier: Optional[str] = None,
|
|
21
23
|
code_challenge_method: OptionalNullable[
|
|
22
24
|
operations.ExchangeAuthCodeForAPIKeyCodeChallengeMethod
|
|
@@ -31,6 +33,11 @@ class OAuth(BaseSDK):
|
|
|
31
33
|
Exchange an authorization code from the PKCE flow for a user-controlled API key
|
|
32
34
|
|
|
33
35
|
:param code: The authorization code received from the OAuth redirect
|
|
36
|
+
:param http_referer: 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
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
40
|
+
|
|
34
41
|
:param code_verifier: The code verifier if code_challenge was used in the authorization request
|
|
35
42
|
:param code_challenge_method: The method used to generate the code challenge
|
|
36
43
|
:param retries: Override the default retry configuration for this method
|
|
@@ -49,9 +56,13 @@ class OAuth(BaseSDK):
|
|
|
49
56
|
base_url = self._get_url(base_url, url_variables)
|
|
50
57
|
|
|
51
58
|
request = operations.ExchangeAuthCodeForAPIKeyRequest(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
http_referer=http_referer,
|
|
60
|
+
x_title=x_title,
|
|
61
|
+
request_body=operations.ExchangeAuthCodeForAPIKeyRequestBody(
|
|
62
|
+
code=code,
|
|
63
|
+
code_verifier=code_verifier,
|
|
64
|
+
code_challenge_method=code_challenge_method,
|
|
65
|
+
),
|
|
55
66
|
)
|
|
56
67
|
|
|
57
68
|
req = self._build_request(
|
|
@@ -66,13 +77,17 @@ class OAuth(BaseSDK):
|
|
|
66
77
|
user_agent_header="user-agent",
|
|
67
78
|
accept_header_value="application/json",
|
|
68
79
|
http_headers=http_headers,
|
|
80
|
+
_globals=operations.ExchangeAuthCodeForAPIKeyGlobals(
|
|
81
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
82
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
83
|
+
),
|
|
69
84
|
security=self.sdk_configuration.security,
|
|
70
85
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
71
|
-
request,
|
|
86
|
+
request.request_body,
|
|
72
87
|
False,
|
|
73
88
|
False,
|
|
74
89
|
"json",
|
|
75
|
-
operations.
|
|
90
|
+
operations.ExchangeAuthCodeForAPIKeyRequestBody,
|
|
76
91
|
),
|
|
77
92
|
allow_empty_value=None,
|
|
78
93
|
timeout_ms=timeout_ms,
|
|
@@ -138,6 +153,8 @@ class OAuth(BaseSDK):
|
|
|
138
153
|
self,
|
|
139
154
|
*,
|
|
140
155
|
code: str,
|
|
156
|
+
http_referer: Optional[str] = None,
|
|
157
|
+
x_title: Optional[str] = None,
|
|
141
158
|
code_verifier: Optional[str] = None,
|
|
142
159
|
code_challenge_method: OptionalNullable[
|
|
143
160
|
operations.ExchangeAuthCodeForAPIKeyCodeChallengeMethod
|
|
@@ -152,6 +169,11 @@ class OAuth(BaseSDK):
|
|
|
152
169
|
Exchange an authorization code from the PKCE flow for a user-controlled API key
|
|
153
170
|
|
|
154
171
|
:param code: The authorization code received from the OAuth redirect
|
|
172
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
173
|
+
This is used to track API usage per application.
|
|
174
|
+
|
|
175
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
176
|
+
|
|
155
177
|
:param code_verifier: The code verifier if code_challenge was used in the authorization request
|
|
156
178
|
:param code_challenge_method: The method used to generate the code challenge
|
|
157
179
|
:param retries: Override the default retry configuration for this method
|
|
@@ -170,9 +192,13 @@ class OAuth(BaseSDK):
|
|
|
170
192
|
base_url = self._get_url(base_url, url_variables)
|
|
171
193
|
|
|
172
194
|
request = operations.ExchangeAuthCodeForAPIKeyRequest(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
195
|
+
http_referer=http_referer,
|
|
196
|
+
x_title=x_title,
|
|
197
|
+
request_body=operations.ExchangeAuthCodeForAPIKeyRequestBody(
|
|
198
|
+
code=code,
|
|
199
|
+
code_verifier=code_verifier,
|
|
200
|
+
code_challenge_method=code_challenge_method,
|
|
201
|
+
),
|
|
176
202
|
)
|
|
177
203
|
|
|
178
204
|
req = self._build_request_async(
|
|
@@ -187,13 +213,17 @@ class OAuth(BaseSDK):
|
|
|
187
213
|
user_agent_header="user-agent",
|
|
188
214
|
accept_header_value="application/json",
|
|
189
215
|
http_headers=http_headers,
|
|
216
|
+
_globals=operations.ExchangeAuthCodeForAPIKeyGlobals(
|
|
217
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
218
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
219
|
+
),
|
|
190
220
|
security=self.sdk_configuration.security,
|
|
191
221
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
192
|
-
request,
|
|
222
|
+
request.request_body,
|
|
193
223
|
False,
|
|
194
224
|
False,
|
|
195
225
|
"json",
|
|
196
|
-
operations.
|
|
226
|
+
operations.ExchangeAuthCodeForAPIKeyRequestBody,
|
|
197
227
|
),
|
|
198
228
|
allow_empty_value=None,
|
|
199
229
|
timeout_ms=timeout_ms,
|
|
@@ -259,6 +289,8 @@ class OAuth(BaseSDK):
|
|
|
259
289
|
self,
|
|
260
290
|
*,
|
|
261
291
|
callback_url: str,
|
|
292
|
+
http_referer: Optional[str] = None,
|
|
293
|
+
x_title: Optional[str] = None,
|
|
262
294
|
code_challenge: Optional[str] = None,
|
|
263
295
|
code_challenge_method: Optional[
|
|
264
296
|
operations.CreateAuthKeysCodeCodeChallengeMethod
|
|
@@ -275,6 +307,11 @@ class OAuth(BaseSDK):
|
|
|
275
307
|
Create an authorization code for the PKCE flow to generate a user-controlled API key
|
|
276
308
|
|
|
277
309
|
:param callback_url: The callback URL to redirect to after authorization. Note, only https URLs on ports 443 and 3000 are allowed.
|
|
310
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
311
|
+
This is used to track API usage per application.
|
|
312
|
+
|
|
313
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
314
|
+
|
|
278
315
|
:param code_challenge: PKCE code challenge for enhanced security
|
|
279
316
|
:param code_challenge_method: The method used to generate the code challenge
|
|
280
317
|
:param limit: Credit limit for the API key to be created
|
|
@@ -295,11 +332,15 @@ class OAuth(BaseSDK):
|
|
|
295
332
|
base_url = self._get_url(base_url, url_variables)
|
|
296
333
|
|
|
297
334
|
request = operations.CreateAuthKeysCodeRequest(
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
335
|
+
http_referer=http_referer,
|
|
336
|
+
x_title=x_title,
|
|
337
|
+
request_body=operations.CreateAuthKeysCodeRequestBody(
|
|
338
|
+
callback_url=callback_url,
|
|
339
|
+
code_challenge=code_challenge,
|
|
340
|
+
code_challenge_method=code_challenge_method,
|
|
341
|
+
limit=limit,
|
|
342
|
+
expires_at=expires_at,
|
|
343
|
+
),
|
|
303
344
|
)
|
|
304
345
|
|
|
305
346
|
req = self._build_request(
|
|
@@ -314,9 +355,17 @@ class OAuth(BaseSDK):
|
|
|
314
355
|
user_agent_header="user-agent",
|
|
315
356
|
accept_header_value="application/json",
|
|
316
357
|
http_headers=http_headers,
|
|
358
|
+
_globals=operations.CreateAuthKeysCodeGlobals(
|
|
359
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
360
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
361
|
+
),
|
|
317
362
|
security=self.sdk_configuration.security,
|
|
318
363
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
319
|
-
request,
|
|
364
|
+
request.request_body,
|
|
365
|
+
False,
|
|
366
|
+
False,
|
|
367
|
+
"json",
|
|
368
|
+
operations.CreateAuthKeysCodeRequestBody,
|
|
320
369
|
),
|
|
321
370
|
allow_empty_value=None,
|
|
322
371
|
timeout_ms=timeout_ms,
|
|
@@ -382,6 +431,8 @@ class OAuth(BaseSDK):
|
|
|
382
431
|
self,
|
|
383
432
|
*,
|
|
384
433
|
callback_url: str,
|
|
434
|
+
http_referer: Optional[str] = None,
|
|
435
|
+
x_title: Optional[str] = None,
|
|
385
436
|
code_challenge: Optional[str] = None,
|
|
386
437
|
code_challenge_method: Optional[
|
|
387
438
|
operations.CreateAuthKeysCodeCodeChallengeMethod
|
|
@@ -398,6 +449,11 @@ class OAuth(BaseSDK):
|
|
|
398
449
|
Create an authorization code for the PKCE flow to generate a user-controlled API key
|
|
399
450
|
|
|
400
451
|
:param callback_url: The callback URL to redirect to after authorization. Note, only https URLs on ports 443 and 3000 are allowed.
|
|
452
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
453
|
+
This is used to track API usage per application.
|
|
454
|
+
|
|
455
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
456
|
+
|
|
401
457
|
:param code_challenge: PKCE code challenge for enhanced security
|
|
402
458
|
:param code_challenge_method: The method used to generate the code challenge
|
|
403
459
|
:param limit: Credit limit for the API key to be created
|
|
@@ -418,11 +474,15 @@ class OAuth(BaseSDK):
|
|
|
418
474
|
base_url = self._get_url(base_url, url_variables)
|
|
419
475
|
|
|
420
476
|
request = operations.CreateAuthKeysCodeRequest(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
477
|
+
http_referer=http_referer,
|
|
478
|
+
x_title=x_title,
|
|
479
|
+
request_body=operations.CreateAuthKeysCodeRequestBody(
|
|
480
|
+
callback_url=callback_url,
|
|
481
|
+
code_challenge=code_challenge,
|
|
482
|
+
code_challenge_method=code_challenge_method,
|
|
483
|
+
limit=limit,
|
|
484
|
+
expires_at=expires_at,
|
|
485
|
+
),
|
|
426
486
|
)
|
|
427
487
|
|
|
428
488
|
req = self._build_request_async(
|
|
@@ -437,9 +497,17 @@ class OAuth(BaseSDK):
|
|
|
437
497
|
user_agent_header="user-agent",
|
|
438
498
|
accept_header_value="application/json",
|
|
439
499
|
http_headers=http_headers,
|
|
500
|
+
_globals=operations.CreateAuthKeysCodeGlobals(
|
|
501
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
502
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
503
|
+
),
|
|
440
504
|
security=self.sdk_configuration.security,
|
|
441
505
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
442
|
-
request,
|
|
506
|
+
request.request_body,
|
|
507
|
+
False,
|
|
508
|
+
False,
|
|
509
|
+
"json",
|
|
510
|
+
operations.CreateAuthKeysCodeRequestBody,
|
|
443
511
|
),
|
|
444
512
|
allow_empty_value=None,
|
|
445
513
|
timeout_ms=timeout_ms,
|