openrouter 0.1.2__py3-none-any.whl → 0.6.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openrouter/_version.py +2 -2
- openrouter/analytics.py +28 -2
- openrouter/api_keys.py +210 -14
- openrouter/chat.py +192 -200
- openrouter/components/__init__.py +229 -285
- openrouter/components/_schema10.py +39 -0
- openrouter/components/_schema14.py +11 -0
- openrouter/components/_schema17.py +154 -0
- openrouter/components/{_schema3.py → _schema19.py} +28 -22
- openrouter/components/{_schema0.py → _schema5.py} +7 -5
- openrouter/components/assistantmessage.py +32 -1
- openrouter/components/chatgenerationparams.py +57 -343
- openrouter/components/chatmessagecontentitemimage.py +4 -4
- openrouter/components/chatresponsechoice.py +1 -6
- openrouter/components/chatstreamingmessagechunk.py +3 -3
- openrouter/components/developermessage.py +41 -0
- openrouter/components/message.py +6 -39
- openrouter/components/model.py +7 -1
- openrouter/components/openresponsesrequest.py +31 -39
- openrouter/components/outputmodality.py +1 -0
- openrouter/components/providername.py +2 -0
- openrouter/components/providerpreferences.py +2 -10
- openrouter/components/publicendpoint.py +8 -24
- openrouter/components/publicpricing.py +3 -24
- openrouter/credits.py +86 -14
- openrouter/embeddings.py +92 -20
- openrouter/endpoints.py +62 -2
- openrouter/generations.py +26 -0
- openrouter/guardrails.py +3367 -0
- openrouter/models_.py +120 -12
- openrouter/oauth.py +90 -22
- openrouter/operations/__init__.py +601 -30
- openrouter/operations/bulkassignkeystoguardrail.py +116 -0
- openrouter/operations/bulkassignmemberstoguardrail.py +116 -0
- openrouter/operations/bulkunassignkeysfromguardrail.py +116 -0
- openrouter/operations/bulkunassignmembersfromguardrail.py +116 -0
- openrouter/operations/createauthkeyscode.py +81 -3
- openrouter/operations/createcoinbasecharge.py +82 -2
- openrouter/operations/createembeddings.py +82 -3
- openrouter/operations/createguardrail.py +325 -0
- openrouter/operations/createkeys.py +81 -3
- openrouter/operations/createresponses.py +84 -3
- openrouter/operations/deleteguardrail.py +104 -0
- openrouter/operations/deletekeys.py +69 -3
- openrouter/operations/exchangeauthcodeforapikey.py +81 -3
- openrouter/operations/getcredits.py +70 -1
- openrouter/operations/getcurrentkey.py +81 -3
- openrouter/operations/getgeneration.py +248 -3
- openrouter/operations/getguardrail.py +228 -0
- openrouter/operations/getkey.py +64 -1
- openrouter/operations/getmodels.py +95 -5
- openrouter/operations/getuseractivity.py +62 -1
- openrouter/operations/list.py +63 -1
- openrouter/operations/listembeddingsmodels.py +74 -0
- openrouter/operations/listendpoints.py +65 -2
- openrouter/operations/listendpointszdr.py +70 -2
- openrouter/operations/listguardrailkeyassignments.py +192 -0
- openrouter/operations/listguardrailmemberassignments.py +187 -0
- openrouter/operations/listguardrails.py +238 -0
- openrouter/operations/listkeyassignments.py +180 -0
- openrouter/operations/listmemberassignments.py +175 -0
- openrouter/operations/listmodelscount.py +74 -0
- openrouter/operations/listmodelsuser.py +70 -2
- openrouter/operations/listproviders.py +70 -2
- openrouter/operations/sendchatcompletionrequest.py +87 -3
- openrouter/operations/updateguardrail.py +334 -0
- openrouter/operations/updatekeys.py +63 -0
- openrouter/providers.py +36 -2
- openrouter/responses.py +178 -148
- openrouter/sdk.py +5 -8
- openrouter/types/models.py +378 -0
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/METADATA +5 -1
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/RECORD +76 -63
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/WHEEL +1 -1
- openrouter/completions.py +0 -361
- openrouter/components/completionchoice.py +0 -82
- openrouter/components/completioncreateparams.py +0 -277
- openrouter/components/completionlogprobs.py +0 -54
- openrouter/components/completionresponse.py +0 -46
- openrouter/components/completionusage.py +0 -19
- openrouter/operations/getparameters.py +0 -123
- openrouter/parameters.py +0 -237
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/licenses/LICENSE +0 -0
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/top_level.txt +0 -0
openrouter/responses.py
CHANGED
|
@@ -22,6 +22,8 @@ class Responses(BaseSDK):
|
|
|
22
22
|
def send(
|
|
23
23
|
self,
|
|
24
24
|
*,
|
|
25
|
+
http_referer: Optional[str] = None,
|
|
26
|
+
x_title: Optional[str] = None,
|
|
25
27
|
input: Optional[
|
|
26
28
|
Union[components.OpenResponsesInput, components.OpenResponsesInputTypedDict]
|
|
27
29
|
] = None,
|
|
@@ -84,16 +86,10 @@ class Responses(BaseSDK):
|
|
|
84
86
|
truncation: OptionalNullable[components.Truncation] = UNSET,
|
|
85
87
|
stream: Union[Literal[False], None] = None,
|
|
86
88
|
provider: OptionalNullable[
|
|
87
|
-
Union[
|
|
88
|
-
components.OpenResponsesRequestProvider,
|
|
89
|
-
components.OpenResponsesRequestProviderTypedDict,
|
|
90
|
-
]
|
|
89
|
+
Union[components.Provider, components.ProviderTypedDict]
|
|
91
90
|
] = UNSET,
|
|
92
91
|
plugins: Optional[
|
|
93
|
-
Union[
|
|
94
|
-
List[components.OpenResponsesRequestPluginUnion],
|
|
95
|
-
List[components.OpenResponsesRequestPluginUnionTypedDict],
|
|
96
|
-
]
|
|
92
|
+
Union[List[components.Plugin], List[components.PluginTypedDict]]
|
|
97
93
|
] = None,
|
|
98
94
|
user: Optional[str] = None,
|
|
99
95
|
session_id: Optional[str] = None,
|
|
@@ -106,6 +102,11 @@ class Responses(BaseSDK):
|
|
|
106
102
|
|
|
107
103
|
Creates a streaming or non-streaming response using OpenResponses API format
|
|
108
104
|
|
|
105
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
106
|
+
This is used to track API usage per application.
|
|
107
|
+
|
|
108
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
109
|
+
|
|
109
110
|
:param input: Input for a response request - can be a string or array of items
|
|
110
111
|
:param instructions:
|
|
111
112
|
:param metadata: Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.
|
|
@@ -150,6 +151,8 @@ class Responses(BaseSDK):
|
|
|
150
151
|
def send(
|
|
151
152
|
self,
|
|
152
153
|
*,
|
|
154
|
+
http_referer: Optional[str] = None,
|
|
155
|
+
x_title: Optional[str] = None,
|
|
153
156
|
input: Optional[
|
|
154
157
|
Union[components.OpenResponsesInput, components.OpenResponsesInputTypedDict]
|
|
155
158
|
] = None,
|
|
@@ -212,16 +215,10 @@ class Responses(BaseSDK):
|
|
|
212
215
|
truncation: OptionalNullable[components.Truncation] = UNSET,
|
|
213
216
|
stream: Literal[True],
|
|
214
217
|
provider: OptionalNullable[
|
|
215
|
-
Union[
|
|
216
|
-
components.OpenResponsesRequestProvider,
|
|
217
|
-
components.OpenResponsesRequestProviderTypedDict,
|
|
218
|
-
]
|
|
218
|
+
Union[components.Provider, components.ProviderTypedDict]
|
|
219
219
|
] = UNSET,
|
|
220
220
|
plugins: Optional[
|
|
221
|
-
Union[
|
|
222
|
-
List[components.OpenResponsesRequestPluginUnion],
|
|
223
|
-
List[components.OpenResponsesRequestPluginUnionTypedDict],
|
|
224
|
-
]
|
|
221
|
+
Union[List[components.Plugin], List[components.PluginTypedDict]]
|
|
225
222
|
] = None,
|
|
226
223
|
user: Optional[str] = None,
|
|
227
224
|
session_id: Optional[str] = None,
|
|
@@ -234,6 +231,11 @@ class Responses(BaseSDK):
|
|
|
234
231
|
|
|
235
232
|
Creates a streaming or non-streaming response using OpenResponses API format
|
|
236
233
|
|
|
234
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
235
|
+
This is used to track API usage per application.
|
|
236
|
+
|
|
237
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
238
|
+
|
|
237
239
|
:param input: Input for a response request - can be a string or array of items
|
|
238
240
|
:param instructions:
|
|
239
241
|
:param metadata: Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.
|
|
@@ -277,6 +279,8 @@ class Responses(BaseSDK):
|
|
|
277
279
|
def send(
|
|
278
280
|
self,
|
|
279
281
|
*,
|
|
282
|
+
http_referer: Optional[str] = None,
|
|
283
|
+
x_title: Optional[str] = None,
|
|
280
284
|
input: Optional[
|
|
281
285
|
Union[components.OpenResponsesInput, components.OpenResponsesInputTypedDict]
|
|
282
286
|
] = None,
|
|
@@ -339,16 +343,10 @@ class Responses(BaseSDK):
|
|
|
339
343
|
truncation: OptionalNullable[components.Truncation] = UNSET,
|
|
340
344
|
stream: Optional[bool] = False,
|
|
341
345
|
provider: OptionalNullable[
|
|
342
|
-
Union[
|
|
343
|
-
components.OpenResponsesRequestProvider,
|
|
344
|
-
components.OpenResponsesRequestProviderTypedDict,
|
|
345
|
-
]
|
|
346
|
+
Union[components.Provider, components.ProviderTypedDict]
|
|
346
347
|
] = UNSET,
|
|
347
348
|
plugins: Optional[
|
|
348
|
-
Union[
|
|
349
|
-
List[components.OpenResponsesRequestPluginUnion],
|
|
350
|
-
List[components.OpenResponsesRequestPluginUnionTypedDict],
|
|
351
|
-
]
|
|
349
|
+
Union[List[components.Plugin], List[components.PluginTypedDict]]
|
|
352
350
|
] = None,
|
|
353
351
|
user: Optional[str] = None,
|
|
354
352
|
session_id: Optional[str] = None,
|
|
@@ -361,6 +359,11 @@ class Responses(BaseSDK):
|
|
|
361
359
|
|
|
362
360
|
Creates a streaming or non-streaming response using OpenResponses API format
|
|
363
361
|
|
|
362
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
363
|
+
This is used to track API usage per application.
|
|
364
|
+
|
|
365
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
366
|
+
|
|
364
367
|
:param input: Input for a response request - can be a string or array of items
|
|
365
368
|
:param instructions:
|
|
366
369
|
:param metadata: Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.
|
|
@@ -410,56 +413,60 @@ class Responses(BaseSDK):
|
|
|
410
413
|
else:
|
|
411
414
|
base_url = self._get_url(base_url, url_variables)
|
|
412
415
|
|
|
413
|
-
request =
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
416
|
+
request = operations.CreateResponsesRequest(
|
|
417
|
+
http_referer=http_referer,
|
|
418
|
+
x_title=x_title,
|
|
419
|
+
open_responses_request=components.OpenResponsesRequest(
|
|
420
|
+
input=utils.get_pydantic_model(
|
|
421
|
+
input, Optional[components.OpenResponsesInput]
|
|
422
|
+
),
|
|
423
|
+
instructions=instructions,
|
|
424
|
+
metadata=metadata,
|
|
425
|
+
tools=utils.get_pydantic_model(
|
|
426
|
+
tools, Optional[List[components.OpenResponsesRequestToolUnion]]
|
|
427
|
+
),
|
|
428
|
+
tool_choice=utils.get_pydantic_model(
|
|
429
|
+
tool_choice, Optional[components.OpenAIResponsesToolChoiceUnion]
|
|
430
|
+
),
|
|
431
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
432
|
+
model=model,
|
|
433
|
+
models=models,
|
|
434
|
+
text=utils.get_pydantic_model(
|
|
435
|
+
text, Optional[components.OpenResponsesResponseText]
|
|
436
|
+
),
|
|
437
|
+
reasoning=utils.get_pydantic_model(
|
|
438
|
+
reasoning, OptionalNullable[components.OpenResponsesReasoningConfig]
|
|
439
|
+
),
|
|
440
|
+
max_output_tokens=max_output_tokens,
|
|
441
|
+
temperature=temperature,
|
|
442
|
+
top_p=top_p,
|
|
443
|
+
top_logprobs=top_logprobs,
|
|
444
|
+
max_tool_calls=max_tool_calls,
|
|
445
|
+
presence_penalty=presence_penalty,
|
|
446
|
+
frequency_penalty=frequency_penalty,
|
|
447
|
+
top_k=top_k,
|
|
448
|
+
image_config=image_config,
|
|
449
|
+
modalities=modalities,
|
|
450
|
+
prompt_cache_key=prompt_cache_key,
|
|
451
|
+
previous_response_id=previous_response_id,
|
|
452
|
+
prompt=utils.get_pydantic_model(
|
|
453
|
+
prompt, OptionalNullable[components.OpenAIResponsesPrompt]
|
|
454
|
+
),
|
|
455
|
+
include=include,
|
|
456
|
+
background=background,
|
|
457
|
+
safety_identifier=safety_identifier,
|
|
458
|
+
service_tier=service_tier,
|
|
459
|
+
truncation=truncation,
|
|
460
|
+
stream=stream,
|
|
461
|
+
provider=utils.get_pydantic_model(
|
|
462
|
+
provider, OptionalNullable[components.Provider]
|
|
463
|
+
),
|
|
464
|
+
plugins=utils.get_pydantic_model(
|
|
465
|
+
plugins, Optional[List[components.Plugin]]
|
|
466
|
+
),
|
|
467
|
+
user=user,
|
|
468
|
+
session_id=session_id,
|
|
460
469
|
),
|
|
461
|
-
user=user,
|
|
462
|
-
session_id=session_id,
|
|
463
470
|
)
|
|
464
471
|
|
|
465
472
|
req = self._build_request(
|
|
@@ -474,9 +481,17 @@ class Responses(BaseSDK):
|
|
|
474
481
|
user_agent_header="user-agent",
|
|
475
482
|
accept_header_value="text/event-stream" if stream else "application/json",
|
|
476
483
|
http_headers=http_headers,
|
|
484
|
+
_globals=operations.CreateResponsesGlobals(
|
|
485
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
486
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
487
|
+
),
|
|
477
488
|
security=self.sdk_configuration.security,
|
|
478
489
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
479
|
-
request,
|
|
490
|
+
request.open_responses_request,
|
|
491
|
+
False,
|
|
492
|
+
False,
|
|
493
|
+
"json",
|
|
494
|
+
components.OpenResponsesRequest,
|
|
480
495
|
),
|
|
481
496
|
allow_empty_value=None,
|
|
482
497
|
timeout_ms=timeout_ms,
|
|
@@ -655,6 +670,8 @@ class Responses(BaseSDK):
|
|
|
655
670
|
async def send_async(
|
|
656
671
|
self,
|
|
657
672
|
*,
|
|
673
|
+
http_referer: Optional[str] = None,
|
|
674
|
+
x_title: Optional[str] = None,
|
|
658
675
|
input: Optional[
|
|
659
676
|
Union[components.OpenResponsesInput, components.OpenResponsesInputTypedDict]
|
|
660
677
|
] = None,
|
|
@@ -717,16 +734,10 @@ class Responses(BaseSDK):
|
|
|
717
734
|
truncation: OptionalNullable[components.Truncation] = UNSET,
|
|
718
735
|
stream: Union[Literal[False], None] = None,
|
|
719
736
|
provider: OptionalNullable[
|
|
720
|
-
Union[
|
|
721
|
-
components.OpenResponsesRequestProvider,
|
|
722
|
-
components.OpenResponsesRequestProviderTypedDict,
|
|
723
|
-
]
|
|
737
|
+
Union[components.Provider, components.ProviderTypedDict]
|
|
724
738
|
] = UNSET,
|
|
725
739
|
plugins: Optional[
|
|
726
|
-
Union[
|
|
727
|
-
List[components.OpenResponsesRequestPluginUnion],
|
|
728
|
-
List[components.OpenResponsesRequestPluginUnionTypedDict],
|
|
729
|
-
]
|
|
740
|
+
Union[List[components.Plugin], List[components.PluginTypedDict]]
|
|
730
741
|
] = None,
|
|
731
742
|
user: Optional[str] = None,
|
|
732
743
|
session_id: Optional[str] = None,
|
|
@@ -739,6 +750,11 @@ class Responses(BaseSDK):
|
|
|
739
750
|
|
|
740
751
|
Creates a streaming or non-streaming response using OpenResponses API format
|
|
741
752
|
|
|
753
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
754
|
+
This is used to track API usage per application.
|
|
755
|
+
|
|
756
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
757
|
+
|
|
742
758
|
:param input: Input for a response request - can be a string or array of items
|
|
743
759
|
:param instructions:
|
|
744
760
|
:param metadata: Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.
|
|
@@ -783,6 +799,8 @@ class Responses(BaseSDK):
|
|
|
783
799
|
async def send_async(
|
|
784
800
|
self,
|
|
785
801
|
*,
|
|
802
|
+
http_referer: Optional[str] = None,
|
|
803
|
+
x_title: Optional[str] = None,
|
|
786
804
|
input: Optional[
|
|
787
805
|
Union[components.OpenResponsesInput, components.OpenResponsesInputTypedDict]
|
|
788
806
|
] = None,
|
|
@@ -845,16 +863,10 @@ class Responses(BaseSDK):
|
|
|
845
863
|
truncation: OptionalNullable[components.Truncation] = UNSET,
|
|
846
864
|
stream: Literal[True],
|
|
847
865
|
provider: OptionalNullable[
|
|
848
|
-
Union[
|
|
849
|
-
components.OpenResponsesRequestProvider,
|
|
850
|
-
components.OpenResponsesRequestProviderTypedDict,
|
|
851
|
-
]
|
|
866
|
+
Union[components.Provider, components.ProviderTypedDict]
|
|
852
867
|
] = UNSET,
|
|
853
868
|
plugins: Optional[
|
|
854
|
-
Union[
|
|
855
|
-
List[components.OpenResponsesRequestPluginUnion],
|
|
856
|
-
List[components.OpenResponsesRequestPluginUnionTypedDict],
|
|
857
|
-
]
|
|
869
|
+
Union[List[components.Plugin], List[components.PluginTypedDict]]
|
|
858
870
|
] = None,
|
|
859
871
|
user: Optional[str] = None,
|
|
860
872
|
session_id: Optional[str] = None,
|
|
@@ -867,6 +879,11 @@ class Responses(BaseSDK):
|
|
|
867
879
|
|
|
868
880
|
Creates a streaming or non-streaming response using OpenResponses API format
|
|
869
881
|
|
|
882
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
883
|
+
This is used to track API usage per application.
|
|
884
|
+
|
|
885
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
886
|
+
|
|
870
887
|
:param input: Input for a response request - can be a string or array of items
|
|
871
888
|
:param instructions:
|
|
872
889
|
:param metadata: Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.
|
|
@@ -910,6 +927,8 @@ class Responses(BaseSDK):
|
|
|
910
927
|
async def send_async(
|
|
911
928
|
self,
|
|
912
929
|
*,
|
|
930
|
+
http_referer: Optional[str] = None,
|
|
931
|
+
x_title: Optional[str] = None,
|
|
913
932
|
input: Optional[
|
|
914
933
|
Union[components.OpenResponsesInput, components.OpenResponsesInputTypedDict]
|
|
915
934
|
] = None,
|
|
@@ -972,16 +991,10 @@ class Responses(BaseSDK):
|
|
|
972
991
|
truncation: OptionalNullable[components.Truncation] = UNSET,
|
|
973
992
|
stream: Optional[bool] = False,
|
|
974
993
|
provider: OptionalNullable[
|
|
975
|
-
Union[
|
|
976
|
-
components.OpenResponsesRequestProvider,
|
|
977
|
-
components.OpenResponsesRequestProviderTypedDict,
|
|
978
|
-
]
|
|
994
|
+
Union[components.Provider, components.ProviderTypedDict]
|
|
979
995
|
] = UNSET,
|
|
980
996
|
plugins: Optional[
|
|
981
|
-
Union[
|
|
982
|
-
List[components.OpenResponsesRequestPluginUnion],
|
|
983
|
-
List[components.OpenResponsesRequestPluginUnionTypedDict],
|
|
984
|
-
]
|
|
997
|
+
Union[List[components.Plugin], List[components.PluginTypedDict]]
|
|
985
998
|
] = None,
|
|
986
999
|
user: Optional[str] = None,
|
|
987
1000
|
session_id: Optional[str] = None,
|
|
@@ -994,6 +1007,11 @@ class Responses(BaseSDK):
|
|
|
994
1007
|
|
|
995
1008
|
Creates a streaming or non-streaming response using OpenResponses API format
|
|
996
1009
|
|
|
1010
|
+
:param http_referer: The app identifier should be your app's URL and is used as the primary identifier for rankings.
|
|
1011
|
+
This is used to track API usage per application.
|
|
1012
|
+
|
|
1013
|
+
:param x_title: The app display name allows you to customize how your app appears in OpenRouter's dashboard.
|
|
1014
|
+
|
|
997
1015
|
:param input: Input for a response request - can be a string or array of items
|
|
998
1016
|
:param instructions:
|
|
999
1017
|
:param metadata: Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.
|
|
@@ -1043,56 +1061,60 @@ class Responses(BaseSDK):
|
|
|
1043
1061
|
else:
|
|
1044
1062
|
base_url = self._get_url(base_url, url_variables)
|
|
1045
1063
|
|
|
1046
|
-
request =
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1064
|
+
request = operations.CreateResponsesRequest(
|
|
1065
|
+
http_referer=http_referer,
|
|
1066
|
+
x_title=x_title,
|
|
1067
|
+
open_responses_request=components.OpenResponsesRequest(
|
|
1068
|
+
input=utils.get_pydantic_model(
|
|
1069
|
+
input, Optional[components.OpenResponsesInput]
|
|
1070
|
+
),
|
|
1071
|
+
instructions=instructions,
|
|
1072
|
+
metadata=metadata,
|
|
1073
|
+
tools=utils.get_pydantic_model(
|
|
1074
|
+
tools, Optional[List[components.OpenResponsesRequestToolUnion]]
|
|
1075
|
+
),
|
|
1076
|
+
tool_choice=utils.get_pydantic_model(
|
|
1077
|
+
tool_choice, Optional[components.OpenAIResponsesToolChoiceUnion]
|
|
1078
|
+
),
|
|
1079
|
+
parallel_tool_calls=parallel_tool_calls,
|
|
1080
|
+
model=model,
|
|
1081
|
+
models=models,
|
|
1082
|
+
text=utils.get_pydantic_model(
|
|
1083
|
+
text, Optional[components.OpenResponsesResponseText]
|
|
1084
|
+
),
|
|
1085
|
+
reasoning=utils.get_pydantic_model(
|
|
1086
|
+
reasoning, OptionalNullable[components.OpenResponsesReasoningConfig]
|
|
1087
|
+
),
|
|
1088
|
+
max_output_tokens=max_output_tokens,
|
|
1089
|
+
temperature=temperature,
|
|
1090
|
+
top_p=top_p,
|
|
1091
|
+
top_logprobs=top_logprobs,
|
|
1092
|
+
max_tool_calls=max_tool_calls,
|
|
1093
|
+
presence_penalty=presence_penalty,
|
|
1094
|
+
frequency_penalty=frequency_penalty,
|
|
1095
|
+
top_k=top_k,
|
|
1096
|
+
image_config=image_config,
|
|
1097
|
+
modalities=modalities,
|
|
1098
|
+
prompt_cache_key=prompt_cache_key,
|
|
1099
|
+
previous_response_id=previous_response_id,
|
|
1100
|
+
prompt=utils.get_pydantic_model(
|
|
1101
|
+
prompt, OptionalNullable[components.OpenAIResponsesPrompt]
|
|
1102
|
+
),
|
|
1103
|
+
include=include,
|
|
1104
|
+
background=background,
|
|
1105
|
+
safety_identifier=safety_identifier,
|
|
1106
|
+
service_tier=service_tier,
|
|
1107
|
+
truncation=truncation,
|
|
1108
|
+
stream=stream,
|
|
1109
|
+
provider=utils.get_pydantic_model(
|
|
1110
|
+
provider, OptionalNullable[components.Provider]
|
|
1111
|
+
),
|
|
1112
|
+
plugins=utils.get_pydantic_model(
|
|
1113
|
+
plugins, Optional[List[components.Plugin]]
|
|
1114
|
+
),
|
|
1115
|
+
user=user,
|
|
1116
|
+
session_id=session_id,
|
|
1093
1117
|
),
|
|
1094
|
-
user=user,
|
|
1095
|
-
session_id=session_id,
|
|
1096
1118
|
)
|
|
1097
1119
|
|
|
1098
1120
|
req = self._build_request_async(
|
|
@@ -1107,9 +1129,17 @@ class Responses(BaseSDK):
|
|
|
1107
1129
|
user_agent_header="user-agent",
|
|
1108
1130
|
accept_header_value="text/event-stream" if stream else "application/json",
|
|
1109
1131
|
http_headers=http_headers,
|
|
1132
|
+
_globals=operations.CreateResponsesGlobals(
|
|
1133
|
+
http_referer=self.sdk_configuration.globals.http_referer,
|
|
1134
|
+
x_title=self.sdk_configuration.globals.x_title,
|
|
1135
|
+
),
|
|
1110
1136
|
security=self.sdk_configuration.security,
|
|
1111
1137
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
1112
|
-
request,
|
|
1138
|
+
request.open_responses_request,
|
|
1139
|
+
False,
|
|
1140
|
+
False,
|
|
1141
|
+
"json",
|
|
1142
|
+
components.OpenResponsesRequest,
|
|
1113
1143
|
),
|
|
1114
1144
|
allow_empty_value=None,
|
|
1115
1145
|
timeout_ms=timeout_ms,
|
openrouter/sdk.py
CHANGED
|
@@ -20,19 +20,18 @@ if TYPE_CHECKING:
|
|
|
20
20
|
from openrouter.api_keys import APIKeys
|
|
21
21
|
from openrouter.beta import Beta
|
|
22
22
|
from openrouter.chat import Chat
|
|
23
|
-
from openrouter.completions import Completions
|
|
24
23
|
from openrouter.credits import Credits
|
|
25
24
|
from openrouter.embeddings import Embeddings
|
|
26
25
|
from openrouter.endpoints import Endpoints
|
|
27
26
|
from openrouter.generations import Generations
|
|
27
|
+
from openrouter.guardrails import Guardrails
|
|
28
28
|
from openrouter.models_ import Models
|
|
29
29
|
from openrouter.oauth import OAuth
|
|
30
|
-
from openrouter.parameters import Parameters
|
|
31
30
|
from openrouter.providers import Providers
|
|
32
31
|
|
|
33
32
|
|
|
34
33
|
class OpenRouter(BaseSDK):
|
|
35
|
-
r"""OpenRouter API: OpenAI-compatible
|
|
34
|
+
r"""OpenRouter API: OpenAI-compatible API with additional OpenRouter features
|
|
36
35
|
https://openrouter.ai/docs - OpenRouter Documentation
|
|
37
36
|
"""
|
|
38
37
|
|
|
@@ -49,16 +48,15 @@ class OpenRouter(BaseSDK):
|
|
|
49
48
|
r"""Model information endpoints"""
|
|
50
49
|
endpoints: "Endpoints"
|
|
51
50
|
r"""Endpoint information"""
|
|
52
|
-
parameters: "Parameters"
|
|
53
|
-
r"""Parameters endpoints"""
|
|
54
51
|
providers: "Providers"
|
|
55
52
|
r"""Provider information endpoints"""
|
|
56
53
|
api_keys: "APIKeys"
|
|
57
54
|
r"""API key management endpoints"""
|
|
55
|
+
guardrails: "Guardrails"
|
|
56
|
+
r"""Guardrails endpoints"""
|
|
58
57
|
o_auth: "OAuth"
|
|
59
58
|
r"""OAuth authentication endpoints"""
|
|
60
59
|
chat: "Chat"
|
|
61
|
-
completions: "Completions"
|
|
62
60
|
_sub_sdk_map = {
|
|
63
61
|
"beta": ("openrouter.beta", "Beta"),
|
|
64
62
|
"analytics": ("openrouter.analytics", "Analytics"),
|
|
@@ -67,12 +65,11 @@ class OpenRouter(BaseSDK):
|
|
|
67
65
|
"generations": ("openrouter.generations", "Generations"),
|
|
68
66
|
"models": ("openrouter.models_", "Models"),
|
|
69
67
|
"endpoints": ("openrouter.endpoints", "Endpoints"),
|
|
70
|
-
"parameters": ("openrouter.parameters", "Parameters"),
|
|
71
68
|
"providers": ("openrouter.providers", "Providers"),
|
|
72
69
|
"api_keys": ("openrouter.api_keys", "APIKeys"),
|
|
70
|
+
"guardrails": ("openrouter.guardrails", "Guardrails"),
|
|
73
71
|
"o_auth": ("openrouter.oauth", "OAuth"),
|
|
74
72
|
"chat": ("openrouter.chat", "Chat"),
|
|
75
|
-
"completions": ("openrouter.completions", "Completions"),
|
|
76
73
|
}
|
|
77
74
|
|
|
78
75
|
def __init__(
|