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
@@ -0,0 +1,3367 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from openrouter import components, errors, operations, utils
5
+ from openrouter._hooks import HookContext
6
+ from openrouter.types import OptionalNullable, UNSET
7
+ from openrouter.utils import get_security_from_env
8
+ from openrouter.utils.unmarshal_json_response import unmarshal_json_response
9
+ from typing import Any, List, Mapping, Optional
10
+
11
+
12
+ class Guardrails(BaseSDK):
13
+ r"""Guardrails endpoints"""
14
+
15
+ def list(
16
+ self,
17
+ *,
18
+ http_referer: Optional[str] = None,
19
+ x_title: Optional[str] = None,
20
+ offset: Optional[str] = None,
21
+ limit: Optional[str] = None,
22
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
23
+ server_url: Optional[str] = None,
24
+ timeout_ms: Optional[int] = None,
25
+ http_headers: Optional[Mapping[str, str]] = None,
26
+ ) -> operations.ListGuardrailsResponse:
27
+ r"""List guardrails
28
+
29
+ List all guardrails for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
30
+
31
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
32
+ This is used to track API usage per application.
33
+
34
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
35
+
36
+ :param offset: Number of records to skip for pagination
37
+ :param limit: Maximum number of records to return (max 100)
38
+ :param retries: Override the default retry configuration for this method
39
+ :param server_url: Override the default server URL for this method
40
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
41
+ :param http_headers: Additional headers to set or replace on requests.
42
+ """
43
+ base_url = None
44
+ url_variables = None
45
+ if timeout_ms is None:
46
+ timeout_ms = self.sdk_configuration.timeout_ms
47
+
48
+ if server_url is not None:
49
+ base_url = server_url
50
+ else:
51
+ base_url = self._get_url(base_url, url_variables)
52
+
53
+ request = operations.ListGuardrailsRequest(
54
+ http_referer=http_referer,
55
+ x_title=x_title,
56
+ offset=offset,
57
+ limit=limit,
58
+ )
59
+
60
+ req = self._build_request(
61
+ method="GET",
62
+ path="/guardrails",
63
+ base_url=base_url,
64
+ url_variables=url_variables,
65
+ request=request,
66
+ request_body_required=False,
67
+ request_has_path_params=False,
68
+ request_has_query_params=True,
69
+ user_agent_header="user-agent",
70
+ accept_header_value="application/json",
71
+ http_headers=http_headers,
72
+ _globals=operations.ListGuardrailsGlobals(
73
+ http_referer=self.sdk_configuration.globals.http_referer,
74
+ x_title=self.sdk_configuration.globals.x_title,
75
+ ),
76
+ security=self.sdk_configuration.security,
77
+ allow_empty_value=None,
78
+ timeout_ms=timeout_ms,
79
+ )
80
+
81
+ if retries == UNSET:
82
+ if self.sdk_configuration.retry_config is not UNSET:
83
+ retries = self.sdk_configuration.retry_config
84
+
85
+ retry_config = None
86
+ if isinstance(retries, utils.RetryConfig):
87
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
88
+
89
+ http_res = self.do_request(
90
+ hook_ctx=HookContext(
91
+ config=self.sdk_configuration,
92
+ base_url=base_url or "",
93
+ operation_id="listGuardrails",
94
+ oauth2_scopes=None,
95
+ security_source=get_security_from_env(
96
+ self.sdk_configuration.security, components.Security
97
+ ),
98
+ ),
99
+ request=req,
100
+ error_status_codes=["401", "4XX", "500", "5XX"],
101
+ retry_config=retry_config,
102
+ )
103
+
104
+ response_data: Any = None
105
+ if utils.match_response(http_res, "200", "application/json"):
106
+ return unmarshal_json_response(operations.ListGuardrailsResponse, http_res)
107
+ if utils.match_response(http_res, "401", "application/json"):
108
+ response_data = unmarshal_json_response(
109
+ errors.UnauthorizedResponseErrorData, http_res
110
+ )
111
+ raise errors.UnauthorizedResponseError(response_data, http_res)
112
+ if utils.match_response(http_res, "500", "application/json"):
113
+ response_data = unmarshal_json_response(
114
+ errors.InternalServerResponseErrorData, http_res
115
+ )
116
+ raise errors.InternalServerResponseError(response_data, http_res)
117
+ if utils.match_response(http_res, "4XX", "*"):
118
+ http_res_text = utils.stream_to_text(http_res)
119
+ raise errors.OpenRouterDefaultError(
120
+ "API error occurred", http_res, http_res_text
121
+ )
122
+ if utils.match_response(http_res, "5XX", "*"):
123
+ http_res_text = utils.stream_to_text(http_res)
124
+ raise errors.OpenRouterDefaultError(
125
+ "API error occurred", http_res, http_res_text
126
+ )
127
+
128
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
129
+
130
+ async def list_async(
131
+ self,
132
+ *,
133
+ http_referer: Optional[str] = None,
134
+ x_title: Optional[str] = None,
135
+ offset: Optional[str] = None,
136
+ limit: Optional[str] = None,
137
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
138
+ server_url: Optional[str] = None,
139
+ timeout_ms: Optional[int] = None,
140
+ http_headers: Optional[Mapping[str, str]] = None,
141
+ ) -> operations.ListGuardrailsResponse:
142
+ r"""List guardrails
143
+
144
+ List all guardrails for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
145
+
146
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
147
+ This is used to track API usage per application.
148
+
149
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
150
+
151
+ :param offset: Number of records to skip for pagination
152
+ :param limit: Maximum number of records to return (max 100)
153
+ :param retries: Override the default retry configuration for this method
154
+ :param server_url: Override the default server URL for this method
155
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
156
+ :param http_headers: Additional headers to set or replace on requests.
157
+ """
158
+ base_url = None
159
+ url_variables = None
160
+ if timeout_ms is None:
161
+ timeout_ms = self.sdk_configuration.timeout_ms
162
+
163
+ if server_url is not None:
164
+ base_url = server_url
165
+ else:
166
+ base_url = self._get_url(base_url, url_variables)
167
+
168
+ request = operations.ListGuardrailsRequest(
169
+ http_referer=http_referer,
170
+ x_title=x_title,
171
+ offset=offset,
172
+ limit=limit,
173
+ )
174
+
175
+ req = self._build_request_async(
176
+ method="GET",
177
+ path="/guardrails",
178
+ base_url=base_url,
179
+ url_variables=url_variables,
180
+ request=request,
181
+ request_body_required=False,
182
+ request_has_path_params=False,
183
+ request_has_query_params=True,
184
+ user_agent_header="user-agent",
185
+ accept_header_value="application/json",
186
+ http_headers=http_headers,
187
+ _globals=operations.ListGuardrailsGlobals(
188
+ http_referer=self.sdk_configuration.globals.http_referer,
189
+ x_title=self.sdk_configuration.globals.x_title,
190
+ ),
191
+ security=self.sdk_configuration.security,
192
+ allow_empty_value=None,
193
+ timeout_ms=timeout_ms,
194
+ )
195
+
196
+ if retries == UNSET:
197
+ if self.sdk_configuration.retry_config is not UNSET:
198
+ retries = self.sdk_configuration.retry_config
199
+
200
+ retry_config = None
201
+ if isinstance(retries, utils.RetryConfig):
202
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
203
+
204
+ http_res = await self.do_request_async(
205
+ hook_ctx=HookContext(
206
+ config=self.sdk_configuration,
207
+ base_url=base_url or "",
208
+ operation_id="listGuardrails",
209
+ oauth2_scopes=None,
210
+ security_source=get_security_from_env(
211
+ self.sdk_configuration.security, components.Security
212
+ ),
213
+ ),
214
+ request=req,
215
+ error_status_codes=["401", "4XX", "500", "5XX"],
216
+ retry_config=retry_config,
217
+ )
218
+
219
+ response_data: Any = None
220
+ if utils.match_response(http_res, "200", "application/json"):
221
+ return unmarshal_json_response(operations.ListGuardrailsResponse, http_res)
222
+ if utils.match_response(http_res, "401", "application/json"):
223
+ response_data = unmarshal_json_response(
224
+ errors.UnauthorizedResponseErrorData, http_res
225
+ )
226
+ raise errors.UnauthorizedResponseError(response_data, http_res)
227
+ if utils.match_response(http_res, "500", "application/json"):
228
+ response_data = unmarshal_json_response(
229
+ errors.InternalServerResponseErrorData, http_res
230
+ )
231
+ raise errors.InternalServerResponseError(response_data, http_res)
232
+ if utils.match_response(http_res, "4XX", "*"):
233
+ http_res_text = await utils.stream_to_text_async(http_res)
234
+ raise errors.OpenRouterDefaultError(
235
+ "API error occurred", http_res, http_res_text
236
+ )
237
+ if utils.match_response(http_res, "5XX", "*"):
238
+ http_res_text = await utils.stream_to_text_async(http_res)
239
+ raise errors.OpenRouterDefaultError(
240
+ "API error occurred", http_res, http_res_text
241
+ )
242
+
243
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
244
+
245
+ def create(
246
+ self,
247
+ *,
248
+ name: str,
249
+ http_referer: Optional[str] = None,
250
+ x_title: Optional[str] = None,
251
+ description: OptionalNullable[str] = UNSET,
252
+ limit_usd: OptionalNullable[float] = UNSET,
253
+ reset_interval: OptionalNullable[
254
+ operations.CreateGuardrailResetIntervalRequest
255
+ ] = UNSET,
256
+ allowed_providers: OptionalNullable[List[str]] = UNSET,
257
+ allowed_models: OptionalNullable[List[str]] = UNSET,
258
+ enforce_zdr: OptionalNullable[bool] = UNSET,
259
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
260
+ server_url: Optional[str] = None,
261
+ timeout_ms: Optional[int] = None,
262
+ http_headers: Optional[Mapping[str, str]] = None,
263
+ ) -> operations.CreateGuardrailResponse:
264
+ r"""Create a guardrail
265
+
266
+ Create a new guardrail for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
267
+
268
+ :param name: Name for the new guardrail
269
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
270
+ This is used to track API usage per application.
271
+
272
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
273
+
274
+ :param description: Description of the guardrail
275
+ :param limit_usd: Spending limit in USD
276
+ :param reset_interval: Interval at which the limit resets (daily, weekly, monthly)
277
+ :param allowed_providers: List of allowed provider IDs
278
+ :param allowed_models: Array of model identifiers (slug or canonical_slug accepted)
279
+ :param enforce_zdr: Whether to enforce zero data retention
280
+ :param retries: Override the default retry configuration for this method
281
+ :param server_url: Override the default server URL for this method
282
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
283
+ :param http_headers: Additional headers to set or replace on requests.
284
+ """
285
+ base_url = None
286
+ url_variables = None
287
+ if timeout_ms is None:
288
+ timeout_ms = self.sdk_configuration.timeout_ms
289
+
290
+ if server_url is not None:
291
+ base_url = server_url
292
+ else:
293
+ base_url = self._get_url(base_url, url_variables)
294
+
295
+ request = operations.CreateGuardrailRequest(
296
+ http_referer=http_referer,
297
+ x_title=x_title,
298
+ request_body=operations.CreateGuardrailRequestBody(
299
+ name=name,
300
+ description=description,
301
+ limit_usd=limit_usd,
302
+ reset_interval=reset_interval,
303
+ allowed_providers=allowed_providers,
304
+ allowed_models=allowed_models,
305
+ enforce_zdr=enforce_zdr,
306
+ ),
307
+ )
308
+
309
+ req = self._build_request(
310
+ method="POST",
311
+ path="/guardrails",
312
+ base_url=base_url,
313
+ url_variables=url_variables,
314
+ request=request,
315
+ request_body_required=True,
316
+ request_has_path_params=False,
317
+ request_has_query_params=True,
318
+ user_agent_header="user-agent",
319
+ accept_header_value="application/json",
320
+ http_headers=http_headers,
321
+ _globals=operations.CreateGuardrailGlobals(
322
+ http_referer=self.sdk_configuration.globals.http_referer,
323
+ x_title=self.sdk_configuration.globals.x_title,
324
+ ),
325
+ security=self.sdk_configuration.security,
326
+ get_serialized_body=lambda: utils.serialize_request_body(
327
+ request.request_body,
328
+ False,
329
+ False,
330
+ "json",
331
+ operations.CreateGuardrailRequestBody,
332
+ ),
333
+ allow_empty_value=None,
334
+ timeout_ms=timeout_ms,
335
+ )
336
+
337
+ if retries == UNSET:
338
+ if self.sdk_configuration.retry_config is not UNSET:
339
+ retries = self.sdk_configuration.retry_config
340
+
341
+ retry_config = None
342
+ if isinstance(retries, utils.RetryConfig):
343
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
344
+
345
+ http_res = self.do_request(
346
+ hook_ctx=HookContext(
347
+ config=self.sdk_configuration,
348
+ base_url=base_url or "",
349
+ operation_id="createGuardrail",
350
+ oauth2_scopes=None,
351
+ security_source=get_security_from_env(
352
+ self.sdk_configuration.security, components.Security
353
+ ),
354
+ ),
355
+ request=req,
356
+ error_status_codes=["400", "401", "4XX", "500", "5XX"],
357
+ retry_config=retry_config,
358
+ )
359
+
360
+ response_data: Any = None
361
+ if utils.match_response(http_res, "201", "application/json"):
362
+ return unmarshal_json_response(operations.CreateGuardrailResponse, http_res)
363
+ if utils.match_response(http_res, "400", "application/json"):
364
+ response_data = unmarshal_json_response(
365
+ errors.BadRequestResponseErrorData, http_res
366
+ )
367
+ raise errors.BadRequestResponseError(response_data, http_res)
368
+ if utils.match_response(http_res, "401", "application/json"):
369
+ response_data = unmarshal_json_response(
370
+ errors.UnauthorizedResponseErrorData, http_res
371
+ )
372
+ raise errors.UnauthorizedResponseError(response_data, http_res)
373
+ if utils.match_response(http_res, "500", "application/json"):
374
+ response_data = unmarshal_json_response(
375
+ errors.InternalServerResponseErrorData, http_res
376
+ )
377
+ raise errors.InternalServerResponseError(response_data, http_res)
378
+ if utils.match_response(http_res, "4XX", "*"):
379
+ http_res_text = utils.stream_to_text(http_res)
380
+ raise errors.OpenRouterDefaultError(
381
+ "API error occurred", http_res, http_res_text
382
+ )
383
+ if utils.match_response(http_res, "5XX", "*"):
384
+ http_res_text = utils.stream_to_text(http_res)
385
+ raise errors.OpenRouterDefaultError(
386
+ "API error occurred", http_res, http_res_text
387
+ )
388
+
389
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
390
+
391
+ async def create_async(
392
+ self,
393
+ *,
394
+ name: str,
395
+ http_referer: Optional[str] = None,
396
+ x_title: Optional[str] = None,
397
+ description: OptionalNullable[str] = UNSET,
398
+ limit_usd: OptionalNullable[float] = UNSET,
399
+ reset_interval: OptionalNullable[
400
+ operations.CreateGuardrailResetIntervalRequest
401
+ ] = UNSET,
402
+ allowed_providers: OptionalNullable[List[str]] = UNSET,
403
+ allowed_models: OptionalNullable[List[str]] = UNSET,
404
+ enforce_zdr: OptionalNullable[bool] = UNSET,
405
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
406
+ server_url: Optional[str] = None,
407
+ timeout_ms: Optional[int] = None,
408
+ http_headers: Optional[Mapping[str, str]] = None,
409
+ ) -> operations.CreateGuardrailResponse:
410
+ r"""Create a guardrail
411
+
412
+ Create a new guardrail for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
413
+
414
+ :param name: Name for the new guardrail
415
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
416
+ This is used to track API usage per application.
417
+
418
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
419
+
420
+ :param description: Description of the guardrail
421
+ :param limit_usd: Spending limit in USD
422
+ :param reset_interval: Interval at which the limit resets (daily, weekly, monthly)
423
+ :param allowed_providers: List of allowed provider IDs
424
+ :param allowed_models: Array of model identifiers (slug or canonical_slug accepted)
425
+ :param enforce_zdr: Whether to enforce zero data retention
426
+ :param retries: Override the default retry configuration for this method
427
+ :param server_url: Override the default server URL for this method
428
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
429
+ :param http_headers: Additional headers to set or replace on requests.
430
+ """
431
+ base_url = None
432
+ url_variables = None
433
+ if timeout_ms is None:
434
+ timeout_ms = self.sdk_configuration.timeout_ms
435
+
436
+ if server_url is not None:
437
+ base_url = server_url
438
+ else:
439
+ base_url = self._get_url(base_url, url_variables)
440
+
441
+ request = operations.CreateGuardrailRequest(
442
+ http_referer=http_referer,
443
+ x_title=x_title,
444
+ request_body=operations.CreateGuardrailRequestBody(
445
+ name=name,
446
+ description=description,
447
+ limit_usd=limit_usd,
448
+ reset_interval=reset_interval,
449
+ allowed_providers=allowed_providers,
450
+ allowed_models=allowed_models,
451
+ enforce_zdr=enforce_zdr,
452
+ ),
453
+ )
454
+
455
+ req = self._build_request_async(
456
+ method="POST",
457
+ path="/guardrails",
458
+ base_url=base_url,
459
+ url_variables=url_variables,
460
+ request=request,
461
+ request_body_required=True,
462
+ request_has_path_params=False,
463
+ request_has_query_params=True,
464
+ user_agent_header="user-agent",
465
+ accept_header_value="application/json",
466
+ http_headers=http_headers,
467
+ _globals=operations.CreateGuardrailGlobals(
468
+ http_referer=self.sdk_configuration.globals.http_referer,
469
+ x_title=self.sdk_configuration.globals.x_title,
470
+ ),
471
+ security=self.sdk_configuration.security,
472
+ get_serialized_body=lambda: utils.serialize_request_body(
473
+ request.request_body,
474
+ False,
475
+ False,
476
+ "json",
477
+ operations.CreateGuardrailRequestBody,
478
+ ),
479
+ allow_empty_value=None,
480
+ timeout_ms=timeout_ms,
481
+ )
482
+
483
+ if retries == UNSET:
484
+ if self.sdk_configuration.retry_config is not UNSET:
485
+ retries = self.sdk_configuration.retry_config
486
+
487
+ retry_config = None
488
+ if isinstance(retries, utils.RetryConfig):
489
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
490
+
491
+ http_res = await self.do_request_async(
492
+ hook_ctx=HookContext(
493
+ config=self.sdk_configuration,
494
+ base_url=base_url or "",
495
+ operation_id="createGuardrail",
496
+ oauth2_scopes=None,
497
+ security_source=get_security_from_env(
498
+ self.sdk_configuration.security, components.Security
499
+ ),
500
+ ),
501
+ request=req,
502
+ error_status_codes=["400", "401", "4XX", "500", "5XX"],
503
+ retry_config=retry_config,
504
+ )
505
+
506
+ response_data: Any = None
507
+ if utils.match_response(http_res, "201", "application/json"):
508
+ return unmarshal_json_response(operations.CreateGuardrailResponse, http_res)
509
+ if utils.match_response(http_res, "400", "application/json"):
510
+ response_data = unmarshal_json_response(
511
+ errors.BadRequestResponseErrorData, http_res
512
+ )
513
+ raise errors.BadRequestResponseError(response_data, http_res)
514
+ if utils.match_response(http_res, "401", "application/json"):
515
+ response_data = unmarshal_json_response(
516
+ errors.UnauthorizedResponseErrorData, http_res
517
+ )
518
+ raise errors.UnauthorizedResponseError(response_data, http_res)
519
+ if utils.match_response(http_res, "500", "application/json"):
520
+ response_data = unmarshal_json_response(
521
+ errors.InternalServerResponseErrorData, http_res
522
+ )
523
+ raise errors.InternalServerResponseError(response_data, http_res)
524
+ if utils.match_response(http_res, "4XX", "*"):
525
+ http_res_text = await utils.stream_to_text_async(http_res)
526
+ raise errors.OpenRouterDefaultError(
527
+ "API error occurred", http_res, http_res_text
528
+ )
529
+ if utils.match_response(http_res, "5XX", "*"):
530
+ http_res_text = await utils.stream_to_text_async(http_res)
531
+ raise errors.OpenRouterDefaultError(
532
+ "API error occurred", http_res, http_res_text
533
+ )
534
+
535
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
536
+
537
+ def get(
538
+ self,
539
+ *,
540
+ id: str,
541
+ http_referer: Optional[str] = None,
542
+ x_title: Optional[str] = None,
543
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
544
+ server_url: Optional[str] = None,
545
+ timeout_ms: Optional[int] = None,
546
+ http_headers: Optional[Mapping[str, str]] = None,
547
+ ) -> operations.GetGuardrailResponse:
548
+ r"""Get a guardrail
549
+
550
+ Get a single guardrail by ID. [Management key](/docs/guides/overview/auth/management-api-keys) required.
551
+
552
+ :param id: The unique identifier of the guardrail to retrieve
553
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
554
+ This is used to track API usage per application.
555
+
556
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
557
+
558
+ :param retries: Override the default retry configuration for this method
559
+ :param server_url: Override the default server URL for this method
560
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
561
+ :param http_headers: Additional headers to set or replace on requests.
562
+ """
563
+ base_url = None
564
+ url_variables = None
565
+ if timeout_ms is None:
566
+ timeout_ms = self.sdk_configuration.timeout_ms
567
+
568
+ if server_url is not None:
569
+ base_url = server_url
570
+ else:
571
+ base_url = self._get_url(base_url, url_variables)
572
+
573
+ request = operations.GetGuardrailRequest(
574
+ http_referer=http_referer,
575
+ x_title=x_title,
576
+ id=id,
577
+ )
578
+
579
+ req = self._build_request(
580
+ method="GET",
581
+ path="/guardrails/{id}",
582
+ base_url=base_url,
583
+ url_variables=url_variables,
584
+ request=request,
585
+ request_body_required=False,
586
+ request_has_path_params=True,
587
+ request_has_query_params=True,
588
+ user_agent_header="user-agent",
589
+ accept_header_value="application/json",
590
+ http_headers=http_headers,
591
+ _globals=operations.GetGuardrailGlobals(
592
+ http_referer=self.sdk_configuration.globals.http_referer,
593
+ x_title=self.sdk_configuration.globals.x_title,
594
+ ),
595
+ security=self.sdk_configuration.security,
596
+ allow_empty_value=None,
597
+ timeout_ms=timeout_ms,
598
+ )
599
+
600
+ if retries == UNSET:
601
+ if self.sdk_configuration.retry_config is not UNSET:
602
+ retries = self.sdk_configuration.retry_config
603
+
604
+ retry_config = None
605
+ if isinstance(retries, utils.RetryConfig):
606
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
607
+
608
+ http_res = self.do_request(
609
+ hook_ctx=HookContext(
610
+ config=self.sdk_configuration,
611
+ base_url=base_url or "",
612
+ operation_id="getGuardrail",
613
+ oauth2_scopes=None,
614
+ security_source=get_security_from_env(
615
+ self.sdk_configuration.security, components.Security
616
+ ),
617
+ ),
618
+ request=req,
619
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
620
+ retry_config=retry_config,
621
+ )
622
+
623
+ response_data: Any = None
624
+ if utils.match_response(http_res, "200", "application/json"):
625
+ return unmarshal_json_response(operations.GetGuardrailResponse, http_res)
626
+ if utils.match_response(http_res, "401", "application/json"):
627
+ response_data = unmarshal_json_response(
628
+ errors.UnauthorizedResponseErrorData, http_res
629
+ )
630
+ raise errors.UnauthorizedResponseError(response_data, http_res)
631
+ if utils.match_response(http_res, "404", "application/json"):
632
+ response_data = unmarshal_json_response(
633
+ errors.NotFoundResponseErrorData, http_res
634
+ )
635
+ raise errors.NotFoundResponseError(response_data, http_res)
636
+ if utils.match_response(http_res, "500", "application/json"):
637
+ response_data = unmarshal_json_response(
638
+ errors.InternalServerResponseErrorData, http_res
639
+ )
640
+ raise errors.InternalServerResponseError(response_data, http_res)
641
+ if utils.match_response(http_res, "4XX", "*"):
642
+ http_res_text = utils.stream_to_text(http_res)
643
+ raise errors.OpenRouterDefaultError(
644
+ "API error occurred", http_res, http_res_text
645
+ )
646
+ if utils.match_response(http_res, "5XX", "*"):
647
+ http_res_text = utils.stream_to_text(http_res)
648
+ raise errors.OpenRouterDefaultError(
649
+ "API error occurred", http_res, http_res_text
650
+ )
651
+
652
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
653
+
654
+ async def get_async(
655
+ self,
656
+ *,
657
+ id: str,
658
+ http_referer: Optional[str] = None,
659
+ x_title: Optional[str] = None,
660
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
661
+ server_url: Optional[str] = None,
662
+ timeout_ms: Optional[int] = None,
663
+ http_headers: Optional[Mapping[str, str]] = None,
664
+ ) -> operations.GetGuardrailResponse:
665
+ r"""Get a guardrail
666
+
667
+ Get a single guardrail by ID. [Management key](/docs/guides/overview/auth/management-api-keys) required.
668
+
669
+ :param id: The unique identifier of the guardrail to retrieve
670
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
671
+ This is used to track API usage per application.
672
+
673
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
674
+
675
+ :param retries: Override the default retry configuration for this method
676
+ :param server_url: Override the default server URL for this method
677
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
678
+ :param http_headers: Additional headers to set or replace on requests.
679
+ """
680
+ base_url = None
681
+ url_variables = None
682
+ if timeout_ms is None:
683
+ timeout_ms = self.sdk_configuration.timeout_ms
684
+
685
+ if server_url is not None:
686
+ base_url = server_url
687
+ else:
688
+ base_url = self._get_url(base_url, url_variables)
689
+
690
+ request = operations.GetGuardrailRequest(
691
+ http_referer=http_referer,
692
+ x_title=x_title,
693
+ id=id,
694
+ )
695
+
696
+ req = self._build_request_async(
697
+ method="GET",
698
+ path="/guardrails/{id}",
699
+ base_url=base_url,
700
+ url_variables=url_variables,
701
+ request=request,
702
+ request_body_required=False,
703
+ request_has_path_params=True,
704
+ request_has_query_params=True,
705
+ user_agent_header="user-agent",
706
+ accept_header_value="application/json",
707
+ http_headers=http_headers,
708
+ _globals=operations.GetGuardrailGlobals(
709
+ http_referer=self.sdk_configuration.globals.http_referer,
710
+ x_title=self.sdk_configuration.globals.x_title,
711
+ ),
712
+ security=self.sdk_configuration.security,
713
+ allow_empty_value=None,
714
+ timeout_ms=timeout_ms,
715
+ )
716
+
717
+ if retries == UNSET:
718
+ if self.sdk_configuration.retry_config is not UNSET:
719
+ retries = self.sdk_configuration.retry_config
720
+
721
+ retry_config = None
722
+ if isinstance(retries, utils.RetryConfig):
723
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
724
+
725
+ http_res = await self.do_request_async(
726
+ hook_ctx=HookContext(
727
+ config=self.sdk_configuration,
728
+ base_url=base_url or "",
729
+ operation_id="getGuardrail",
730
+ oauth2_scopes=None,
731
+ security_source=get_security_from_env(
732
+ self.sdk_configuration.security, components.Security
733
+ ),
734
+ ),
735
+ request=req,
736
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
737
+ retry_config=retry_config,
738
+ )
739
+
740
+ response_data: Any = None
741
+ if utils.match_response(http_res, "200", "application/json"):
742
+ return unmarshal_json_response(operations.GetGuardrailResponse, http_res)
743
+ if utils.match_response(http_res, "401", "application/json"):
744
+ response_data = unmarshal_json_response(
745
+ errors.UnauthorizedResponseErrorData, http_res
746
+ )
747
+ raise errors.UnauthorizedResponseError(response_data, http_res)
748
+ if utils.match_response(http_res, "404", "application/json"):
749
+ response_data = unmarshal_json_response(
750
+ errors.NotFoundResponseErrorData, http_res
751
+ )
752
+ raise errors.NotFoundResponseError(response_data, http_res)
753
+ if utils.match_response(http_res, "500", "application/json"):
754
+ response_data = unmarshal_json_response(
755
+ errors.InternalServerResponseErrorData, http_res
756
+ )
757
+ raise errors.InternalServerResponseError(response_data, http_res)
758
+ if utils.match_response(http_res, "4XX", "*"):
759
+ http_res_text = await utils.stream_to_text_async(http_res)
760
+ raise errors.OpenRouterDefaultError(
761
+ "API error occurred", http_res, http_res_text
762
+ )
763
+ if utils.match_response(http_res, "5XX", "*"):
764
+ http_res_text = await utils.stream_to_text_async(http_res)
765
+ raise errors.OpenRouterDefaultError(
766
+ "API error occurred", http_res, http_res_text
767
+ )
768
+
769
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
770
+
771
+ def update(
772
+ self,
773
+ *,
774
+ id: str,
775
+ http_referer: Optional[str] = None,
776
+ x_title: Optional[str] = None,
777
+ name: Optional[str] = None,
778
+ description: OptionalNullable[str] = UNSET,
779
+ limit_usd: OptionalNullable[float] = UNSET,
780
+ reset_interval: OptionalNullable[
781
+ operations.UpdateGuardrailResetIntervalRequest
782
+ ] = UNSET,
783
+ allowed_providers: OptionalNullable[List[str]] = UNSET,
784
+ allowed_models: OptionalNullable[List[str]] = UNSET,
785
+ enforce_zdr: OptionalNullable[bool] = UNSET,
786
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
787
+ server_url: Optional[str] = None,
788
+ timeout_ms: Optional[int] = None,
789
+ http_headers: Optional[Mapping[str, str]] = None,
790
+ ) -> operations.UpdateGuardrailResponse:
791
+ r"""Update a guardrail
792
+
793
+ Update an existing guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
794
+
795
+ :param id: The unique identifier of the guardrail to update
796
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
797
+ This is used to track API usage per application.
798
+
799
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
800
+
801
+ :param name: New name for the guardrail
802
+ :param description: New description for the guardrail
803
+ :param limit_usd: New spending limit in USD
804
+ :param reset_interval: Interval at which the limit resets (daily, weekly, monthly)
805
+ :param allowed_providers: New list of allowed provider IDs
806
+ :param allowed_models: Array of model identifiers (slug or canonical_slug accepted)
807
+ :param enforce_zdr: Whether to enforce zero data retention
808
+ :param retries: Override the default retry configuration for this method
809
+ :param server_url: Override the default server URL for this method
810
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
811
+ :param http_headers: Additional headers to set or replace on requests.
812
+ """
813
+ base_url = None
814
+ url_variables = None
815
+ if timeout_ms is None:
816
+ timeout_ms = self.sdk_configuration.timeout_ms
817
+
818
+ if server_url is not None:
819
+ base_url = server_url
820
+ else:
821
+ base_url = self._get_url(base_url, url_variables)
822
+
823
+ request = operations.UpdateGuardrailRequest(
824
+ http_referer=http_referer,
825
+ x_title=x_title,
826
+ id=id,
827
+ request_body=operations.UpdateGuardrailRequestBody(
828
+ name=name,
829
+ description=description,
830
+ limit_usd=limit_usd,
831
+ reset_interval=reset_interval,
832
+ allowed_providers=allowed_providers,
833
+ allowed_models=allowed_models,
834
+ enforce_zdr=enforce_zdr,
835
+ ),
836
+ )
837
+
838
+ req = self._build_request(
839
+ method="PATCH",
840
+ path="/guardrails/{id}",
841
+ base_url=base_url,
842
+ url_variables=url_variables,
843
+ request=request,
844
+ request_body_required=True,
845
+ request_has_path_params=True,
846
+ request_has_query_params=True,
847
+ user_agent_header="user-agent",
848
+ accept_header_value="application/json",
849
+ http_headers=http_headers,
850
+ _globals=operations.UpdateGuardrailGlobals(
851
+ http_referer=self.sdk_configuration.globals.http_referer,
852
+ x_title=self.sdk_configuration.globals.x_title,
853
+ ),
854
+ security=self.sdk_configuration.security,
855
+ get_serialized_body=lambda: utils.serialize_request_body(
856
+ request.request_body,
857
+ False,
858
+ False,
859
+ "json",
860
+ operations.UpdateGuardrailRequestBody,
861
+ ),
862
+ allow_empty_value=None,
863
+ timeout_ms=timeout_ms,
864
+ )
865
+
866
+ if retries == UNSET:
867
+ if self.sdk_configuration.retry_config is not UNSET:
868
+ retries = self.sdk_configuration.retry_config
869
+
870
+ retry_config = None
871
+ if isinstance(retries, utils.RetryConfig):
872
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
873
+
874
+ http_res = self.do_request(
875
+ hook_ctx=HookContext(
876
+ config=self.sdk_configuration,
877
+ base_url=base_url or "",
878
+ operation_id="updateGuardrail",
879
+ oauth2_scopes=None,
880
+ security_source=get_security_from_env(
881
+ self.sdk_configuration.security, components.Security
882
+ ),
883
+ ),
884
+ request=req,
885
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
886
+ retry_config=retry_config,
887
+ )
888
+
889
+ response_data: Any = None
890
+ if utils.match_response(http_res, "200", "application/json"):
891
+ return unmarshal_json_response(operations.UpdateGuardrailResponse, http_res)
892
+ if utils.match_response(http_res, "400", "application/json"):
893
+ response_data = unmarshal_json_response(
894
+ errors.BadRequestResponseErrorData, http_res
895
+ )
896
+ raise errors.BadRequestResponseError(response_data, http_res)
897
+ if utils.match_response(http_res, "401", "application/json"):
898
+ response_data = unmarshal_json_response(
899
+ errors.UnauthorizedResponseErrorData, http_res
900
+ )
901
+ raise errors.UnauthorizedResponseError(response_data, http_res)
902
+ if utils.match_response(http_res, "404", "application/json"):
903
+ response_data = unmarshal_json_response(
904
+ errors.NotFoundResponseErrorData, http_res
905
+ )
906
+ raise errors.NotFoundResponseError(response_data, http_res)
907
+ if utils.match_response(http_res, "500", "application/json"):
908
+ response_data = unmarshal_json_response(
909
+ errors.InternalServerResponseErrorData, http_res
910
+ )
911
+ raise errors.InternalServerResponseError(response_data, http_res)
912
+ if utils.match_response(http_res, "4XX", "*"):
913
+ http_res_text = utils.stream_to_text(http_res)
914
+ raise errors.OpenRouterDefaultError(
915
+ "API error occurred", http_res, http_res_text
916
+ )
917
+ if utils.match_response(http_res, "5XX", "*"):
918
+ http_res_text = utils.stream_to_text(http_res)
919
+ raise errors.OpenRouterDefaultError(
920
+ "API error occurred", http_res, http_res_text
921
+ )
922
+
923
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
924
+
925
+ async def update_async(
926
+ self,
927
+ *,
928
+ id: str,
929
+ http_referer: Optional[str] = None,
930
+ x_title: Optional[str] = None,
931
+ name: Optional[str] = None,
932
+ description: OptionalNullable[str] = UNSET,
933
+ limit_usd: OptionalNullable[float] = UNSET,
934
+ reset_interval: OptionalNullable[
935
+ operations.UpdateGuardrailResetIntervalRequest
936
+ ] = UNSET,
937
+ allowed_providers: OptionalNullable[List[str]] = UNSET,
938
+ allowed_models: OptionalNullable[List[str]] = UNSET,
939
+ enforce_zdr: OptionalNullable[bool] = UNSET,
940
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
941
+ server_url: Optional[str] = None,
942
+ timeout_ms: Optional[int] = None,
943
+ http_headers: Optional[Mapping[str, str]] = None,
944
+ ) -> operations.UpdateGuardrailResponse:
945
+ r"""Update a guardrail
946
+
947
+ Update an existing guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
948
+
949
+ :param id: The unique identifier of the guardrail to update
950
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
951
+ This is used to track API usage per application.
952
+
953
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
954
+
955
+ :param name: New name for the guardrail
956
+ :param description: New description for the guardrail
957
+ :param limit_usd: New spending limit in USD
958
+ :param reset_interval: Interval at which the limit resets (daily, weekly, monthly)
959
+ :param allowed_providers: New list of allowed provider IDs
960
+ :param allowed_models: Array of model identifiers (slug or canonical_slug accepted)
961
+ :param enforce_zdr: Whether to enforce zero data retention
962
+ :param retries: Override the default retry configuration for this method
963
+ :param server_url: Override the default server URL for this method
964
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
965
+ :param http_headers: Additional headers to set or replace on requests.
966
+ """
967
+ base_url = None
968
+ url_variables = None
969
+ if timeout_ms is None:
970
+ timeout_ms = self.sdk_configuration.timeout_ms
971
+
972
+ if server_url is not None:
973
+ base_url = server_url
974
+ else:
975
+ base_url = self._get_url(base_url, url_variables)
976
+
977
+ request = operations.UpdateGuardrailRequest(
978
+ http_referer=http_referer,
979
+ x_title=x_title,
980
+ id=id,
981
+ request_body=operations.UpdateGuardrailRequestBody(
982
+ name=name,
983
+ description=description,
984
+ limit_usd=limit_usd,
985
+ reset_interval=reset_interval,
986
+ allowed_providers=allowed_providers,
987
+ allowed_models=allowed_models,
988
+ enforce_zdr=enforce_zdr,
989
+ ),
990
+ )
991
+
992
+ req = self._build_request_async(
993
+ method="PATCH",
994
+ path="/guardrails/{id}",
995
+ base_url=base_url,
996
+ url_variables=url_variables,
997
+ request=request,
998
+ request_body_required=True,
999
+ request_has_path_params=True,
1000
+ request_has_query_params=True,
1001
+ user_agent_header="user-agent",
1002
+ accept_header_value="application/json",
1003
+ http_headers=http_headers,
1004
+ _globals=operations.UpdateGuardrailGlobals(
1005
+ http_referer=self.sdk_configuration.globals.http_referer,
1006
+ x_title=self.sdk_configuration.globals.x_title,
1007
+ ),
1008
+ security=self.sdk_configuration.security,
1009
+ get_serialized_body=lambda: utils.serialize_request_body(
1010
+ request.request_body,
1011
+ False,
1012
+ False,
1013
+ "json",
1014
+ operations.UpdateGuardrailRequestBody,
1015
+ ),
1016
+ allow_empty_value=None,
1017
+ timeout_ms=timeout_ms,
1018
+ )
1019
+
1020
+ if retries == UNSET:
1021
+ if self.sdk_configuration.retry_config is not UNSET:
1022
+ retries = self.sdk_configuration.retry_config
1023
+
1024
+ retry_config = None
1025
+ if isinstance(retries, utils.RetryConfig):
1026
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1027
+
1028
+ http_res = await self.do_request_async(
1029
+ hook_ctx=HookContext(
1030
+ config=self.sdk_configuration,
1031
+ base_url=base_url or "",
1032
+ operation_id="updateGuardrail",
1033
+ oauth2_scopes=None,
1034
+ security_source=get_security_from_env(
1035
+ self.sdk_configuration.security, components.Security
1036
+ ),
1037
+ ),
1038
+ request=req,
1039
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
1040
+ retry_config=retry_config,
1041
+ )
1042
+
1043
+ response_data: Any = None
1044
+ if utils.match_response(http_res, "200", "application/json"):
1045
+ return unmarshal_json_response(operations.UpdateGuardrailResponse, http_res)
1046
+ if utils.match_response(http_res, "400", "application/json"):
1047
+ response_data = unmarshal_json_response(
1048
+ errors.BadRequestResponseErrorData, http_res
1049
+ )
1050
+ raise errors.BadRequestResponseError(response_data, http_res)
1051
+ if utils.match_response(http_res, "401", "application/json"):
1052
+ response_data = unmarshal_json_response(
1053
+ errors.UnauthorizedResponseErrorData, http_res
1054
+ )
1055
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1056
+ if utils.match_response(http_res, "404", "application/json"):
1057
+ response_data = unmarshal_json_response(
1058
+ errors.NotFoundResponseErrorData, http_res
1059
+ )
1060
+ raise errors.NotFoundResponseError(response_data, http_res)
1061
+ if utils.match_response(http_res, "500", "application/json"):
1062
+ response_data = unmarshal_json_response(
1063
+ errors.InternalServerResponseErrorData, http_res
1064
+ )
1065
+ raise errors.InternalServerResponseError(response_data, http_res)
1066
+ if utils.match_response(http_res, "4XX", "*"):
1067
+ http_res_text = await utils.stream_to_text_async(http_res)
1068
+ raise errors.OpenRouterDefaultError(
1069
+ "API error occurred", http_res, http_res_text
1070
+ )
1071
+ if utils.match_response(http_res, "5XX", "*"):
1072
+ http_res_text = await utils.stream_to_text_async(http_res)
1073
+ raise errors.OpenRouterDefaultError(
1074
+ "API error occurred", http_res, http_res_text
1075
+ )
1076
+
1077
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1078
+
1079
+ def delete(
1080
+ self,
1081
+ *,
1082
+ id: str,
1083
+ http_referer: Optional[str] = None,
1084
+ x_title: Optional[str] = None,
1085
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1086
+ server_url: Optional[str] = None,
1087
+ timeout_ms: Optional[int] = None,
1088
+ http_headers: Optional[Mapping[str, str]] = None,
1089
+ ) -> operations.DeleteGuardrailResponse:
1090
+ r"""Delete a guardrail
1091
+
1092
+ Delete an existing guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1093
+
1094
+ :param id: The unique identifier of the guardrail to delete
1095
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1096
+ This is used to track API usage per application.
1097
+
1098
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1099
+
1100
+ :param retries: Override the default retry configuration for this method
1101
+ :param server_url: Override the default server URL for this method
1102
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1103
+ :param http_headers: Additional headers to set or replace on requests.
1104
+ """
1105
+ base_url = None
1106
+ url_variables = None
1107
+ if timeout_ms is None:
1108
+ timeout_ms = self.sdk_configuration.timeout_ms
1109
+
1110
+ if server_url is not None:
1111
+ base_url = server_url
1112
+ else:
1113
+ base_url = self._get_url(base_url, url_variables)
1114
+
1115
+ request = operations.DeleteGuardrailRequest(
1116
+ http_referer=http_referer,
1117
+ x_title=x_title,
1118
+ id=id,
1119
+ )
1120
+
1121
+ req = self._build_request(
1122
+ method="DELETE",
1123
+ path="/guardrails/{id}",
1124
+ base_url=base_url,
1125
+ url_variables=url_variables,
1126
+ request=request,
1127
+ request_body_required=False,
1128
+ request_has_path_params=True,
1129
+ request_has_query_params=True,
1130
+ user_agent_header="user-agent",
1131
+ accept_header_value="application/json",
1132
+ http_headers=http_headers,
1133
+ _globals=operations.DeleteGuardrailGlobals(
1134
+ http_referer=self.sdk_configuration.globals.http_referer,
1135
+ x_title=self.sdk_configuration.globals.x_title,
1136
+ ),
1137
+ security=self.sdk_configuration.security,
1138
+ allow_empty_value=None,
1139
+ timeout_ms=timeout_ms,
1140
+ )
1141
+
1142
+ if retries == UNSET:
1143
+ if self.sdk_configuration.retry_config is not UNSET:
1144
+ retries = self.sdk_configuration.retry_config
1145
+
1146
+ retry_config = None
1147
+ if isinstance(retries, utils.RetryConfig):
1148
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1149
+
1150
+ http_res = self.do_request(
1151
+ hook_ctx=HookContext(
1152
+ config=self.sdk_configuration,
1153
+ base_url=base_url or "",
1154
+ operation_id="deleteGuardrail",
1155
+ oauth2_scopes=None,
1156
+ security_source=get_security_from_env(
1157
+ self.sdk_configuration.security, components.Security
1158
+ ),
1159
+ ),
1160
+ request=req,
1161
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
1162
+ retry_config=retry_config,
1163
+ )
1164
+
1165
+ response_data: Any = None
1166
+ if utils.match_response(http_res, "200", "application/json"):
1167
+ return unmarshal_json_response(operations.DeleteGuardrailResponse, http_res)
1168
+ if utils.match_response(http_res, "401", "application/json"):
1169
+ response_data = unmarshal_json_response(
1170
+ errors.UnauthorizedResponseErrorData, http_res
1171
+ )
1172
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1173
+ if utils.match_response(http_res, "404", "application/json"):
1174
+ response_data = unmarshal_json_response(
1175
+ errors.NotFoundResponseErrorData, http_res
1176
+ )
1177
+ raise errors.NotFoundResponseError(response_data, http_res)
1178
+ if utils.match_response(http_res, "500", "application/json"):
1179
+ response_data = unmarshal_json_response(
1180
+ errors.InternalServerResponseErrorData, http_res
1181
+ )
1182
+ raise errors.InternalServerResponseError(response_data, http_res)
1183
+ if utils.match_response(http_res, "4XX", "*"):
1184
+ http_res_text = utils.stream_to_text(http_res)
1185
+ raise errors.OpenRouterDefaultError(
1186
+ "API error occurred", http_res, http_res_text
1187
+ )
1188
+ if utils.match_response(http_res, "5XX", "*"):
1189
+ http_res_text = utils.stream_to_text(http_res)
1190
+ raise errors.OpenRouterDefaultError(
1191
+ "API error occurred", http_res, http_res_text
1192
+ )
1193
+
1194
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1195
+
1196
+ async def delete_async(
1197
+ self,
1198
+ *,
1199
+ id: str,
1200
+ http_referer: Optional[str] = None,
1201
+ x_title: Optional[str] = None,
1202
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1203
+ server_url: Optional[str] = None,
1204
+ timeout_ms: Optional[int] = None,
1205
+ http_headers: Optional[Mapping[str, str]] = None,
1206
+ ) -> operations.DeleteGuardrailResponse:
1207
+ r"""Delete a guardrail
1208
+
1209
+ Delete an existing guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1210
+
1211
+ :param id: The unique identifier of the guardrail to delete
1212
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1213
+ This is used to track API usage per application.
1214
+
1215
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1216
+
1217
+ :param retries: Override the default retry configuration for this method
1218
+ :param server_url: Override the default server URL for this method
1219
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1220
+ :param http_headers: Additional headers to set or replace on requests.
1221
+ """
1222
+ base_url = None
1223
+ url_variables = None
1224
+ if timeout_ms is None:
1225
+ timeout_ms = self.sdk_configuration.timeout_ms
1226
+
1227
+ if server_url is not None:
1228
+ base_url = server_url
1229
+ else:
1230
+ base_url = self._get_url(base_url, url_variables)
1231
+
1232
+ request = operations.DeleteGuardrailRequest(
1233
+ http_referer=http_referer,
1234
+ x_title=x_title,
1235
+ id=id,
1236
+ )
1237
+
1238
+ req = self._build_request_async(
1239
+ method="DELETE",
1240
+ path="/guardrails/{id}",
1241
+ base_url=base_url,
1242
+ url_variables=url_variables,
1243
+ request=request,
1244
+ request_body_required=False,
1245
+ request_has_path_params=True,
1246
+ request_has_query_params=True,
1247
+ user_agent_header="user-agent",
1248
+ accept_header_value="application/json",
1249
+ http_headers=http_headers,
1250
+ _globals=operations.DeleteGuardrailGlobals(
1251
+ http_referer=self.sdk_configuration.globals.http_referer,
1252
+ x_title=self.sdk_configuration.globals.x_title,
1253
+ ),
1254
+ security=self.sdk_configuration.security,
1255
+ allow_empty_value=None,
1256
+ timeout_ms=timeout_ms,
1257
+ )
1258
+
1259
+ if retries == UNSET:
1260
+ if self.sdk_configuration.retry_config is not UNSET:
1261
+ retries = self.sdk_configuration.retry_config
1262
+
1263
+ retry_config = None
1264
+ if isinstance(retries, utils.RetryConfig):
1265
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1266
+
1267
+ http_res = await self.do_request_async(
1268
+ hook_ctx=HookContext(
1269
+ config=self.sdk_configuration,
1270
+ base_url=base_url or "",
1271
+ operation_id="deleteGuardrail",
1272
+ oauth2_scopes=None,
1273
+ security_source=get_security_from_env(
1274
+ self.sdk_configuration.security, components.Security
1275
+ ),
1276
+ ),
1277
+ request=req,
1278
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
1279
+ retry_config=retry_config,
1280
+ )
1281
+
1282
+ response_data: Any = None
1283
+ if utils.match_response(http_res, "200", "application/json"):
1284
+ return unmarshal_json_response(operations.DeleteGuardrailResponse, http_res)
1285
+ if utils.match_response(http_res, "401", "application/json"):
1286
+ response_data = unmarshal_json_response(
1287
+ errors.UnauthorizedResponseErrorData, http_res
1288
+ )
1289
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1290
+ if utils.match_response(http_res, "404", "application/json"):
1291
+ response_data = unmarshal_json_response(
1292
+ errors.NotFoundResponseErrorData, http_res
1293
+ )
1294
+ raise errors.NotFoundResponseError(response_data, http_res)
1295
+ if utils.match_response(http_res, "500", "application/json"):
1296
+ response_data = unmarshal_json_response(
1297
+ errors.InternalServerResponseErrorData, http_res
1298
+ )
1299
+ raise errors.InternalServerResponseError(response_data, http_res)
1300
+ if utils.match_response(http_res, "4XX", "*"):
1301
+ http_res_text = await utils.stream_to_text_async(http_res)
1302
+ raise errors.OpenRouterDefaultError(
1303
+ "API error occurred", http_res, http_res_text
1304
+ )
1305
+ if utils.match_response(http_res, "5XX", "*"):
1306
+ http_res_text = await utils.stream_to_text_async(http_res)
1307
+ raise errors.OpenRouterDefaultError(
1308
+ "API error occurred", http_res, http_res_text
1309
+ )
1310
+
1311
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1312
+
1313
+ def list_key_assignments(
1314
+ self,
1315
+ *,
1316
+ http_referer: Optional[str] = None,
1317
+ x_title: Optional[str] = None,
1318
+ offset: Optional[str] = None,
1319
+ limit: Optional[str] = None,
1320
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1321
+ server_url: Optional[str] = None,
1322
+ timeout_ms: Optional[int] = None,
1323
+ http_headers: Optional[Mapping[str, str]] = None,
1324
+ ) -> operations.ListKeyAssignmentsResponse:
1325
+ r"""List all key assignments
1326
+
1327
+ List all API key guardrail assignments for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1328
+
1329
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1330
+ This is used to track API usage per application.
1331
+
1332
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1333
+
1334
+ :param offset: Number of records to skip for pagination
1335
+ :param limit: Maximum number of records to return (max 100)
1336
+ :param retries: Override the default retry configuration for this method
1337
+ :param server_url: Override the default server URL for this method
1338
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1339
+ :param http_headers: Additional headers to set or replace on requests.
1340
+ """
1341
+ base_url = None
1342
+ url_variables = None
1343
+ if timeout_ms is None:
1344
+ timeout_ms = self.sdk_configuration.timeout_ms
1345
+
1346
+ if server_url is not None:
1347
+ base_url = server_url
1348
+ else:
1349
+ base_url = self._get_url(base_url, url_variables)
1350
+
1351
+ request = operations.ListKeyAssignmentsRequest(
1352
+ http_referer=http_referer,
1353
+ x_title=x_title,
1354
+ offset=offset,
1355
+ limit=limit,
1356
+ )
1357
+
1358
+ req = self._build_request(
1359
+ method="GET",
1360
+ path="/guardrails/assignments/keys",
1361
+ base_url=base_url,
1362
+ url_variables=url_variables,
1363
+ request=request,
1364
+ request_body_required=False,
1365
+ request_has_path_params=False,
1366
+ request_has_query_params=True,
1367
+ user_agent_header="user-agent",
1368
+ accept_header_value="application/json",
1369
+ http_headers=http_headers,
1370
+ _globals=operations.ListKeyAssignmentsGlobals(
1371
+ http_referer=self.sdk_configuration.globals.http_referer,
1372
+ x_title=self.sdk_configuration.globals.x_title,
1373
+ ),
1374
+ security=self.sdk_configuration.security,
1375
+ allow_empty_value=None,
1376
+ timeout_ms=timeout_ms,
1377
+ )
1378
+
1379
+ if retries == UNSET:
1380
+ if self.sdk_configuration.retry_config is not UNSET:
1381
+ retries = self.sdk_configuration.retry_config
1382
+
1383
+ retry_config = None
1384
+ if isinstance(retries, utils.RetryConfig):
1385
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1386
+
1387
+ http_res = self.do_request(
1388
+ hook_ctx=HookContext(
1389
+ config=self.sdk_configuration,
1390
+ base_url=base_url or "",
1391
+ operation_id="listKeyAssignments",
1392
+ oauth2_scopes=None,
1393
+ security_source=get_security_from_env(
1394
+ self.sdk_configuration.security, components.Security
1395
+ ),
1396
+ ),
1397
+ request=req,
1398
+ error_status_codes=["401", "4XX", "500", "5XX"],
1399
+ retry_config=retry_config,
1400
+ )
1401
+
1402
+ response_data: Any = None
1403
+ if utils.match_response(http_res, "200", "application/json"):
1404
+ return unmarshal_json_response(
1405
+ operations.ListKeyAssignmentsResponse, http_res
1406
+ )
1407
+ if utils.match_response(http_res, "401", "application/json"):
1408
+ response_data = unmarshal_json_response(
1409
+ errors.UnauthorizedResponseErrorData, http_res
1410
+ )
1411
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1412
+ if utils.match_response(http_res, "500", "application/json"):
1413
+ response_data = unmarshal_json_response(
1414
+ errors.InternalServerResponseErrorData, http_res
1415
+ )
1416
+ raise errors.InternalServerResponseError(response_data, http_res)
1417
+ if utils.match_response(http_res, "4XX", "*"):
1418
+ http_res_text = utils.stream_to_text(http_res)
1419
+ raise errors.OpenRouterDefaultError(
1420
+ "API error occurred", http_res, http_res_text
1421
+ )
1422
+ if utils.match_response(http_res, "5XX", "*"):
1423
+ http_res_text = utils.stream_to_text(http_res)
1424
+ raise errors.OpenRouterDefaultError(
1425
+ "API error occurred", http_res, http_res_text
1426
+ )
1427
+
1428
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1429
+
1430
+ async def list_key_assignments_async(
1431
+ self,
1432
+ *,
1433
+ http_referer: Optional[str] = None,
1434
+ x_title: Optional[str] = None,
1435
+ offset: Optional[str] = None,
1436
+ limit: Optional[str] = None,
1437
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1438
+ server_url: Optional[str] = None,
1439
+ timeout_ms: Optional[int] = None,
1440
+ http_headers: Optional[Mapping[str, str]] = None,
1441
+ ) -> operations.ListKeyAssignmentsResponse:
1442
+ r"""List all key assignments
1443
+
1444
+ List all API key guardrail assignments for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1445
+
1446
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1447
+ This is used to track API usage per application.
1448
+
1449
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1450
+
1451
+ :param offset: Number of records to skip for pagination
1452
+ :param limit: Maximum number of records to return (max 100)
1453
+ :param retries: Override the default retry configuration for this method
1454
+ :param server_url: Override the default server URL for this method
1455
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1456
+ :param http_headers: Additional headers to set or replace on requests.
1457
+ """
1458
+ base_url = None
1459
+ url_variables = None
1460
+ if timeout_ms is None:
1461
+ timeout_ms = self.sdk_configuration.timeout_ms
1462
+
1463
+ if server_url is not None:
1464
+ base_url = server_url
1465
+ else:
1466
+ base_url = self._get_url(base_url, url_variables)
1467
+
1468
+ request = operations.ListKeyAssignmentsRequest(
1469
+ http_referer=http_referer,
1470
+ x_title=x_title,
1471
+ offset=offset,
1472
+ limit=limit,
1473
+ )
1474
+
1475
+ req = self._build_request_async(
1476
+ method="GET",
1477
+ path="/guardrails/assignments/keys",
1478
+ base_url=base_url,
1479
+ url_variables=url_variables,
1480
+ request=request,
1481
+ request_body_required=False,
1482
+ request_has_path_params=False,
1483
+ request_has_query_params=True,
1484
+ user_agent_header="user-agent",
1485
+ accept_header_value="application/json",
1486
+ http_headers=http_headers,
1487
+ _globals=operations.ListKeyAssignmentsGlobals(
1488
+ http_referer=self.sdk_configuration.globals.http_referer,
1489
+ x_title=self.sdk_configuration.globals.x_title,
1490
+ ),
1491
+ security=self.sdk_configuration.security,
1492
+ allow_empty_value=None,
1493
+ timeout_ms=timeout_ms,
1494
+ )
1495
+
1496
+ if retries == UNSET:
1497
+ if self.sdk_configuration.retry_config is not UNSET:
1498
+ retries = self.sdk_configuration.retry_config
1499
+
1500
+ retry_config = None
1501
+ if isinstance(retries, utils.RetryConfig):
1502
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1503
+
1504
+ http_res = await self.do_request_async(
1505
+ hook_ctx=HookContext(
1506
+ config=self.sdk_configuration,
1507
+ base_url=base_url or "",
1508
+ operation_id="listKeyAssignments",
1509
+ oauth2_scopes=None,
1510
+ security_source=get_security_from_env(
1511
+ self.sdk_configuration.security, components.Security
1512
+ ),
1513
+ ),
1514
+ request=req,
1515
+ error_status_codes=["401", "4XX", "500", "5XX"],
1516
+ retry_config=retry_config,
1517
+ )
1518
+
1519
+ response_data: Any = None
1520
+ if utils.match_response(http_res, "200", "application/json"):
1521
+ return unmarshal_json_response(
1522
+ operations.ListKeyAssignmentsResponse, http_res
1523
+ )
1524
+ if utils.match_response(http_res, "401", "application/json"):
1525
+ response_data = unmarshal_json_response(
1526
+ errors.UnauthorizedResponseErrorData, http_res
1527
+ )
1528
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1529
+ if utils.match_response(http_res, "500", "application/json"):
1530
+ response_data = unmarshal_json_response(
1531
+ errors.InternalServerResponseErrorData, http_res
1532
+ )
1533
+ raise errors.InternalServerResponseError(response_data, http_res)
1534
+ if utils.match_response(http_res, "4XX", "*"):
1535
+ http_res_text = await utils.stream_to_text_async(http_res)
1536
+ raise errors.OpenRouterDefaultError(
1537
+ "API error occurred", http_res, http_res_text
1538
+ )
1539
+ if utils.match_response(http_res, "5XX", "*"):
1540
+ http_res_text = await utils.stream_to_text_async(http_res)
1541
+ raise errors.OpenRouterDefaultError(
1542
+ "API error occurred", http_res, http_res_text
1543
+ )
1544
+
1545
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1546
+
1547
+ def list_member_assignments(
1548
+ self,
1549
+ *,
1550
+ http_referer: Optional[str] = None,
1551
+ x_title: Optional[str] = None,
1552
+ offset: Optional[str] = None,
1553
+ limit: Optional[str] = None,
1554
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1555
+ server_url: Optional[str] = None,
1556
+ timeout_ms: Optional[int] = None,
1557
+ http_headers: Optional[Mapping[str, str]] = None,
1558
+ ) -> operations.ListMemberAssignmentsResponse:
1559
+ r"""List all member assignments
1560
+
1561
+ List all organization member guardrail assignments for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1562
+
1563
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1564
+ This is used to track API usage per application.
1565
+
1566
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1567
+
1568
+ :param offset: Number of records to skip for pagination
1569
+ :param limit: Maximum number of records to return (max 100)
1570
+ :param retries: Override the default retry configuration for this method
1571
+ :param server_url: Override the default server URL for this method
1572
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1573
+ :param http_headers: Additional headers to set or replace on requests.
1574
+ """
1575
+ base_url = None
1576
+ url_variables = None
1577
+ if timeout_ms is None:
1578
+ timeout_ms = self.sdk_configuration.timeout_ms
1579
+
1580
+ if server_url is not None:
1581
+ base_url = server_url
1582
+ else:
1583
+ base_url = self._get_url(base_url, url_variables)
1584
+
1585
+ request = operations.ListMemberAssignmentsRequest(
1586
+ http_referer=http_referer,
1587
+ x_title=x_title,
1588
+ offset=offset,
1589
+ limit=limit,
1590
+ )
1591
+
1592
+ req = self._build_request(
1593
+ method="GET",
1594
+ path="/guardrails/assignments/members",
1595
+ base_url=base_url,
1596
+ url_variables=url_variables,
1597
+ request=request,
1598
+ request_body_required=False,
1599
+ request_has_path_params=False,
1600
+ request_has_query_params=True,
1601
+ user_agent_header="user-agent",
1602
+ accept_header_value="application/json",
1603
+ http_headers=http_headers,
1604
+ _globals=operations.ListMemberAssignmentsGlobals(
1605
+ http_referer=self.sdk_configuration.globals.http_referer,
1606
+ x_title=self.sdk_configuration.globals.x_title,
1607
+ ),
1608
+ security=self.sdk_configuration.security,
1609
+ allow_empty_value=None,
1610
+ timeout_ms=timeout_ms,
1611
+ )
1612
+
1613
+ if retries == UNSET:
1614
+ if self.sdk_configuration.retry_config is not UNSET:
1615
+ retries = self.sdk_configuration.retry_config
1616
+
1617
+ retry_config = None
1618
+ if isinstance(retries, utils.RetryConfig):
1619
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1620
+
1621
+ http_res = self.do_request(
1622
+ hook_ctx=HookContext(
1623
+ config=self.sdk_configuration,
1624
+ base_url=base_url or "",
1625
+ operation_id="listMemberAssignments",
1626
+ oauth2_scopes=None,
1627
+ security_source=get_security_from_env(
1628
+ self.sdk_configuration.security, components.Security
1629
+ ),
1630
+ ),
1631
+ request=req,
1632
+ error_status_codes=["401", "4XX", "500", "5XX"],
1633
+ retry_config=retry_config,
1634
+ )
1635
+
1636
+ response_data: Any = None
1637
+ if utils.match_response(http_res, "200", "application/json"):
1638
+ return unmarshal_json_response(
1639
+ operations.ListMemberAssignmentsResponse, http_res
1640
+ )
1641
+ if utils.match_response(http_res, "401", "application/json"):
1642
+ response_data = unmarshal_json_response(
1643
+ errors.UnauthorizedResponseErrorData, http_res
1644
+ )
1645
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1646
+ if utils.match_response(http_res, "500", "application/json"):
1647
+ response_data = unmarshal_json_response(
1648
+ errors.InternalServerResponseErrorData, http_res
1649
+ )
1650
+ raise errors.InternalServerResponseError(response_data, http_res)
1651
+ if utils.match_response(http_res, "4XX", "*"):
1652
+ http_res_text = utils.stream_to_text(http_res)
1653
+ raise errors.OpenRouterDefaultError(
1654
+ "API error occurred", http_res, http_res_text
1655
+ )
1656
+ if utils.match_response(http_res, "5XX", "*"):
1657
+ http_res_text = utils.stream_to_text(http_res)
1658
+ raise errors.OpenRouterDefaultError(
1659
+ "API error occurred", http_res, http_res_text
1660
+ )
1661
+
1662
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1663
+
1664
+ async def list_member_assignments_async(
1665
+ self,
1666
+ *,
1667
+ http_referer: Optional[str] = None,
1668
+ x_title: Optional[str] = None,
1669
+ offset: Optional[str] = None,
1670
+ limit: Optional[str] = None,
1671
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1672
+ server_url: Optional[str] = None,
1673
+ timeout_ms: Optional[int] = None,
1674
+ http_headers: Optional[Mapping[str, str]] = None,
1675
+ ) -> operations.ListMemberAssignmentsResponse:
1676
+ r"""List all member assignments
1677
+
1678
+ List all organization member guardrail assignments for the authenticated user. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1679
+
1680
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1681
+ This is used to track API usage per application.
1682
+
1683
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1684
+
1685
+ :param offset: Number of records to skip for pagination
1686
+ :param limit: Maximum number of records to return (max 100)
1687
+ :param retries: Override the default retry configuration for this method
1688
+ :param server_url: Override the default server URL for this method
1689
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1690
+ :param http_headers: Additional headers to set or replace on requests.
1691
+ """
1692
+ base_url = None
1693
+ url_variables = None
1694
+ if timeout_ms is None:
1695
+ timeout_ms = self.sdk_configuration.timeout_ms
1696
+
1697
+ if server_url is not None:
1698
+ base_url = server_url
1699
+ else:
1700
+ base_url = self._get_url(base_url, url_variables)
1701
+
1702
+ request = operations.ListMemberAssignmentsRequest(
1703
+ http_referer=http_referer,
1704
+ x_title=x_title,
1705
+ offset=offset,
1706
+ limit=limit,
1707
+ )
1708
+
1709
+ req = self._build_request_async(
1710
+ method="GET",
1711
+ path="/guardrails/assignments/members",
1712
+ base_url=base_url,
1713
+ url_variables=url_variables,
1714
+ request=request,
1715
+ request_body_required=False,
1716
+ request_has_path_params=False,
1717
+ request_has_query_params=True,
1718
+ user_agent_header="user-agent",
1719
+ accept_header_value="application/json",
1720
+ http_headers=http_headers,
1721
+ _globals=operations.ListMemberAssignmentsGlobals(
1722
+ http_referer=self.sdk_configuration.globals.http_referer,
1723
+ x_title=self.sdk_configuration.globals.x_title,
1724
+ ),
1725
+ security=self.sdk_configuration.security,
1726
+ allow_empty_value=None,
1727
+ timeout_ms=timeout_ms,
1728
+ )
1729
+
1730
+ if retries == UNSET:
1731
+ if self.sdk_configuration.retry_config is not UNSET:
1732
+ retries = self.sdk_configuration.retry_config
1733
+
1734
+ retry_config = None
1735
+ if isinstance(retries, utils.RetryConfig):
1736
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1737
+
1738
+ http_res = await self.do_request_async(
1739
+ hook_ctx=HookContext(
1740
+ config=self.sdk_configuration,
1741
+ base_url=base_url or "",
1742
+ operation_id="listMemberAssignments",
1743
+ oauth2_scopes=None,
1744
+ security_source=get_security_from_env(
1745
+ self.sdk_configuration.security, components.Security
1746
+ ),
1747
+ ),
1748
+ request=req,
1749
+ error_status_codes=["401", "4XX", "500", "5XX"],
1750
+ retry_config=retry_config,
1751
+ )
1752
+
1753
+ response_data: Any = None
1754
+ if utils.match_response(http_res, "200", "application/json"):
1755
+ return unmarshal_json_response(
1756
+ operations.ListMemberAssignmentsResponse, http_res
1757
+ )
1758
+ if utils.match_response(http_res, "401", "application/json"):
1759
+ response_data = unmarshal_json_response(
1760
+ errors.UnauthorizedResponseErrorData, http_res
1761
+ )
1762
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1763
+ if utils.match_response(http_res, "500", "application/json"):
1764
+ response_data = unmarshal_json_response(
1765
+ errors.InternalServerResponseErrorData, http_res
1766
+ )
1767
+ raise errors.InternalServerResponseError(response_data, http_res)
1768
+ if utils.match_response(http_res, "4XX", "*"):
1769
+ http_res_text = await utils.stream_to_text_async(http_res)
1770
+ raise errors.OpenRouterDefaultError(
1771
+ "API error occurred", http_res, http_res_text
1772
+ )
1773
+ if utils.match_response(http_res, "5XX", "*"):
1774
+ http_res_text = await utils.stream_to_text_async(http_res)
1775
+ raise errors.OpenRouterDefaultError(
1776
+ "API error occurred", http_res, http_res_text
1777
+ )
1778
+
1779
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1780
+
1781
+ def list_guardrail_key_assignments(
1782
+ self,
1783
+ *,
1784
+ id: str,
1785
+ http_referer: Optional[str] = None,
1786
+ x_title: Optional[str] = None,
1787
+ offset: Optional[str] = None,
1788
+ limit: Optional[str] = None,
1789
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1790
+ server_url: Optional[str] = None,
1791
+ timeout_ms: Optional[int] = None,
1792
+ http_headers: Optional[Mapping[str, str]] = None,
1793
+ ) -> operations.ListGuardrailKeyAssignmentsResponse:
1794
+ r"""List key assignments for a guardrail
1795
+
1796
+ List all API key assignments for a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1797
+
1798
+ :param id: The unique identifier of the guardrail
1799
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1800
+ This is used to track API usage per application.
1801
+
1802
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1803
+
1804
+ :param offset: Number of records to skip for pagination
1805
+ :param limit: Maximum number of records to return (max 100)
1806
+ :param retries: Override the default retry configuration for this method
1807
+ :param server_url: Override the default server URL for this method
1808
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1809
+ :param http_headers: Additional headers to set or replace on requests.
1810
+ """
1811
+ base_url = None
1812
+ url_variables = None
1813
+ if timeout_ms is None:
1814
+ timeout_ms = self.sdk_configuration.timeout_ms
1815
+
1816
+ if server_url is not None:
1817
+ base_url = server_url
1818
+ else:
1819
+ base_url = self._get_url(base_url, url_variables)
1820
+
1821
+ request = operations.ListGuardrailKeyAssignmentsRequest(
1822
+ http_referer=http_referer,
1823
+ x_title=x_title,
1824
+ id=id,
1825
+ offset=offset,
1826
+ limit=limit,
1827
+ )
1828
+
1829
+ req = self._build_request(
1830
+ method="GET",
1831
+ path="/guardrails/{id}/assignments/keys",
1832
+ base_url=base_url,
1833
+ url_variables=url_variables,
1834
+ request=request,
1835
+ request_body_required=False,
1836
+ request_has_path_params=True,
1837
+ request_has_query_params=True,
1838
+ user_agent_header="user-agent",
1839
+ accept_header_value="application/json",
1840
+ http_headers=http_headers,
1841
+ _globals=operations.ListGuardrailKeyAssignmentsGlobals(
1842
+ http_referer=self.sdk_configuration.globals.http_referer,
1843
+ x_title=self.sdk_configuration.globals.x_title,
1844
+ ),
1845
+ security=self.sdk_configuration.security,
1846
+ allow_empty_value=None,
1847
+ timeout_ms=timeout_ms,
1848
+ )
1849
+
1850
+ if retries == UNSET:
1851
+ if self.sdk_configuration.retry_config is not UNSET:
1852
+ retries = self.sdk_configuration.retry_config
1853
+
1854
+ retry_config = None
1855
+ if isinstance(retries, utils.RetryConfig):
1856
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1857
+
1858
+ http_res = self.do_request(
1859
+ hook_ctx=HookContext(
1860
+ config=self.sdk_configuration,
1861
+ base_url=base_url or "",
1862
+ operation_id="listGuardrailKeyAssignments",
1863
+ oauth2_scopes=None,
1864
+ security_source=get_security_from_env(
1865
+ self.sdk_configuration.security, components.Security
1866
+ ),
1867
+ ),
1868
+ request=req,
1869
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
1870
+ retry_config=retry_config,
1871
+ )
1872
+
1873
+ response_data: Any = None
1874
+ if utils.match_response(http_res, "200", "application/json"):
1875
+ return unmarshal_json_response(
1876
+ operations.ListGuardrailKeyAssignmentsResponse, http_res
1877
+ )
1878
+ if utils.match_response(http_res, "401", "application/json"):
1879
+ response_data = unmarshal_json_response(
1880
+ errors.UnauthorizedResponseErrorData, http_res
1881
+ )
1882
+ raise errors.UnauthorizedResponseError(response_data, http_res)
1883
+ if utils.match_response(http_res, "404", "application/json"):
1884
+ response_data = unmarshal_json_response(
1885
+ errors.NotFoundResponseErrorData, http_res
1886
+ )
1887
+ raise errors.NotFoundResponseError(response_data, http_res)
1888
+ if utils.match_response(http_res, "500", "application/json"):
1889
+ response_data = unmarshal_json_response(
1890
+ errors.InternalServerResponseErrorData, http_res
1891
+ )
1892
+ raise errors.InternalServerResponseError(response_data, http_res)
1893
+ if utils.match_response(http_res, "4XX", "*"):
1894
+ http_res_text = utils.stream_to_text(http_res)
1895
+ raise errors.OpenRouterDefaultError(
1896
+ "API error occurred", http_res, http_res_text
1897
+ )
1898
+ if utils.match_response(http_res, "5XX", "*"):
1899
+ http_res_text = utils.stream_to_text(http_res)
1900
+ raise errors.OpenRouterDefaultError(
1901
+ "API error occurred", http_res, http_res_text
1902
+ )
1903
+
1904
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
1905
+
1906
+ async def list_guardrail_key_assignments_async(
1907
+ self,
1908
+ *,
1909
+ id: str,
1910
+ http_referer: Optional[str] = None,
1911
+ x_title: Optional[str] = None,
1912
+ offset: Optional[str] = None,
1913
+ limit: Optional[str] = None,
1914
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1915
+ server_url: Optional[str] = None,
1916
+ timeout_ms: Optional[int] = None,
1917
+ http_headers: Optional[Mapping[str, str]] = None,
1918
+ ) -> operations.ListGuardrailKeyAssignmentsResponse:
1919
+ r"""List key assignments for a guardrail
1920
+
1921
+ List all API key assignments for a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
1922
+
1923
+ :param id: The unique identifier of the guardrail
1924
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
1925
+ This is used to track API usage per application.
1926
+
1927
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
1928
+
1929
+ :param offset: Number of records to skip for pagination
1930
+ :param limit: Maximum number of records to return (max 100)
1931
+ :param retries: Override the default retry configuration for this method
1932
+ :param server_url: Override the default server URL for this method
1933
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1934
+ :param http_headers: Additional headers to set or replace on requests.
1935
+ """
1936
+ base_url = None
1937
+ url_variables = None
1938
+ if timeout_ms is None:
1939
+ timeout_ms = self.sdk_configuration.timeout_ms
1940
+
1941
+ if server_url is not None:
1942
+ base_url = server_url
1943
+ else:
1944
+ base_url = self._get_url(base_url, url_variables)
1945
+
1946
+ request = operations.ListGuardrailKeyAssignmentsRequest(
1947
+ http_referer=http_referer,
1948
+ x_title=x_title,
1949
+ id=id,
1950
+ offset=offset,
1951
+ limit=limit,
1952
+ )
1953
+
1954
+ req = self._build_request_async(
1955
+ method="GET",
1956
+ path="/guardrails/{id}/assignments/keys",
1957
+ base_url=base_url,
1958
+ url_variables=url_variables,
1959
+ request=request,
1960
+ request_body_required=False,
1961
+ request_has_path_params=True,
1962
+ request_has_query_params=True,
1963
+ user_agent_header="user-agent",
1964
+ accept_header_value="application/json",
1965
+ http_headers=http_headers,
1966
+ _globals=operations.ListGuardrailKeyAssignmentsGlobals(
1967
+ http_referer=self.sdk_configuration.globals.http_referer,
1968
+ x_title=self.sdk_configuration.globals.x_title,
1969
+ ),
1970
+ security=self.sdk_configuration.security,
1971
+ allow_empty_value=None,
1972
+ timeout_ms=timeout_ms,
1973
+ )
1974
+
1975
+ if retries == UNSET:
1976
+ if self.sdk_configuration.retry_config is not UNSET:
1977
+ retries = self.sdk_configuration.retry_config
1978
+
1979
+ retry_config = None
1980
+ if isinstance(retries, utils.RetryConfig):
1981
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1982
+
1983
+ http_res = await self.do_request_async(
1984
+ hook_ctx=HookContext(
1985
+ config=self.sdk_configuration,
1986
+ base_url=base_url or "",
1987
+ operation_id="listGuardrailKeyAssignments",
1988
+ oauth2_scopes=None,
1989
+ security_source=get_security_from_env(
1990
+ self.sdk_configuration.security, components.Security
1991
+ ),
1992
+ ),
1993
+ request=req,
1994
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
1995
+ retry_config=retry_config,
1996
+ )
1997
+
1998
+ response_data: Any = None
1999
+ if utils.match_response(http_res, "200", "application/json"):
2000
+ return unmarshal_json_response(
2001
+ operations.ListGuardrailKeyAssignmentsResponse, http_res
2002
+ )
2003
+ if utils.match_response(http_res, "401", "application/json"):
2004
+ response_data = unmarshal_json_response(
2005
+ errors.UnauthorizedResponseErrorData, http_res
2006
+ )
2007
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2008
+ if utils.match_response(http_res, "404", "application/json"):
2009
+ response_data = unmarshal_json_response(
2010
+ errors.NotFoundResponseErrorData, http_res
2011
+ )
2012
+ raise errors.NotFoundResponseError(response_data, http_res)
2013
+ if utils.match_response(http_res, "500", "application/json"):
2014
+ response_data = unmarshal_json_response(
2015
+ errors.InternalServerResponseErrorData, http_res
2016
+ )
2017
+ raise errors.InternalServerResponseError(response_data, http_res)
2018
+ if utils.match_response(http_res, "4XX", "*"):
2019
+ http_res_text = await utils.stream_to_text_async(http_res)
2020
+ raise errors.OpenRouterDefaultError(
2021
+ "API error occurred", http_res, http_res_text
2022
+ )
2023
+ if utils.match_response(http_res, "5XX", "*"):
2024
+ http_res_text = await utils.stream_to_text_async(http_res)
2025
+ raise errors.OpenRouterDefaultError(
2026
+ "API error occurred", http_res, http_res_text
2027
+ )
2028
+
2029
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2030
+
2031
+ def bulk_assign_keys(
2032
+ self,
2033
+ *,
2034
+ id: str,
2035
+ key_hashes: List[str],
2036
+ http_referer: Optional[str] = None,
2037
+ x_title: Optional[str] = None,
2038
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2039
+ server_url: Optional[str] = None,
2040
+ timeout_ms: Optional[int] = None,
2041
+ http_headers: Optional[Mapping[str, str]] = None,
2042
+ ) -> operations.BulkAssignKeysToGuardrailResponse:
2043
+ r"""Bulk assign keys to a guardrail
2044
+
2045
+ Assign multiple API keys to a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2046
+
2047
+ :param id: The unique identifier of the guardrail
2048
+ :param key_hashes: Array of API key hashes to assign to the guardrail
2049
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2050
+ This is used to track API usage per application.
2051
+
2052
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2053
+
2054
+ :param retries: Override the default retry configuration for this method
2055
+ :param server_url: Override the default server URL for this method
2056
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2057
+ :param http_headers: Additional headers to set or replace on requests.
2058
+ """
2059
+ base_url = None
2060
+ url_variables = None
2061
+ if timeout_ms is None:
2062
+ timeout_ms = self.sdk_configuration.timeout_ms
2063
+
2064
+ if server_url is not None:
2065
+ base_url = server_url
2066
+ else:
2067
+ base_url = self._get_url(base_url, url_variables)
2068
+
2069
+ request = operations.BulkAssignKeysToGuardrailRequest(
2070
+ http_referer=http_referer,
2071
+ x_title=x_title,
2072
+ id=id,
2073
+ request_body=operations.BulkAssignKeysToGuardrailRequestBody(
2074
+ key_hashes=key_hashes,
2075
+ ),
2076
+ )
2077
+
2078
+ req = self._build_request(
2079
+ method="POST",
2080
+ path="/guardrails/{id}/assignments/keys",
2081
+ base_url=base_url,
2082
+ url_variables=url_variables,
2083
+ request=request,
2084
+ request_body_required=True,
2085
+ request_has_path_params=True,
2086
+ request_has_query_params=True,
2087
+ user_agent_header="user-agent",
2088
+ accept_header_value="application/json",
2089
+ http_headers=http_headers,
2090
+ _globals=operations.BulkAssignKeysToGuardrailGlobals(
2091
+ http_referer=self.sdk_configuration.globals.http_referer,
2092
+ x_title=self.sdk_configuration.globals.x_title,
2093
+ ),
2094
+ security=self.sdk_configuration.security,
2095
+ get_serialized_body=lambda: utils.serialize_request_body(
2096
+ request.request_body,
2097
+ False,
2098
+ False,
2099
+ "json",
2100
+ operations.BulkAssignKeysToGuardrailRequestBody,
2101
+ ),
2102
+ allow_empty_value=None,
2103
+ timeout_ms=timeout_ms,
2104
+ )
2105
+
2106
+ if retries == UNSET:
2107
+ if self.sdk_configuration.retry_config is not UNSET:
2108
+ retries = self.sdk_configuration.retry_config
2109
+
2110
+ retry_config = None
2111
+ if isinstance(retries, utils.RetryConfig):
2112
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2113
+
2114
+ http_res = self.do_request(
2115
+ hook_ctx=HookContext(
2116
+ config=self.sdk_configuration,
2117
+ base_url=base_url or "",
2118
+ operation_id="bulkAssignKeysToGuardrail",
2119
+ oauth2_scopes=None,
2120
+ security_source=get_security_from_env(
2121
+ self.sdk_configuration.security, components.Security
2122
+ ),
2123
+ ),
2124
+ request=req,
2125
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
2126
+ retry_config=retry_config,
2127
+ )
2128
+
2129
+ response_data: Any = None
2130
+ if utils.match_response(http_res, "200", "application/json"):
2131
+ return unmarshal_json_response(
2132
+ operations.BulkAssignKeysToGuardrailResponse, http_res
2133
+ )
2134
+ if utils.match_response(http_res, "400", "application/json"):
2135
+ response_data = unmarshal_json_response(
2136
+ errors.BadRequestResponseErrorData, http_res
2137
+ )
2138
+ raise errors.BadRequestResponseError(response_data, http_res)
2139
+ if utils.match_response(http_res, "401", "application/json"):
2140
+ response_data = unmarshal_json_response(
2141
+ errors.UnauthorizedResponseErrorData, http_res
2142
+ )
2143
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2144
+ if utils.match_response(http_res, "404", "application/json"):
2145
+ response_data = unmarshal_json_response(
2146
+ errors.NotFoundResponseErrorData, http_res
2147
+ )
2148
+ raise errors.NotFoundResponseError(response_data, http_res)
2149
+ if utils.match_response(http_res, "500", "application/json"):
2150
+ response_data = unmarshal_json_response(
2151
+ errors.InternalServerResponseErrorData, http_res
2152
+ )
2153
+ raise errors.InternalServerResponseError(response_data, http_res)
2154
+ if utils.match_response(http_res, "4XX", "*"):
2155
+ http_res_text = utils.stream_to_text(http_res)
2156
+ raise errors.OpenRouterDefaultError(
2157
+ "API error occurred", http_res, http_res_text
2158
+ )
2159
+ if utils.match_response(http_res, "5XX", "*"):
2160
+ http_res_text = utils.stream_to_text(http_res)
2161
+ raise errors.OpenRouterDefaultError(
2162
+ "API error occurred", http_res, http_res_text
2163
+ )
2164
+
2165
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2166
+
2167
+ async def bulk_assign_keys_async(
2168
+ self,
2169
+ *,
2170
+ id: str,
2171
+ key_hashes: List[str],
2172
+ http_referer: Optional[str] = None,
2173
+ x_title: Optional[str] = None,
2174
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2175
+ server_url: Optional[str] = None,
2176
+ timeout_ms: Optional[int] = None,
2177
+ http_headers: Optional[Mapping[str, str]] = None,
2178
+ ) -> operations.BulkAssignKeysToGuardrailResponse:
2179
+ r"""Bulk assign keys to a guardrail
2180
+
2181
+ Assign multiple API keys to a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2182
+
2183
+ :param id: The unique identifier of the guardrail
2184
+ :param key_hashes: Array of API key hashes to assign to the guardrail
2185
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2186
+ This is used to track API usage per application.
2187
+
2188
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2189
+
2190
+ :param retries: Override the default retry configuration for this method
2191
+ :param server_url: Override the default server URL for this method
2192
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2193
+ :param http_headers: Additional headers to set or replace on requests.
2194
+ """
2195
+ base_url = None
2196
+ url_variables = None
2197
+ if timeout_ms is None:
2198
+ timeout_ms = self.sdk_configuration.timeout_ms
2199
+
2200
+ if server_url is not None:
2201
+ base_url = server_url
2202
+ else:
2203
+ base_url = self._get_url(base_url, url_variables)
2204
+
2205
+ request = operations.BulkAssignKeysToGuardrailRequest(
2206
+ http_referer=http_referer,
2207
+ x_title=x_title,
2208
+ id=id,
2209
+ request_body=operations.BulkAssignKeysToGuardrailRequestBody(
2210
+ key_hashes=key_hashes,
2211
+ ),
2212
+ )
2213
+
2214
+ req = self._build_request_async(
2215
+ method="POST",
2216
+ path="/guardrails/{id}/assignments/keys",
2217
+ base_url=base_url,
2218
+ url_variables=url_variables,
2219
+ request=request,
2220
+ request_body_required=True,
2221
+ request_has_path_params=True,
2222
+ request_has_query_params=True,
2223
+ user_agent_header="user-agent",
2224
+ accept_header_value="application/json",
2225
+ http_headers=http_headers,
2226
+ _globals=operations.BulkAssignKeysToGuardrailGlobals(
2227
+ http_referer=self.sdk_configuration.globals.http_referer,
2228
+ x_title=self.sdk_configuration.globals.x_title,
2229
+ ),
2230
+ security=self.sdk_configuration.security,
2231
+ get_serialized_body=lambda: utils.serialize_request_body(
2232
+ request.request_body,
2233
+ False,
2234
+ False,
2235
+ "json",
2236
+ operations.BulkAssignKeysToGuardrailRequestBody,
2237
+ ),
2238
+ allow_empty_value=None,
2239
+ timeout_ms=timeout_ms,
2240
+ )
2241
+
2242
+ if retries == UNSET:
2243
+ if self.sdk_configuration.retry_config is not UNSET:
2244
+ retries = self.sdk_configuration.retry_config
2245
+
2246
+ retry_config = None
2247
+ if isinstance(retries, utils.RetryConfig):
2248
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2249
+
2250
+ http_res = await self.do_request_async(
2251
+ hook_ctx=HookContext(
2252
+ config=self.sdk_configuration,
2253
+ base_url=base_url or "",
2254
+ operation_id="bulkAssignKeysToGuardrail",
2255
+ oauth2_scopes=None,
2256
+ security_source=get_security_from_env(
2257
+ self.sdk_configuration.security, components.Security
2258
+ ),
2259
+ ),
2260
+ request=req,
2261
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
2262
+ retry_config=retry_config,
2263
+ )
2264
+
2265
+ response_data: Any = None
2266
+ if utils.match_response(http_res, "200", "application/json"):
2267
+ return unmarshal_json_response(
2268
+ operations.BulkAssignKeysToGuardrailResponse, http_res
2269
+ )
2270
+ if utils.match_response(http_res, "400", "application/json"):
2271
+ response_data = unmarshal_json_response(
2272
+ errors.BadRequestResponseErrorData, http_res
2273
+ )
2274
+ raise errors.BadRequestResponseError(response_data, http_res)
2275
+ if utils.match_response(http_res, "401", "application/json"):
2276
+ response_data = unmarshal_json_response(
2277
+ errors.UnauthorizedResponseErrorData, http_res
2278
+ )
2279
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2280
+ if utils.match_response(http_res, "404", "application/json"):
2281
+ response_data = unmarshal_json_response(
2282
+ errors.NotFoundResponseErrorData, http_res
2283
+ )
2284
+ raise errors.NotFoundResponseError(response_data, http_res)
2285
+ if utils.match_response(http_res, "500", "application/json"):
2286
+ response_data = unmarshal_json_response(
2287
+ errors.InternalServerResponseErrorData, http_res
2288
+ )
2289
+ raise errors.InternalServerResponseError(response_data, http_res)
2290
+ if utils.match_response(http_res, "4XX", "*"):
2291
+ http_res_text = await utils.stream_to_text_async(http_res)
2292
+ raise errors.OpenRouterDefaultError(
2293
+ "API error occurred", http_res, http_res_text
2294
+ )
2295
+ if utils.match_response(http_res, "5XX", "*"):
2296
+ http_res_text = await utils.stream_to_text_async(http_res)
2297
+ raise errors.OpenRouterDefaultError(
2298
+ "API error occurred", http_res, http_res_text
2299
+ )
2300
+
2301
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2302
+
2303
+ def list_guardrail_member_assignments(
2304
+ self,
2305
+ *,
2306
+ id: str,
2307
+ http_referer: Optional[str] = None,
2308
+ x_title: Optional[str] = None,
2309
+ offset: Optional[str] = None,
2310
+ limit: Optional[str] = None,
2311
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2312
+ server_url: Optional[str] = None,
2313
+ timeout_ms: Optional[int] = None,
2314
+ http_headers: Optional[Mapping[str, str]] = None,
2315
+ ) -> operations.ListGuardrailMemberAssignmentsResponse:
2316
+ r"""List member assignments for a guardrail
2317
+
2318
+ List all organization member assignments for a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2319
+
2320
+ :param id: The unique identifier of the guardrail
2321
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2322
+ This is used to track API usage per application.
2323
+
2324
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2325
+
2326
+ :param offset: Number of records to skip for pagination
2327
+ :param limit: Maximum number of records to return (max 100)
2328
+ :param retries: Override the default retry configuration for this method
2329
+ :param server_url: Override the default server URL for this method
2330
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2331
+ :param http_headers: Additional headers to set or replace on requests.
2332
+ """
2333
+ base_url = None
2334
+ url_variables = None
2335
+ if timeout_ms is None:
2336
+ timeout_ms = self.sdk_configuration.timeout_ms
2337
+
2338
+ if server_url is not None:
2339
+ base_url = server_url
2340
+ else:
2341
+ base_url = self._get_url(base_url, url_variables)
2342
+
2343
+ request = operations.ListGuardrailMemberAssignmentsRequest(
2344
+ http_referer=http_referer,
2345
+ x_title=x_title,
2346
+ id=id,
2347
+ offset=offset,
2348
+ limit=limit,
2349
+ )
2350
+
2351
+ req = self._build_request(
2352
+ method="GET",
2353
+ path="/guardrails/{id}/assignments/members",
2354
+ base_url=base_url,
2355
+ url_variables=url_variables,
2356
+ request=request,
2357
+ request_body_required=False,
2358
+ request_has_path_params=True,
2359
+ request_has_query_params=True,
2360
+ user_agent_header="user-agent",
2361
+ accept_header_value="application/json",
2362
+ http_headers=http_headers,
2363
+ _globals=operations.ListGuardrailMemberAssignmentsGlobals(
2364
+ http_referer=self.sdk_configuration.globals.http_referer,
2365
+ x_title=self.sdk_configuration.globals.x_title,
2366
+ ),
2367
+ security=self.sdk_configuration.security,
2368
+ allow_empty_value=None,
2369
+ timeout_ms=timeout_ms,
2370
+ )
2371
+
2372
+ if retries == UNSET:
2373
+ if self.sdk_configuration.retry_config is not UNSET:
2374
+ retries = self.sdk_configuration.retry_config
2375
+
2376
+ retry_config = None
2377
+ if isinstance(retries, utils.RetryConfig):
2378
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2379
+
2380
+ http_res = self.do_request(
2381
+ hook_ctx=HookContext(
2382
+ config=self.sdk_configuration,
2383
+ base_url=base_url or "",
2384
+ operation_id="listGuardrailMemberAssignments",
2385
+ oauth2_scopes=None,
2386
+ security_source=get_security_from_env(
2387
+ self.sdk_configuration.security, components.Security
2388
+ ),
2389
+ ),
2390
+ request=req,
2391
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
2392
+ retry_config=retry_config,
2393
+ )
2394
+
2395
+ response_data: Any = None
2396
+ if utils.match_response(http_res, "200", "application/json"):
2397
+ return unmarshal_json_response(
2398
+ operations.ListGuardrailMemberAssignmentsResponse, http_res
2399
+ )
2400
+ if utils.match_response(http_res, "401", "application/json"):
2401
+ response_data = unmarshal_json_response(
2402
+ errors.UnauthorizedResponseErrorData, http_res
2403
+ )
2404
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2405
+ if utils.match_response(http_res, "404", "application/json"):
2406
+ response_data = unmarshal_json_response(
2407
+ errors.NotFoundResponseErrorData, http_res
2408
+ )
2409
+ raise errors.NotFoundResponseError(response_data, http_res)
2410
+ if utils.match_response(http_res, "500", "application/json"):
2411
+ response_data = unmarshal_json_response(
2412
+ errors.InternalServerResponseErrorData, http_res
2413
+ )
2414
+ raise errors.InternalServerResponseError(response_data, http_res)
2415
+ if utils.match_response(http_res, "4XX", "*"):
2416
+ http_res_text = utils.stream_to_text(http_res)
2417
+ raise errors.OpenRouterDefaultError(
2418
+ "API error occurred", http_res, http_res_text
2419
+ )
2420
+ if utils.match_response(http_res, "5XX", "*"):
2421
+ http_res_text = utils.stream_to_text(http_res)
2422
+ raise errors.OpenRouterDefaultError(
2423
+ "API error occurred", http_res, http_res_text
2424
+ )
2425
+
2426
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2427
+
2428
+ async def list_guardrail_member_assignments_async(
2429
+ self,
2430
+ *,
2431
+ id: str,
2432
+ http_referer: Optional[str] = None,
2433
+ x_title: Optional[str] = None,
2434
+ offset: Optional[str] = None,
2435
+ limit: Optional[str] = None,
2436
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2437
+ server_url: Optional[str] = None,
2438
+ timeout_ms: Optional[int] = None,
2439
+ http_headers: Optional[Mapping[str, str]] = None,
2440
+ ) -> operations.ListGuardrailMemberAssignmentsResponse:
2441
+ r"""List member assignments for a guardrail
2442
+
2443
+ List all organization member assignments for a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2444
+
2445
+ :param id: The unique identifier of the guardrail
2446
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2447
+ This is used to track API usage per application.
2448
+
2449
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2450
+
2451
+ :param offset: Number of records to skip for pagination
2452
+ :param limit: Maximum number of records to return (max 100)
2453
+ :param retries: Override the default retry configuration for this method
2454
+ :param server_url: Override the default server URL for this method
2455
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2456
+ :param http_headers: Additional headers to set or replace on requests.
2457
+ """
2458
+ base_url = None
2459
+ url_variables = None
2460
+ if timeout_ms is None:
2461
+ timeout_ms = self.sdk_configuration.timeout_ms
2462
+
2463
+ if server_url is not None:
2464
+ base_url = server_url
2465
+ else:
2466
+ base_url = self._get_url(base_url, url_variables)
2467
+
2468
+ request = operations.ListGuardrailMemberAssignmentsRequest(
2469
+ http_referer=http_referer,
2470
+ x_title=x_title,
2471
+ id=id,
2472
+ offset=offset,
2473
+ limit=limit,
2474
+ )
2475
+
2476
+ req = self._build_request_async(
2477
+ method="GET",
2478
+ path="/guardrails/{id}/assignments/members",
2479
+ base_url=base_url,
2480
+ url_variables=url_variables,
2481
+ request=request,
2482
+ request_body_required=False,
2483
+ request_has_path_params=True,
2484
+ request_has_query_params=True,
2485
+ user_agent_header="user-agent",
2486
+ accept_header_value="application/json",
2487
+ http_headers=http_headers,
2488
+ _globals=operations.ListGuardrailMemberAssignmentsGlobals(
2489
+ http_referer=self.sdk_configuration.globals.http_referer,
2490
+ x_title=self.sdk_configuration.globals.x_title,
2491
+ ),
2492
+ security=self.sdk_configuration.security,
2493
+ allow_empty_value=None,
2494
+ timeout_ms=timeout_ms,
2495
+ )
2496
+
2497
+ if retries == UNSET:
2498
+ if self.sdk_configuration.retry_config is not UNSET:
2499
+ retries = self.sdk_configuration.retry_config
2500
+
2501
+ retry_config = None
2502
+ if isinstance(retries, utils.RetryConfig):
2503
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2504
+
2505
+ http_res = await self.do_request_async(
2506
+ hook_ctx=HookContext(
2507
+ config=self.sdk_configuration,
2508
+ base_url=base_url or "",
2509
+ operation_id="listGuardrailMemberAssignments",
2510
+ oauth2_scopes=None,
2511
+ security_source=get_security_from_env(
2512
+ self.sdk_configuration.security, components.Security
2513
+ ),
2514
+ ),
2515
+ request=req,
2516
+ error_status_codes=["401", "404", "4XX", "500", "5XX"],
2517
+ retry_config=retry_config,
2518
+ )
2519
+
2520
+ response_data: Any = None
2521
+ if utils.match_response(http_res, "200", "application/json"):
2522
+ return unmarshal_json_response(
2523
+ operations.ListGuardrailMemberAssignmentsResponse, http_res
2524
+ )
2525
+ if utils.match_response(http_res, "401", "application/json"):
2526
+ response_data = unmarshal_json_response(
2527
+ errors.UnauthorizedResponseErrorData, http_res
2528
+ )
2529
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2530
+ if utils.match_response(http_res, "404", "application/json"):
2531
+ response_data = unmarshal_json_response(
2532
+ errors.NotFoundResponseErrorData, http_res
2533
+ )
2534
+ raise errors.NotFoundResponseError(response_data, http_res)
2535
+ if utils.match_response(http_res, "500", "application/json"):
2536
+ response_data = unmarshal_json_response(
2537
+ errors.InternalServerResponseErrorData, http_res
2538
+ )
2539
+ raise errors.InternalServerResponseError(response_data, http_res)
2540
+ if utils.match_response(http_res, "4XX", "*"):
2541
+ http_res_text = await utils.stream_to_text_async(http_res)
2542
+ raise errors.OpenRouterDefaultError(
2543
+ "API error occurred", http_res, http_res_text
2544
+ )
2545
+ if utils.match_response(http_res, "5XX", "*"):
2546
+ http_res_text = await utils.stream_to_text_async(http_res)
2547
+ raise errors.OpenRouterDefaultError(
2548
+ "API error occurred", http_res, http_res_text
2549
+ )
2550
+
2551
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2552
+
2553
+ def bulk_assign_members(
2554
+ self,
2555
+ *,
2556
+ id: str,
2557
+ member_user_ids: List[str],
2558
+ http_referer: Optional[str] = None,
2559
+ x_title: Optional[str] = None,
2560
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2561
+ server_url: Optional[str] = None,
2562
+ timeout_ms: Optional[int] = None,
2563
+ http_headers: Optional[Mapping[str, str]] = None,
2564
+ ) -> operations.BulkAssignMembersToGuardrailResponse:
2565
+ r"""Bulk assign members to a guardrail
2566
+
2567
+ Assign multiple organization members to a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2568
+
2569
+ :param id: The unique identifier of the guardrail
2570
+ :param member_user_ids: Array of member user IDs to assign to the guardrail
2571
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2572
+ This is used to track API usage per application.
2573
+
2574
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2575
+
2576
+ :param retries: Override the default retry configuration for this method
2577
+ :param server_url: Override the default server URL for this method
2578
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2579
+ :param http_headers: Additional headers to set or replace on requests.
2580
+ """
2581
+ base_url = None
2582
+ url_variables = None
2583
+ if timeout_ms is None:
2584
+ timeout_ms = self.sdk_configuration.timeout_ms
2585
+
2586
+ if server_url is not None:
2587
+ base_url = server_url
2588
+ else:
2589
+ base_url = self._get_url(base_url, url_variables)
2590
+
2591
+ request = operations.BulkAssignMembersToGuardrailRequest(
2592
+ http_referer=http_referer,
2593
+ x_title=x_title,
2594
+ id=id,
2595
+ request_body=operations.BulkAssignMembersToGuardrailRequestBody(
2596
+ member_user_ids=member_user_ids,
2597
+ ),
2598
+ )
2599
+
2600
+ req = self._build_request(
2601
+ method="POST",
2602
+ path="/guardrails/{id}/assignments/members",
2603
+ base_url=base_url,
2604
+ url_variables=url_variables,
2605
+ request=request,
2606
+ request_body_required=True,
2607
+ request_has_path_params=True,
2608
+ request_has_query_params=True,
2609
+ user_agent_header="user-agent",
2610
+ accept_header_value="application/json",
2611
+ http_headers=http_headers,
2612
+ _globals=operations.BulkAssignMembersToGuardrailGlobals(
2613
+ http_referer=self.sdk_configuration.globals.http_referer,
2614
+ x_title=self.sdk_configuration.globals.x_title,
2615
+ ),
2616
+ security=self.sdk_configuration.security,
2617
+ get_serialized_body=lambda: utils.serialize_request_body(
2618
+ request.request_body,
2619
+ False,
2620
+ False,
2621
+ "json",
2622
+ operations.BulkAssignMembersToGuardrailRequestBody,
2623
+ ),
2624
+ allow_empty_value=None,
2625
+ timeout_ms=timeout_ms,
2626
+ )
2627
+
2628
+ if retries == UNSET:
2629
+ if self.sdk_configuration.retry_config is not UNSET:
2630
+ retries = self.sdk_configuration.retry_config
2631
+
2632
+ retry_config = None
2633
+ if isinstance(retries, utils.RetryConfig):
2634
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2635
+
2636
+ http_res = self.do_request(
2637
+ hook_ctx=HookContext(
2638
+ config=self.sdk_configuration,
2639
+ base_url=base_url or "",
2640
+ operation_id="bulkAssignMembersToGuardrail",
2641
+ oauth2_scopes=None,
2642
+ security_source=get_security_from_env(
2643
+ self.sdk_configuration.security, components.Security
2644
+ ),
2645
+ ),
2646
+ request=req,
2647
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
2648
+ retry_config=retry_config,
2649
+ )
2650
+
2651
+ response_data: Any = None
2652
+ if utils.match_response(http_res, "200", "application/json"):
2653
+ return unmarshal_json_response(
2654
+ operations.BulkAssignMembersToGuardrailResponse, http_res
2655
+ )
2656
+ if utils.match_response(http_res, "400", "application/json"):
2657
+ response_data = unmarshal_json_response(
2658
+ errors.BadRequestResponseErrorData, http_res
2659
+ )
2660
+ raise errors.BadRequestResponseError(response_data, http_res)
2661
+ if utils.match_response(http_res, "401", "application/json"):
2662
+ response_data = unmarshal_json_response(
2663
+ errors.UnauthorizedResponseErrorData, http_res
2664
+ )
2665
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2666
+ if utils.match_response(http_res, "404", "application/json"):
2667
+ response_data = unmarshal_json_response(
2668
+ errors.NotFoundResponseErrorData, http_res
2669
+ )
2670
+ raise errors.NotFoundResponseError(response_data, http_res)
2671
+ if utils.match_response(http_res, "500", "application/json"):
2672
+ response_data = unmarshal_json_response(
2673
+ errors.InternalServerResponseErrorData, http_res
2674
+ )
2675
+ raise errors.InternalServerResponseError(response_data, http_res)
2676
+ if utils.match_response(http_res, "4XX", "*"):
2677
+ http_res_text = utils.stream_to_text(http_res)
2678
+ raise errors.OpenRouterDefaultError(
2679
+ "API error occurred", http_res, http_res_text
2680
+ )
2681
+ if utils.match_response(http_res, "5XX", "*"):
2682
+ http_res_text = utils.stream_to_text(http_res)
2683
+ raise errors.OpenRouterDefaultError(
2684
+ "API error occurred", http_res, http_res_text
2685
+ )
2686
+
2687
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2688
+
2689
+ async def bulk_assign_members_async(
2690
+ self,
2691
+ *,
2692
+ id: str,
2693
+ member_user_ids: List[str],
2694
+ http_referer: Optional[str] = None,
2695
+ x_title: Optional[str] = None,
2696
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2697
+ server_url: Optional[str] = None,
2698
+ timeout_ms: Optional[int] = None,
2699
+ http_headers: Optional[Mapping[str, str]] = None,
2700
+ ) -> operations.BulkAssignMembersToGuardrailResponse:
2701
+ r"""Bulk assign members to a guardrail
2702
+
2703
+ Assign multiple organization members to a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2704
+
2705
+ :param id: The unique identifier of the guardrail
2706
+ :param member_user_ids: Array of member user IDs to assign to the guardrail
2707
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2708
+ This is used to track API usage per application.
2709
+
2710
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2711
+
2712
+ :param retries: Override the default retry configuration for this method
2713
+ :param server_url: Override the default server URL for this method
2714
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2715
+ :param http_headers: Additional headers to set or replace on requests.
2716
+ """
2717
+ base_url = None
2718
+ url_variables = None
2719
+ if timeout_ms is None:
2720
+ timeout_ms = self.sdk_configuration.timeout_ms
2721
+
2722
+ if server_url is not None:
2723
+ base_url = server_url
2724
+ else:
2725
+ base_url = self._get_url(base_url, url_variables)
2726
+
2727
+ request = operations.BulkAssignMembersToGuardrailRequest(
2728
+ http_referer=http_referer,
2729
+ x_title=x_title,
2730
+ id=id,
2731
+ request_body=operations.BulkAssignMembersToGuardrailRequestBody(
2732
+ member_user_ids=member_user_ids,
2733
+ ),
2734
+ )
2735
+
2736
+ req = self._build_request_async(
2737
+ method="POST",
2738
+ path="/guardrails/{id}/assignments/members",
2739
+ base_url=base_url,
2740
+ url_variables=url_variables,
2741
+ request=request,
2742
+ request_body_required=True,
2743
+ request_has_path_params=True,
2744
+ request_has_query_params=True,
2745
+ user_agent_header="user-agent",
2746
+ accept_header_value="application/json",
2747
+ http_headers=http_headers,
2748
+ _globals=operations.BulkAssignMembersToGuardrailGlobals(
2749
+ http_referer=self.sdk_configuration.globals.http_referer,
2750
+ x_title=self.sdk_configuration.globals.x_title,
2751
+ ),
2752
+ security=self.sdk_configuration.security,
2753
+ get_serialized_body=lambda: utils.serialize_request_body(
2754
+ request.request_body,
2755
+ False,
2756
+ False,
2757
+ "json",
2758
+ operations.BulkAssignMembersToGuardrailRequestBody,
2759
+ ),
2760
+ allow_empty_value=None,
2761
+ timeout_ms=timeout_ms,
2762
+ )
2763
+
2764
+ if retries == UNSET:
2765
+ if self.sdk_configuration.retry_config is not UNSET:
2766
+ retries = self.sdk_configuration.retry_config
2767
+
2768
+ retry_config = None
2769
+ if isinstance(retries, utils.RetryConfig):
2770
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2771
+
2772
+ http_res = await self.do_request_async(
2773
+ hook_ctx=HookContext(
2774
+ config=self.sdk_configuration,
2775
+ base_url=base_url or "",
2776
+ operation_id="bulkAssignMembersToGuardrail",
2777
+ oauth2_scopes=None,
2778
+ security_source=get_security_from_env(
2779
+ self.sdk_configuration.security, components.Security
2780
+ ),
2781
+ ),
2782
+ request=req,
2783
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
2784
+ retry_config=retry_config,
2785
+ )
2786
+
2787
+ response_data: Any = None
2788
+ if utils.match_response(http_res, "200", "application/json"):
2789
+ return unmarshal_json_response(
2790
+ operations.BulkAssignMembersToGuardrailResponse, http_res
2791
+ )
2792
+ if utils.match_response(http_res, "400", "application/json"):
2793
+ response_data = unmarshal_json_response(
2794
+ errors.BadRequestResponseErrorData, http_res
2795
+ )
2796
+ raise errors.BadRequestResponseError(response_data, http_res)
2797
+ if utils.match_response(http_res, "401", "application/json"):
2798
+ response_data = unmarshal_json_response(
2799
+ errors.UnauthorizedResponseErrorData, http_res
2800
+ )
2801
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2802
+ if utils.match_response(http_res, "404", "application/json"):
2803
+ response_data = unmarshal_json_response(
2804
+ errors.NotFoundResponseErrorData, http_res
2805
+ )
2806
+ raise errors.NotFoundResponseError(response_data, http_res)
2807
+ if utils.match_response(http_res, "500", "application/json"):
2808
+ response_data = unmarshal_json_response(
2809
+ errors.InternalServerResponseErrorData, http_res
2810
+ )
2811
+ raise errors.InternalServerResponseError(response_data, http_res)
2812
+ if utils.match_response(http_res, "4XX", "*"):
2813
+ http_res_text = await utils.stream_to_text_async(http_res)
2814
+ raise errors.OpenRouterDefaultError(
2815
+ "API error occurred", http_res, http_res_text
2816
+ )
2817
+ if utils.match_response(http_res, "5XX", "*"):
2818
+ http_res_text = await utils.stream_to_text_async(http_res)
2819
+ raise errors.OpenRouterDefaultError(
2820
+ "API error occurred", http_res, http_res_text
2821
+ )
2822
+
2823
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2824
+
2825
+ def bulk_unassign_keys(
2826
+ self,
2827
+ *,
2828
+ id: str,
2829
+ key_hashes: List[str],
2830
+ http_referer: Optional[str] = None,
2831
+ x_title: Optional[str] = None,
2832
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2833
+ server_url: Optional[str] = None,
2834
+ timeout_ms: Optional[int] = None,
2835
+ http_headers: Optional[Mapping[str, str]] = None,
2836
+ ) -> operations.BulkUnassignKeysFromGuardrailResponse:
2837
+ r"""Bulk unassign keys from a guardrail
2838
+
2839
+ Unassign multiple API keys from a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2840
+
2841
+ :param id: The unique identifier of the guardrail
2842
+ :param key_hashes: Array of API key hashes to unassign from the guardrail
2843
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2844
+ This is used to track API usage per application.
2845
+
2846
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2847
+
2848
+ :param retries: Override the default retry configuration for this method
2849
+ :param server_url: Override the default server URL for this method
2850
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2851
+ :param http_headers: Additional headers to set or replace on requests.
2852
+ """
2853
+ base_url = None
2854
+ url_variables = None
2855
+ if timeout_ms is None:
2856
+ timeout_ms = self.sdk_configuration.timeout_ms
2857
+
2858
+ if server_url is not None:
2859
+ base_url = server_url
2860
+ else:
2861
+ base_url = self._get_url(base_url, url_variables)
2862
+
2863
+ request = operations.BulkUnassignKeysFromGuardrailRequest(
2864
+ http_referer=http_referer,
2865
+ x_title=x_title,
2866
+ id=id,
2867
+ request_body=operations.BulkUnassignKeysFromGuardrailRequestBody(
2868
+ key_hashes=key_hashes,
2869
+ ),
2870
+ )
2871
+
2872
+ req = self._build_request(
2873
+ method="POST",
2874
+ path="/guardrails/{id}/assignments/keys/remove",
2875
+ base_url=base_url,
2876
+ url_variables=url_variables,
2877
+ request=request,
2878
+ request_body_required=True,
2879
+ request_has_path_params=True,
2880
+ request_has_query_params=True,
2881
+ user_agent_header="user-agent",
2882
+ accept_header_value="application/json",
2883
+ http_headers=http_headers,
2884
+ _globals=operations.BulkUnassignKeysFromGuardrailGlobals(
2885
+ http_referer=self.sdk_configuration.globals.http_referer,
2886
+ x_title=self.sdk_configuration.globals.x_title,
2887
+ ),
2888
+ security=self.sdk_configuration.security,
2889
+ get_serialized_body=lambda: utils.serialize_request_body(
2890
+ request.request_body,
2891
+ False,
2892
+ False,
2893
+ "json",
2894
+ operations.BulkUnassignKeysFromGuardrailRequestBody,
2895
+ ),
2896
+ allow_empty_value=None,
2897
+ timeout_ms=timeout_ms,
2898
+ )
2899
+
2900
+ if retries == UNSET:
2901
+ if self.sdk_configuration.retry_config is not UNSET:
2902
+ retries = self.sdk_configuration.retry_config
2903
+
2904
+ retry_config = None
2905
+ if isinstance(retries, utils.RetryConfig):
2906
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2907
+
2908
+ http_res = self.do_request(
2909
+ hook_ctx=HookContext(
2910
+ config=self.sdk_configuration,
2911
+ base_url=base_url or "",
2912
+ operation_id="bulkUnassignKeysFromGuardrail",
2913
+ oauth2_scopes=None,
2914
+ security_source=get_security_from_env(
2915
+ self.sdk_configuration.security, components.Security
2916
+ ),
2917
+ ),
2918
+ request=req,
2919
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
2920
+ retry_config=retry_config,
2921
+ )
2922
+
2923
+ response_data: Any = None
2924
+ if utils.match_response(http_res, "200", "application/json"):
2925
+ return unmarshal_json_response(
2926
+ operations.BulkUnassignKeysFromGuardrailResponse, http_res
2927
+ )
2928
+ if utils.match_response(http_res, "400", "application/json"):
2929
+ response_data = unmarshal_json_response(
2930
+ errors.BadRequestResponseErrorData, http_res
2931
+ )
2932
+ raise errors.BadRequestResponseError(response_data, http_res)
2933
+ if utils.match_response(http_res, "401", "application/json"):
2934
+ response_data = unmarshal_json_response(
2935
+ errors.UnauthorizedResponseErrorData, http_res
2936
+ )
2937
+ raise errors.UnauthorizedResponseError(response_data, http_res)
2938
+ if utils.match_response(http_res, "404", "application/json"):
2939
+ response_data = unmarshal_json_response(
2940
+ errors.NotFoundResponseErrorData, http_res
2941
+ )
2942
+ raise errors.NotFoundResponseError(response_data, http_res)
2943
+ if utils.match_response(http_res, "500", "application/json"):
2944
+ response_data = unmarshal_json_response(
2945
+ errors.InternalServerResponseErrorData, http_res
2946
+ )
2947
+ raise errors.InternalServerResponseError(response_data, http_res)
2948
+ if utils.match_response(http_res, "4XX", "*"):
2949
+ http_res_text = utils.stream_to_text(http_res)
2950
+ raise errors.OpenRouterDefaultError(
2951
+ "API error occurred", http_res, http_res_text
2952
+ )
2953
+ if utils.match_response(http_res, "5XX", "*"):
2954
+ http_res_text = utils.stream_to_text(http_res)
2955
+ raise errors.OpenRouterDefaultError(
2956
+ "API error occurred", http_res, http_res_text
2957
+ )
2958
+
2959
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
2960
+
2961
+ async def bulk_unassign_keys_async(
2962
+ self,
2963
+ *,
2964
+ id: str,
2965
+ key_hashes: List[str],
2966
+ http_referer: Optional[str] = None,
2967
+ x_title: Optional[str] = None,
2968
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2969
+ server_url: Optional[str] = None,
2970
+ timeout_ms: Optional[int] = None,
2971
+ http_headers: Optional[Mapping[str, str]] = None,
2972
+ ) -> operations.BulkUnassignKeysFromGuardrailResponse:
2973
+ r"""Bulk unassign keys from a guardrail
2974
+
2975
+ Unassign multiple API keys from a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
2976
+
2977
+ :param id: The unique identifier of the guardrail
2978
+ :param key_hashes: Array of API key hashes to unassign from the guardrail
2979
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
2980
+ This is used to track API usage per application.
2981
+
2982
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
2983
+
2984
+ :param retries: Override the default retry configuration for this method
2985
+ :param server_url: Override the default server URL for this method
2986
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2987
+ :param http_headers: Additional headers to set or replace on requests.
2988
+ """
2989
+ base_url = None
2990
+ url_variables = None
2991
+ if timeout_ms is None:
2992
+ timeout_ms = self.sdk_configuration.timeout_ms
2993
+
2994
+ if server_url is not None:
2995
+ base_url = server_url
2996
+ else:
2997
+ base_url = self._get_url(base_url, url_variables)
2998
+
2999
+ request = operations.BulkUnassignKeysFromGuardrailRequest(
3000
+ http_referer=http_referer,
3001
+ x_title=x_title,
3002
+ id=id,
3003
+ request_body=operations.BulkUnassignKeysFromGuardrailRequestBody(
3004
+ key_hashes=key_hashes,
3005
+ ),
3006
+ )
3007
+
3008
+ req = self._build_request_async(
3009
+ method="POST",
3010
+ path="/guardrails/{id}/assignments/keys/remove",
3011
+ base_url=base_url,
3012
+ url_variables=url_variables,
3013
+ request=request,
3014
+ request_body_required=True,
3015
+ request_has_path_params=True,
3016
+ request_has_query_params=True,
3017
+ user_agent_header="user-agent",
3018
+ accept_header_value="application/json",
3019
+ http_headers=http_headers,
3020
+ _globals=operations.BulkUnassignKeysFromGuardrailGlobals(
3021
+ http_referer=self.sdk_configuration.globals.http_referer,
3022
+ x_title=self.sdk_configuration.globals.x_title,
3023
+ ),
3024
+ security=self.sdk_configuration.security,
3025
+ get_serialized_body=lambda: utils.serialize_request_body(
3026
+ request.request_body,
3027
+ False,
3028
+ False,
3029
+ "json",
3030
+ operations.BulkUnassignKeysFromGuardrailRequestBody,
3031
+ ),
3032
+ allow_empty_value=None,
3033
+ timeout_ms=timeout_ms,
3034
+ )
3035
+
3036
+ if retries == UNSET:
3037
+ if self.sdk_configuration.retry_config is not UNSET:
3038
+ retries = self.sdk_configuration.retry_config
3039
+
3040
+ retry_config = None
3041
+ if isinstance(retries, utils.RetryConfig):
3042
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
3043
+
3044
+ http_res = await self.do_request_async(
3045
+ hook_ctx=HookContext(
3046
+ config=self.sdk_configuration,
3047
+ base_url=base_url or "",
3048
+ operation_id="bulkUnassignKeysFromGuardrail",
3049
+ oauth2_scopes=None,
3050
+ security_source=get_security_from_env(
3051
+ self.sdk_configuration.security, components.Security
3052
+ ),
3053
+ ),
3054
+ request=req,
3055
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
3056
+ retry_config=retry_config,
3057
+ )
3058
+
3059
+ response_data: Any = None
3060
+ if utils.match_response(http_res, "200", "application/json"):
3061
+ return unmarshal_json_response(
3062
+ operations.BulkUnassignKeysFromGuardrailResponse, http_res
3063
+ )
3064
+ if utils.match_response(http_res, "400", "application/json"):
3065
+ response_data = unmarshal_json_response(
3066
+ errors.BadRequestResponseErrorData, http_res
3067
+ )
3068
+ raise errors.BadRequestResponseError(response_data, http_res)
3069
+ if utils.match_response(http_res, "401", "application/json"):
3070
+ response_data = unmarshal_json_response(
3071
+ errors.UnauthorizedResponseErrorData, http_res
3072
+ )
3073
+ raise errors.UnauthorizedResponseError(response_data, http_res)
3074
+ if utils.match_response(http_res, "404", "application/json"):
3075
+ response_data = unmarshal_json_response(
3076
+ errors.NotFoundResponseErrorData, http_res
3077
+ )
3078
+ raise errors.NotFoundResponseError(response_data, http_res)
3079
+ if utils.match_response(http_res, "500", "application/json"):
3080
+ response_data = unmarshal_json_response(
3081
+ errors.InternalServerResponseErrorData, http_res
3082
+ )
3083
+ raise errors.InternalServerResponseError(response_data, http_res)
3084
+ if utils.match_response(http_res, "4XX", "*"):
3085
+ http_res_text = await utils.stream_to_text_async(http_res)
3086
+ raise errors.OpenRouterDefaultError(
3087
+ "API error occurred", http_res, http_res_text
3088
+ )
3089
+ if utils.match_response(http_res, "5XX", "*"):
3090
+ http_res_text = await utils.stream_to_text_async(http_res)
3091
+ raise errors.OpenRouterDefaultError(
3092
+ "API error occurred", http_res, http_res_text
3093
+ )
3094
+
3095
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
3096
+
3097
+ def bulk_unassign_members(
3098
+ self,
3099
+ *,
3100
+ id: str,
3101
+ member_user_ids: List[str],
3102
+ http_referer: Optional[str] = None,
3103
+ x_title: Optional[str] = None,
3104
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
3105
+ server_url: Optional[str] = None,
3106
+ timeout_ms: Optional[int] = None,
3107
+ http_headers: Optional[Mapping[str, str]] = None,
3108
+ ) -> operations.BulkUnassignMembersFromGuardrailResponse:
3109
+ r"""Bulk unassign members from a guardrail
3110
+
3111
+ Unassign multiple organization members from a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
3112
+
3113
+ :param id: The unique identifier of the guardrail
3114
+ :param member_user_ids: Array of member user IDs to unassign from the guardrail
3115
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
3116
+ This is used to track API usage per application.
3117
+
3118
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
3119
+
3120
+ :param retries: Override the default retry configuration for this method
3121
+ :param server_url: Override the default server URL for this method
3122
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
3123
+ :param http_headers: Additional headers to set or replace on requests.
3124
+ """
3125
+ base_url = None
3126
+ url_variables = None
3127
+ if timeout_ms is None:
3128
+ timeout_ms = self.sdk_configuration.timeout_ms
3129
+
3130
+ if server_url is not None:
3131
+ base_url = server_url
3132
+ else:
3133
+ base_url = self._get_url(base_url, url_variables)
3134
+
3135
+ request = operations.BulkUnassignMembersFromGuardrailRequest(
3136
+ http_referer=http_referer,
3137
+ x_title=x_title,
3138
+ id=id,
3139
+ request_body=operations.BulkUnassignMembersFromGuardrailRequestBody(
3140
+ member_user_ids=member_user_ids,
3141
+ ),
3142
+ )
3143
+
3144
+ req = self._build_request(
3145
+ method="POST",
3146
+ path="/guardrails/{id}/assignments/members/remove",
3147
+ base_url=base_url,
3148
+ url_variables=url_variables,
3149
+ request=request,
3150
+ request_body_required=True,
3151
+ request_has_path_params=True,
3152
+ request_has_query_params=True,
3153
+ user_agent_header="user-agent",
3154
+ accept_header_value="application/json",
3155
+ http_headers=http_headers,
3156
+ _globals=operations.BulkUnassignMembersFromGuardrailGlobals(
3157
+ http_referer=self.sdk_configuration.globals.http_referer,
3158
+ x_title=self.sdk_configuration.globals.x_title,
3159
+ ),
3160
+ security=self.sdk_configuration.security,
3161
+ get_serialized_body=lambda: utils.serialize_request_body(
3162
+ request.request_body,
3163
+ False,
3164
+ False,
3165
+ "json",
3166
+ operations.BulkUnassignMembersFromGuardrailRequestBody,
3167
+ ),
3168
+ allow_empty_value=None,
3169
+ timeout_ms=timeout_ms,
3170
+ )
3171
+
3172
+ if retries == UNSET:
3173
+ if self.sdk_configuration.retry_config is not UNSET:
3174
+ retries = self.sdk_configuration.retry_config
3175
+
3176
+ retry_config = None
3177
+ if isinstance(retries, utils.RetryConfig):
3178
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
3179
+
3180
+ http_res = self.do_request(
3181
+ hook_ctx=HookContext(
3182
+ config=self.sdk_configuration,
3183
+ base_url=base_url or "",
3184
+ operation_id="bulkUnassignMembersFromGuardrail",
3185
+ oauth2_scopes=None,
3186
+ security_source=get_security_from_env(
3187
+ self.sdk_configuration.security, components.Security
3188
+ ),
3189
+ ),
3190
+ request=req,
3191
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
3192
+ retry_config=retry_config,
3193
+ )
3194
+
3195
+ response_data: Any = None
3196
+ if utils.match_response(http_res, "200", "application/json"):
3197
+ return unmarshal_json_response(
3198
+ operations.BulkUnassignMembersFromGuardrailResponse, http_res
3199
+ )
3200
+ if utils.match_response(http_res, "400", "application/json"):
3201
+ response_data = unmarshal_json_response(
3202
+ errors.BadRequestResponseErrorData, http_res
3203
+ )
3204
+ raise errors.BadRequestResponseError(response_data, http_res)
3205
+ if utils.match_response(http_res, "401", "application/json"):
3206
+ response_data = unmarshal_json_response(
3207
+ errors.UnauthorizedResponseErrorData, http_res
3208
+ )
3209
+ raise errors.UnauthorizedResponseError(response_data, http_res)
3210
+ if utils.match_response(http_res, "404", "application/json"):
3211
+ response_data = unmarshal_json_response(
3212
+ errors.NotFoundResponseErrorData, http_res
3213
+ )
3214
+ raise errors.NotFoundResponseError(response_data, http_res)
3215
+ if utils.match_response(http_res, "500", "application/json"):
3216
+ response_data = unmarshal_json_response(
3217
+ errors.InternalServerResponseErrorData, http_res
3218
+ )
3219
+ raise errors.InternalServerResponseError(response_data, http_res)
3220
+ if utils.match_response(http_res, "4XX", "*"):
3221
+ http_res_text = utils.stream_to_text(http_res)
3222
+ raise errors.OpenRouterDefaultError(
3223
+ "API error occurred", http_res, http_res_text
3224
+ )
3225
+ if utils.match_response(http_res, "5XX", "*"):
3226
+ http_res_text = utils.stream_to_text(http_res)
3227
+ raise errors.OpenRouterDefaultError(
3228
+ "API error occurred", http_res, http_res_text
3229
+ )
3230
+
3231
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
3232
+
3233
+ async def bulk_unassign_members_async(
3234
+ self,
3235
+ *,
3236
+ id: str,
3237
+ member_user_ids: List[str],
3238
+ http_referer: Optional[str] = None,
3239
+ x_title: Optional[str] = None,
3240
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
3241
+ server_url: Optional[str] = None,
3242
+ timeout_ms: Optional[int] = None,
3243
+ http_headers: Optional[Mapping[str, str]] = None,
3244
+ ) -> operations.BulkUnassignMembersFromGuardrailResponse:
3245
+ r"""Bulk unassign members from a guardrail
3246
+
3247
+ Unassign multiple organization members from a specific guardrail. [Management key](/docs/guides/overview/auth/management-api-keys) required.
3248
+
3249
+ :param id: The unique identifier of the guardrail
3250
+ :param member_user_ids: Array of member user IDs to unassign from the guardrail
3251
+ :param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
3252
+ This is used to track API usage per application.
3253
+
3254
+ :param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
3255
+
3256
+ :param retries: Override the default retry configuration for this method
3257
+ :param server_url: Override the default server URL for this method
3258
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
3259
+ :param http_headers: Additional headers to set or replace on requests.
3260
+ """
3261
+ base_url = None
3262
+ url_variables = None
3263
+ if timeout_ms is None:
3264
+ timeout_ms = self.sdk_configuration.timeout_ms
3265
+
3266
+ if server_url is not None:
3267
+ base_url = server_url
3268
+ else:
3269
+ base_url = self._get_url(base_url, url_variables)
3270
+
3271
+ request = operations.BulkUnassignMembersFromGuardrailRequest(
3272
+ http_referer=http_referer,
3273
+ x_title=x_title,
3274
+ id=id,
3275
+ request_body=operations.BulkUnassignMembersFromGuardrailRequestBody(
3276
+ member_user_ids=member_user_ids,
3277
+ ),
3278
+ )
3279
+
3280
+ req = self._build_request_async(
3281
+ method="POST",
3282
+ path="/guardrails/{id}/assignments/members/remove",
3283
+ base_url=base_url,
3284
+ url_variables=url_variables,
3285
+ request=request,
3286
+ request_body_required=True,
3287
+ request_has_path_params=True,
3288
+ request_has_query_params=True,
3289
+ user_agent_header="user-agent",
3290
+ accept_header_value="application/json",
3291
+ http_headers=http_headers,
3292
+ _globals=operations.BulkUnassignMembersFromGuardrailGlobals(
3293
+ http_referer=self.sdk_configuration.globals.http_referer,
3294
+ x_title=self.sdk_configuration.globals.x_title,
3295
+ ),
3296
+ security=self.sdk_configuration.security,
3297
+ get_serialized_body=lambda: utils.serialize_request_body(
3298
+ request.request_body,
3299
+ False,
3300
+ False,
3301
+ "json",
3302
+ operations.BulkUnassignMembersFromGuardrailRequestBody,
3303
+ ),
3304
+ allow_empty_value=None,
3305
+ timeout_ms=timeout_ms,
3306
+ )
3307
+
3308
+ if retries == UNSET:
3309
+ if self.sdk_configuration.retry_config is not UNSET:
3310
+ retries = self.sdk_configuration.retry_config
3311
+
3312
+ retry_config = None
3313
+ if isinstance(retries, utils.RetryConfig):
3314
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
3315
+
3316
+ http_res = await self.do_request_async(
3317
+ hook_ctx=HookContext(
3318
+ config=self.sdk_configuration,
3319
+ base_url=base_url or "",
3320
+ operation_id="bulkUnassignMembersFromGuardrail",
3321
+ oauth2_scopes=None,
3322
+ security_source=get_security_from_env(
3323
+ self.sdk_configuration.security, components.Security
3324
+ ),
3325
+ ),
3326
+ request=req,
3327
+ error_status_codes=["400", "401", "404", "4XX", "500", "5XX"],
3328
+ retry_config=retry_config,
3329
+ )
3330
+
3331
+ response_data: Any = None
3332
+ if utils.match_response(http_res, "200", "application/json"):
3333
+ return unmarshal_json_response(
3334
+ operations.BulkUnassignMembersFromGuardrailResponse, http_res
3335
+ )
3336
+ if utils.match_response(http_res, "400", "application/json"):
3337
+ response_data = unmarshal_json_response(
3338
+ errors.BadRequestResponseErrorData, http_res
3339
+ )
3340
+ raise errors.BadRequestResponseError(response_data, http_res)
3341
+ if utils.match_response(http_res, "401", "application/json"):
3342
+ response_data = unmarshal_json_response(
3343
+ errors.UnauthorizedResponseErrorData, http_res
3344
+ )
3345
+ raise errors.UnauthorizedResponseError(response_data, http_res)
3346
+ if utils.match_response(http_res, "404", "application/json"):
3347
+ response_data = unmarshal_json_response(
3348
+ errors.NotFoundResponseErrorData, http_res
3349
+ )
3350
+ raise errors.NotFoundResponseError(response_data, http_res)
3351
+ if utils.match_response(http_res, "500", "application/json"):
3352
+ response_data = unmarshal_json_response(
3353
+ errors.InternalServerResponseErrorData, http_res
3354
+ )
3355
+ raise errors.InternalServerResponseError(response_data, http_res)
3356
+ if utils.match_response(http_res, "4XX", "*"):
3357
+ http_res_text = await utils.stream_to_text_async(http_res)
3358
+ raise errors.OpenRouterDefaultError(
3359
+ "API error occurred", http_res, http_res_text
3360
+ )
3361
+ if utils.match_response(http_res, "5XX", "*"):
3362
+ http_res_text = await utils.stream_to_text_async(http_res)
3363
+ raise errors.OpenRouterDefaultError(
3364
+ "API error occurred", http_res, http_res_text
3365
+ )
3366
+
3367
+ raise errors.OpenRouterDefaultError("Unexpected response received", http_res)