perplexityai 0.7.1__py3-none-any.whl → 0.8.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.

Potentially problematic release.


This version of perplexityai might be problematic. Click here for more details.

Files changed (34) hide show
  1. perplexity/_version.py +1 -1
  2. perplexity/resources/async_/chat/completions.py +90 -76
  3. perplexity/resources/chat/completions.py +178 -80
  4. perplexity/resources/content.py +2 -6
  5. perplexity/resources/search.py +2 -60
  6. perplexity/types/__init__.py +4 -3
  7. perplexity/types/async_/chat/__init__.py +1 -1
  8. perplexity/types/async_/chat/completion_create_params.py +187 -40
  9. perplexity/types/async_/chat/completion_create_response.py +13 -13
  10. perplexity/types/async_/chat/completion_get_params.py +23 -0
  11. perplexity/types/async_/chat/completion_get_response.py +13 -13
  12. perplexity/types/async_/chat/completion_list_response.py +1 -1
  13. perplexity/types/chat/completion_create_params.py +182 -40
  14. perplexity/types/chat/completion_create_response.py +13 -10
  15. perplexity/types/content_create_params.py +0 -1
  16. perplexity/types/content_create_response.py +0 -6
  17. perplexity/types/search_create_params.py +0 -24
  18. perplexity/types/search_create_response.py +0 -7
  19. perplexity/types/shared/__init__.py +4 -3
  20. perplexity/types/shared/{search_result.py → api_public_search_result.py} +6 -2
  21. perplexity/types/shared/chat_message_input.py +212 -0
  22. perplexity/types/shared/chat_message_output.py +212 -0
  23. perplexity/types/shared/{chat_choice.py → choice.py} +6 -4
  24. perplexity/types/shared/usage_info.py +19 -1
  25. perplexity/types/shared_params/__init__.py +2 -1
  26. perplexity/types/shared_params/api_public_search_result.py +20 -0
  27. perplexity/types/shared_params/chat_message_input.py +216 -0
  28. {perplexityai-0.7.1.dist-info → perplexityai-0.8.0.dist-info}/METADATA +44 -5
  29. {perplexityai-0.7.1.dist-info → perplexityai-0.8.0.dist-info}/RECORD +31 -29
  30. perplexity/types/async_/chat/completion_list_params.py +0 -15
  31. perplexity/types/shared/chat_message.py +0 -31
  32. perplexity/types/shared_params/chat_message.py +0 -31
  33. {perplexityai-0.7.1.dist-info → perplexityai-0.8.0.dist-info}/WHEEL +0 -0
  34. {perplexityai-0.7.1.dist-info → perplexityai-0.8.0.dist-info}/licenses/LICENSE +0 -0
perplexity/_version.py CHANGED
@@ -1,4 +1,4 @@
1
1
  # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  __title__ = "perplexity"
4
- __version__ = "0.7.1" # x-release-please-version
4
+ __version__ = "0.8.0" # x-release-please-version
@@ -2,10 +2,12 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ from typing import Optional
6
+
5
7
  import httpx
6
8
 
7
9
  from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
8
- from ...._utils import maybe_transform, async_maybe_transform
10
+ from ...._utils import maybe_transform, strip_not_given, async_maybe_transform
9
11
  from ...._compat import cached_property
10
12
  from ...._resource import SyncAPIResource, AsyncAPIResource
11
13
  from ...._response import (
@@ -15,7 +17,7 @@ from ...._response import (
15
17
  async_to_streamed_response_wrapper,
16
18
  )
17
19
  from ...._base_client import make_request_options
18
- from ....types.async_.chat import completion_list_params, completion_create_params
20
+ from ....types.async_.chat import completion_get_params, completion_create_params
19
21
  from ....types.async_.chat.completion_get_response import CompletionGetResponse
20
22
  from ....types.async_.chat.completion_list_response import CompletionListResponse
21
23
  from ....types.async_.chat.completion_create_response import CompletionCreateResponse
@@ -47,6 +49,7 @@ class CompletionsResource(SyncAPIResource):
47
49
  self,
48
50
  *,
49
51
  request: completion_create_params.Request,
52
+ idempotency_key: Optional[str] | NotGiven = NOT_GIVEN,
50
53
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
51
54
  # The extra values given here take precedence over values defined on the client or passed to this method.
52
55
  extra_headers: Headers | None = None,
@@ -55,7 +58,10 @@ class CompletionsResource(SyncAPIResource):
55
58
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
56
59
  ) -> CompletionCreateResponse:
57
60
  """
58
- Creates an asynchronous chat completion job
61
+ FastAPI wrapper around async chat completions
62
+
63
+ This endpoint creates an asynchronous chat completion job and returns a job ID
64
+ that can be used to poll for results.
59
65
 
60
66
  Args:
61
67
  extra_headers: Send extra headers
@@ -68,7 +74,13 @@ class CompletionsResource(SyncAPIResource):
68
74
  """
69
75
  return self._post(
70
76
  "/async/chat/completions",
71
- body=maybe_transform({"request": request}, completion_create_params.CompletionCreateParams),
77
+ body=maybe_transform(
78
+ {
79
+ "request": request,
80
+ "idempotency_key": idempotency_key,
81
+ },
82
+ completion_create_params.CompletionCreateParams,
83
+ ),
72
84
  options=make_request_options(
73
85
  extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
74
86
  ),
@@ -78,8 +90,6 @@ class CompletionsResource(SyncAPIResource):
78
90
  def list(
79
91
  self,
80
92
  *,
81
- limit: int | NotGiven = NOT_GIVEN,
82
- next_token: str | NotGiven = NOT_GIVEN,
83
93
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
84
94
  # The extra values given here take precedence over values defined on the client or passed to this method.
85
95
  extra_headers: Headers | None = None,
@@ -87,44 +97,25 @@ class CompletionsResource(SyncAPIResource):
87
97
  extra_body: Body | None = None,
88
98
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
89
99
  ) -> CompletionListResponse:
90
- """
91
- Lists all asynchronous chat completion requests for the authenticated user
92
-
93
- Args:
94
- limit: Maximum number of requests to return
95
-
96
- next_token: Token for fetching the next page of results
97
-
98
- extra_headers: Send extra headers
99
-
100
- extra_query: Add additional query parameters to the request
101
-
102
- extra_body: Add additional JSON properties to the request
103
-
104
- timeout: Override the client-level default timeout for this request, in seconds
105
- """
100
+ """list all async chat completion requests for a given user."""
106
101
  return self._get(
107
102
  "/async/chat/completions",
108
103
  options=make_request_options(
109
- extra_headers=extra_headers,
110
- extra_query=extra_query,
111
- extra_body=extra_body,
112
- timeout=timeout,
113
- query=maybe_transform(
114
- {
115
- "limit": limit,
116
- "next_token": next_token,
117
- },
118
- completion_list_params.CompletionListParams,
119
- ),
104
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
120
105
  ),
121
106
  cast_to=CompletionListResponse,
122
107
  )
123
108
 
124
109
  def get(
125
110
  self,
126
- request_id: str,
111
+ api_request: str,
127
112
  *,
113
+ local_mode: bool | NotGiven = NOT_GIVEN,
114
+ x_client_env: str | NotGiven = NOT_GIVEN,
115
+ x_client_name: str | NotGiven = NOT_GIVEN,
116
+ x_request_time: str | NotGiven = NOT_GIVEN,
117
+ x_usage_tier: str | NotGiven = NOT_GIVEN,
118
+ x_user_id: str | NotGiven = NOT_GIVEN,
128
119
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
129
120
  # The extra values given here take precedence over values defined on the client or passed to this method.
130
121
  extra_headers: Headers | None = None,
@@ -133,7 +124,7 @@ class CompletionsResource(SyncAPIResource):
133
124
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
134
125
  ) -> CompletionGetResponse:
135
126
  """
136
- Retrieves the status and result of a specific asynchronous chat completion job
127
+ get the response for a given async chat completion request.
137
128
 
138
129
  Args:
139
130
  extra_headers: Send extra headers
@@ -144,12 +135,28 @@ class CompletionsResource(SyncAPIResource):
144
135
 
145
136
  timeout: Override the client-level default timeout for this request, in seconds
146
137
  """
147
- if not request_id:
148
- raise ValueError(f"Expected a non-empty value for `request_id` but received {request_id!r}")
138
+ if not api_request:
139
+ raise ValueError(f"Expected a non-empty value for `api_request` but received {api_request!r}")
140
+ extra_headers = {
141
+ **strip_not_given(
142
+ {
143
+ "x-client-env": x_client_env,
144
+ "x-client-name": x_client_name,
145
+ "x-request-time": x_request_time,
146
+ "x-usage-tier": x_usage_tier,
147
+ "x-user-id": x_user_id,
148
+ }
149
+ ),
150
+ **(extra_headers or {}),
151
+ }
149
152
  return self._get(
150
- f"/async/chat/completions/{request_id}",
153
+ f"/async/chat/completions/{api_request}",
151
154
  options=make_request_options(
152
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
155
+ extra_headers=extra_headers,
156
+ extra_query=extra_query,
157
+ extra_body=extra_body,
158
+ timeout=timeout,
159
+ query=maybe_transform({"local_mode": local_mode}, completion_get_params.CompletionGetParams),
153
160
  ),
154
161
  cast_to=CompletionGetResponse,
155
162
  )
@@ -179,6 +186,7 @@ class AsyncCompletionsResource(AsyncAPIResource):
179
186
  self,
180
187
  *,
181
188
  request: completion_create_params.Request,
189
+ idempotency_key: Optional[str] | NotGiven = NOT_GIVEN,
182
190
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
183
191
  # The extra values given here take precedence over values defined on the client or passed to this method.
184
192
  extra_headers: Headers | None = None,
@@ -187,7 +195,10 @@ class AsyncCompletionsResource(AsyncAPIResource):
187
195
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
188
196
  ) -> CompletionCreateResponse:
189
197
  """
190
- Creates an asynchronous chat completion job
198
+ FastAPI wrapper around async chat completions
199
+
200
+ This endpoint creates an asynchronous chat completion job and returns a job ID
201
+ that can be used to poll for results.
191
202
 
192
203
  Args:
193
204
  extra_headers: Send extra headers
@@ -200,7 +211,13 @@ class AsyncCompletionsResource(AsyncAPIResource):
200
211
  """
201
212
  return await self._post(
202
213
  "/async/chat/completions",
203
- body=await async_maybe_transform({"request": request}, completion_create_params.CompletionCreateParams),
214
+ body=await async_maybe_transform(
215
+ {
216
+ "request": request,
217
+ "idempotency_key": idempotency_key,
218
+ },
219
+ completion_create_params.CompletionCreateParams,
220
+ ),
204
221
  options=make_request_options(
205
222
  extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
206
223
  ),
@@ -210,8 +227,6 @@ class AsyncCompletionsResource(AsyncAPIResource):
210
227
  async def list(
211
228
  self,
212
229
  *,
213
- limit: int | NotGiven = NOT_GIVEN,
214
- next_token: str | NotGiven = NOT_GIVEN,
215
230
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
216
231
  # The extra values given here take precedence over values defined on the client or passed to this method.
217
232
  extra_headers: Headers | None = None,
@@ -219,44 +234,25 @@ class AsyncCompletionsResource(AsyncAPIResource):
219
234
  extra_body: Body | None = None,
220
235
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
221
236
  ) -> CompletionListResponse:
222
- """
223
- Lists all asynchronous chat completion requests for the authenticated user
224
-
225
- Args:
226
- limit: Maximum number of requests to return
227
-
228
- next_token: Token for fetching the next page of results
229
-
230
- extra_headers: Send extra headers
231
-
232
- extra_query: Add additional query parameters to the request
233
-
234
- extra_body: Add additional JSON properties to the request
235
-
236
- timeout: Override the client-level default timeout for this request, in seconds
237
- """
237
+ """list all async chat completion requests for a given user."""
238
238
  return await self._get(
239
239
  "/async/chat/completions",
240
240
  options=make_request_options(
241
- extra_headers=extra_headers,
242
- extra_query=extra_query,
243
- extra_body=extra_body,
244
- timeout=timeout,
245
- query=await async_maybe_transform(
246
- {
247
- "limit": limit,
248
- "next_token": next_token,
249
- },
250
- completion_list_params.CompletionListParams,
251
- ),
241
+ extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
252
242
  ),
253
243
  cast_to=CompletionListResponse,
254
244
  )
255
245
 
256
246
  async def get(
257
247
  self,
258
- request_id: str,
248
+ api_request: str,
259
249
  *,
250
+ local_mode: bool | NotGiven = NOT_GIVEN,
251
+ x_client_env: str | NotGiven = NOT_GIVEN,
252
+ x_client_name: str | NotGiven = NOT_GIVEN,
253
+ x_request_time: str | NotGiven = NOT_GIVEN,
254
+ x_usage_tier: str | NotGiven = NOT_GIVEN,
255
+ x_user_id: str | NotGiven = NOT_GIVEN,
260
256
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
261
257
  # The extra values given here take precedence over values defined on the client or passed to this method.
262
258
  extra_headers: Headers | None = None,
@@ -265,7 +261,7 @@ class AsyncCompletionsResource(AsyncAPIResource):
265
261
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
266
262
  ) -> CompletionGetResponse:
267
263
  """
268
- Retrieves the status and result of a specific asynchronous chat completion job
264
+ get the response for a given async chat completion request.
269
265
 
270
266
  Args:
271
267
  extra_headers: Send extra headers
@@ -276,12 +272,30 @@ class AsyncCompletionsResource(AsyncAPIResource):
276
272
 
277
273
  timeout: Override the client-level default timeout for this request, in seconds
278
274
  """
279
- if not request_id:
280
- raise ValueError(f"Expected a non-empty value for `request_id` but received {request_id!r}")
275
+ if not api_request:
276
+ raise ValueError(f"Expected a non-empty value for `api_request` but received {api_request!r}")
277
+ extra_headers = {
278
+ **strip_not_given(
279
+ {
280
+ "x-client-env": x_client_env,
281
+ "x-client-name": x_client_name,
282
+ "x-request-time": x_request_time,
283
+ "x-usage-tier": x_usage_tier,
284
+ "x-user-id": x_user_id,
285
+ }
286
+ ),
287
+ **(extra_headers or {}),
288
+ }
281
289
  return await self._get(
282
- f"/async/chat/completions/{request_id}",
290
+ f"/async/chat/completions/{api_request}",
283
291
  options=make_request_options(
284
- extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
292
+ extra_headers=extra_headers,
293
+ extra_query=extra_query,
294
+ extra_body=extra_body,
295
+ timeout=timeout,
296
+ query=await async_maybe_transform(
297
+ {"local_mode": local_mode}, completion_get_params.CompletionGetParams
298
+ ),
285
299
  ),
286
300
  cast_to=CompletionGetResponse,
287
301
  )
@@ -2,7 +2,7 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from typing import Iterable, Optional
5
+ from typing import Dict, Union, Iterable, Optional
6
6
  from typing_extensions import Literal
7
7
 
8
8
  import httpx
@@ -19,8 +19,8 @@ from ..._response import (
19
19
  )
20
20
  from ...types.chat import completion_create_params
21
21
  from ..._base_client import make_request_options
22
- from ...types.shared_params.chat_message import ChatMessage
23
22
  from ...types.chat.completion_create_response import CompletionCreateResponse
23
+ from ...types.shared_params.chat_message_input import ChatMessageInput
24
24
 
25
25
  __all__ = ["CompletionsResource", "AsyncCompletionsResource"]
26
26
 
@@ -48,20 +48,60 @@ class CompletionsResource(SyncAPIResource):
48
48
  def create(
49
49
  self,
50
50
  *,
51
- messages: Iterable[ChatMessage],
52
- model: Literal["sonar", "sonar-pro", "sonar-deep-research", "sonar-reasoning", "sonar-reasoning-pro"],
53
- disable_search: bool | NotGiven = NOT_GIVEN,
54
- enable_search_classifier: bool | NotGiven = NOT_GIVEN,
51
+ messages: Iterable[ChatMessageInput],
52
+ model: str,
53
+ _debug_pro_search: bool | NotGiven = NOT_GIVEN,
54
+ _inputs: Optional[Iterable[int]] | NotGiven = NOT_GIVEN,
55
+ _is_browser_agent: Optional[bool] | NotGiven = NOT_GIVEN,
56
+ _prompt_token_length: Optional[int] | NotGiven = NOT_GIVEN,
57
+ best_of: Optional[int] | NotGiven = NOT_GIVEN,
58
+ country: Optional[str] | NotGiven = NOT_GIVEN,
59
+ cum_logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
60
+ debug_params: Optional[completion_create_params.DebugParams] | NotGiven = NOT_GIVEN,
61
+ disable_search: Optional[bool] | NotGiven = NOT_GIVEN,
62
+ diverse_first_token: Optional[bool] | NotGiven = NOT_GIVEN,
63
+ enable_search_classifier: Optional[bool] | NotGiven = NOT_GIVEN,
64
+ file_workspace_id: Optional[str] | NotGiven = NOT_GIVEN,
65
+ frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
66
+ has_image_url: bool | NotGiven = NOT_GIVEN,
67
+ image_domain_filter: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
68
+ image_format_filter: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
55
69
  last_updated_after_filter: Optional[str] | NotGiven = NOT_GIVEN,
56
70
  last_updated_before_filter: Optional[str] | NotGiven = NOT_GIVEN,
57
- reasoning_effort: Optional[Literal["low", "medium", "high"]] | NotGiven = NOT_GIVEN,
58
- return_images: bool | NotGiven = NOT_GIVEN,
59
- return_related_questions: bool | NotGiven = NOT_GIVEN,
71
+ latitude: Optional[float] | NotGiven = NOT_GIVEN,
72
+ logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
73
+ longitude: Optional[float] | NotGiven = NOT_GIVEN,
74
+ max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
75
+ n: Optional[int] | NotGiven = NOT_GIVEN,
76
+ num_images: int | NotGiven = NOT_GIVEN,
77
+ num_search_results: int | NotGiven = NOT_GIVEN,
78
+ parallel_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
79
+ presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
80
+ ranking_model: Optional[str] | NotGiven = NOT_GIVEN,
81
+ reasoning_effort: Optional[Literal["minimal", "low", "medium", "high"]] | NotGiven = NOT_GIVEN,
82
+ response_format: Optional[completion_create_params.ResponseFormat] | NotGiven = NOT_GIVEN,
83
+ response_metadata: Optional[Dict[str, object]] | NotGiven = NOT_GIVEN,
84
+ return_images: Optional[bool] | NotGiven = NOT_GIVEN,
85
+ return_related_questions: Optional[bool] | NotGiven = NOT_GIVEN,
86
+ return_videos: Optional[bool] | NotGiven = NOT_GIVEN,
87
+ safe_search: Optional[bool] | NotGiven = NOT_GIVEN,
60
88
  search_after_date_filter: Optional[str] | NotGiven = NOT_GIVEN,
61
89
  search_before_date_filter: Optional[str] | NotGiven = NOT_GIVEN,
62
90
  search_domain_filter: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
91
+ search_internal_properties: Optional[Dict[str, object]] | NotGiven = NOT_GIVEN,
63
92
  search_mode: Optional[Literal["web", "academic", "sec"]] | NotGiven = NOT_GIVEN,
64
93
  search_recency_filter: Optional[Literal["hour", "day", "week", "month", "year"]] | NotGiven = NOT_GIVEN,
94
+ search_tenant: Optional[str] | NotGiven = NOT_GIVEN,
95
+ stop: Union[str, SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
96
+ stream: Optional[bool] | NotGiven = NOT_GIVEN,
97
+ temperature: Optional[float] | NotGiven = NOT_GIVEN,
98
+ tool_choice: Optional[Literal["none", "auto", "required"]] | NotGiven = NOT_GIVEN,
99
+ tools: Optional[Iterable[completion_create_params.Tool]] | NotGiven = NOT_GIVEN,
100
+ top_k: Optional[int] | NotGiven = NOT_GIVEN,
101
+ top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
102
+ top_p: Optional[float] | NotGiven = NOT_GIVEN,
103
+ updated_after_timestamp: Optional[int] | NotGiven = NOT_GIVEN,
104
+ updated_before_timestamp: Optional[int] | NotGiven = NOT_GIVEN,
65
105
  web_search_options: completion_create_params.WebSearchOptions | NotGiven = NOT_GIVEN,
66
106
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
67
107
  # The extra values given here take precedence over values defined on the client or passed to this method.
@@ -71,40 +111,9 @@ class CompletionsResource(SyncAPIResource):
71
111
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
72
112
  ) -> CompletionCreateResponse:
73
113
  """
74
- Generates a model's response for the given chat conversation with integrated
75
- search capabilities
114
+ FastAPI wrapper around chat completions
76
115
 
77
116
  Args:
78
- messages: A list of messages comprising the conversation so far
79
-
80
- model: The name of the model that will complete your prompt
81
-
82
- disable_search: Disables web search completely - model uses only training data
83
-
84
- enable_search_classifier: Enables classifier that decides if web search is needed
85
-
86
- last_updated_after_filter: Only include content last updated after this date (YYYY-MM-DD)
87
-
88
- last_updated_before_filter: Only include content last updated before this date (YYYY-MM-DD)
89
-
90
- reasoning_effort: Controls computational effort for sonar-deep-research model. Higher effort =
91
- more thorough but more tokens
92
-
93
- return_images: Whether to include images in search results
94
-
95
- return_related_questions: Whether to return related questions
96
-
97
- search_after_date_filter: Only include content published after this date (YYYY-MM-DD)
98
-
99
- search_before_date_filter: Only include content published before this date (YYYY-MM-DD)
100
-
101
- search_domain_filter: List of domains to limit search results to. Use '-' prefix to exclude domains
102
-
103
- search_mode: Type of search: 'web' for general, 'academic' for scholarly, 'sec' for SEC
104
- filings
105
-
106
- search_recency_filter: Filter results by how recently they were published
107
-
108
117
  extra_headers: Send extra headers
109
118
 
110
119
  extra_query: Add additional query parameters to the request
@@ -119,18 +128,58 @@ class CompletionsResource(SyncAPIResource):
119
128
  {
120
129
  "messages": messages,
121
130
  "model": model,
131
+ "_debug_pro_search": _debug_pro_search,
132
+ "_inputs": _inputs,
133
+ "_is_browser_agent": _is_browser_agent,
134
+ "_prompt_token_length": _prompt_token_length,
135
+ "best_of": best_of,
136
+ "country": country,
137
+ "cum_logprobs": cum_logprobs,
138
+ "debug_params": debug_params,
122
139
  "disable_search": disable_search,
140
+ "diverse_first_token": diverse_first_token,
123
141
  "enable_search_classifier": enable_search_classifier,
142
+ "file_workspace_id": file_workspace_id,
143
+ "frequency_penalty": frequency_penalty,
144
+ "has_image_url": has_image_url,
145
+ "image_domain_filter": image_domain_filter,
146
+ "image_format_filter": image_format_filter,
124
147
  "last_updated_after_filter": last_updated_after_filter,
125
148
  "last_updated_before_filter": last_updated_before_filter,
149
+ "latitude": latitude,
150
+ "logprobs": logprobs,
151
+ "longitude": longitude,
152
+ "max_tokens": max_tokens,
153
+ "n": n,
154
+ "num_images": num_images,
155
+ "num_search_results": num_search_results,
156
+ "parallel_tool_calls": parallel_tool_calls,
157
+ "presence_penalty": presence_penalty,
158
+ "ranking_model": ranking_model,
126
159
  "reasoning_effort": reasoning_effort,
160
+ "response_format": response_format,
161
+ "response_metadata": response_metadata,
127
162
  "return_images": return_images,
128
163
  "return_related_questions": return_related_questions,
164
+ "return_videos": return_videos,
165
+ "safe_search": safe_search,
129
166
  "search_after_date_filter": search_after_date_filter,
130
167
  "search_before_date_filter": search_before_date_filter,
131
168
  "search_domain_filter": search_domain_filter,
169
+ "search_internal_properties": search_internal_properties,
132
170
  "search_mode": search_mode,
133
171
  "search_recency_filter": search_recency_filter,
172
+ "search_tenant": search_tenant,
173
+ "stop": stop,
174
+ "stream": stream,
175
+ "temperature": temperature,
176
+ "tool_choice": tool_choice,
177
+ "tools": tools,
178
+ "top_k": top_k,
179
+ "top_logprobs": top_logprobs,
180
+ "top_p": top_p,
181
+ "updated_after_timestamp": updated_after_timestamp,
182
+ "updated_before_timestamp": updated_before_timestamp,
134
183
  "web_search_options": web_search_options,
135
184
  },
136
185
  completion_create_params.CompletionCreateParams,
@@ -165,20 +214,60 @@ class AsyncCompletionsResource(AsyncAPIResource):
165
214
  async def create(
166
215
  self,
167
216
  *,
168
- messages: Iterable[ChatMessage],
169
- model: Literal["sonar", "sonar-pro", "sonar-deep-research", "sonar-reasoning", "sonar-reasoning-pro"],
170
- disable_search: bool | NotGiven = NOT_GIVEN,
171
- enable_search_classifier: bool | NotGiven = NOT_GIVEN,
217
+ messages: Iterable[ChatMessageInput],
218
+ model: str,
219
+ _debug_pro_search: bool | NotGiven = NOT_GIVEN,
220
+ _inputs: Optional[Iterable[int]] | NotGiven = NOT_GIVEN,
221
+ _is_browser_agent: Optional[bool] | NotGiven = NOT_GIVEN,
222
+ _prompt_token_length: Optional[int] | NotGiven = NOT_GIVEN,
223
+ best_of: Optional[int] | NotGiven = NOT_GIVEN,
224
+ country: Optional[str] | NotGiven = NOT_GIVEN,
225
+ cum_logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
226
+ debug_params: Optional[completion_create_params.DebugParams] | NotGiven = NOT_GIVEN,
227
+ disable_search: Optional[bool] | NotGiven = NOT_GIVEN,
228
+ diverse_first_token: Optional[bool] | NotGiven = NOT_GIVEN,
229
+ enable_search_classifier: Optional[bool] | NotGiven = NOT_GIVEN,
230
+ file_workspace_id: Optional[str] | NotGiven = NOT_GIVEN,
231
+ frequency_penalty: Optional[float] | NotGiven = NOT_GIVEN,
232
+ has_image_url: bool | NotGiven = NOT_GIVEN,
233
+ image_domain_filter: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
234
+ image_format_filter: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
172
235
  last_updated_after_filter: Optional[str] | NotGiven = NOT_GIVEN,
173
236
  last_updated_before_filter: Optional[str] | NotGiven = NOT_GIVEN,
174
- reasoning_effort: Optional[Literal["low", "medium", "high"]] | NotGiven = NOT_GIVEN,
175
- return_images: bool | NotGiven = NOT_GIVEN,
176
- return_related_questions: bool | NotGiven = NOT_GIVEN,
237
+ latitude: Optional[float] | NotGiven = NOT_GIVEN,
238
+ logprobs: Optional[bool] | NotGiven = NOT_GIVEN,
239
+ longitude: Optional[float] | NotGiven = NOT_GIVEN,
240
+ max_tokens: Optional[int] | NotGiven = NOT_GIVEN,
241
+ n: Optional[int] | NotGiven = NOT_GIVEN,
242
+ num_images: int | NotGiven = NOT_GIVEN,
243
+ num_search_results: int | NotGiven = NOT_GIVEN,
244
+ parallel_tool_calls: Optional[bool] | NotGiven = NOT_GIVEN,
245
+ presence_penalty: Optional[float] | NotGiven = NOT_GIVEN,
246
+ ranking_model: Optional[str] | NotGiven = NOT_GIVEN,
247
+ reasoning_effort: Optional[Literal["minimal", "low", "medium", "high"]] | NotGiven = NOT_GIVEN,
248
+ response_format: Optional[completion_create_params.ResponseFormat] | NotGiven = NOT_GIVEN,
249
+ response_metadata: Optional[Dict[str, object]] | NotGiven = NOT_GIVEN,
250
+ return_images: Optional[bool] | NotGiven = NOT_GIVEN,
251
+ return_related_questions: Optional[bool] | NotGiven = NOT_GIVEN,
252
+ return_videos: Optional[bool] | NotGiven = NOT_GIVEN,
253
+ safe_search: Optional[bool] | NotGiven = NOT_GIVEN,
177
254
  search_after_date_filter: Optional[str] | NotGiven = NOT_GIVEN,
178
255
  search_before_date_filter: Optional[str] | NotGiven = NOT_GIVEN,
179
256
  search_domain_filter: Optional[SequenceNotStr[str]] | NotGiven = NOT_GIVEN,
257
+ search_internal_properties: Optional[Dict[str, object]] | NotGiven = NOT_GIVEN,
180
258
  search_mode: Optional[Literal["web", "academic", "sec"]] | NotGiven = NOT_GIVEN,
181
259
  search_recency_filter: Optional[Literal["hour", "day", "week", "month", "year"]] | NotGiven = NOT_GIVEN,
260
+ search_tenant: Optional[str] | NotGiven = NOT_GIVEN,
261
+ stop: Union[str, SequenceNotStr[str], None] | NotGiven = NOT_GIVEN,
262
+ stream: Optional[bool] | NotGiven = NOT_GIVEN,
263
+ temperature: Optional[float] | NotGiven = NOT_GIVEN,
264
+ tool_choice: Optional[Literal["none", "auto", "required"]] | NotGiven = NOT_GIVEN,
265
+ tools: Optional[Iterable[completion_create_params.Tool]] | NotGiven = NOT_GIVEN,
266
+ top_k: Optional[int] | NotGiven = NOT_GIVEN,
267
+ top_logprobs: Optional[int] | NotGiven = NOT_GIVEN,
268
+ top_p: Optional[float] | NotGiven = NOT_GIVEN,
269
+ updated_after_timestamp: Optional[int] | NotGiven = NOT_GIVEN,
270
+ updated_before_timestamp: Optional[int] | NotGiven = NOT_GIVEN,
182
271
  web_search_options: completion_create_params.WebSearchOptions | NotGiven = NOT_GIVEN,
183
272
  # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
184
273
  # The extra values given here take precedence over values defined on the client or passed to this method.
@@ -188,40 +277,9 @@ class AsyncCompletionsResource(AsyncAPIResource):
188
277
  timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
189
278
  ) -> CompletionCreateResponse:
190
279
  """
191
- Generates a model's response for the given chat conversation with integrated
192
- search capabilities
280
+ FastAPI wrapper around chat completions
193
281
 
194
282
  Args:
195
- messages: A list of messages comprising the conversation so far
196
-
197
- model: The name of the model that will complete your prompt
198
-
199
- disable_search: Disables web search completely - model uses only training data
200
-
201
- enable_search_classifier: Enables classifier that decides if web search is needed
202
-
203
- last_updated_after_filter: Only include content last updated after this date (YYYY-MM-DD)
204
-
205
- last_updated_before_filter: Only include content last updated before this date (YYYY-MM-DD)
206
-
207
- reasoning_effort: Controls computational effort for sonar-deep-research model. Higher effort =
208
- more thorough but more tokens
209
-
210
- return_images: Whether to include images in search results
211
-
212
- return_related_questions: Whether to return related questions
213
-
214
- search_after_date_filter: Only include content published after this date (YYYY-MM-DD)
215
-
216
- search_before_date_filter: Only include content published before this date (YYYY-MM-DD)
217
-
218
- search_domain_filter: List of domains to limit search results to. Use '-' prefix to exclude domains
219
-
220
- search_mode: Type of search: 'web' for general, 'academic' for scholarly, 'sec' for SEC
221
- filings
222
-
223
- search_recency_filter: Filter results by how recently they were published
224
-
225
283
  extra_headers: Send extra headers
226
284
 
227
285
  extra_query: Add additional query parameters to the request
@@ -236,18 +294,58 @@ class AsyncCompletionsResource(AsyncAPIResource):
236
294
  {
237
295
  "messages": messages,
238
296
  "model": model,
297
+ "_debug_pro_search": _debug_pro_search,
298
+ "_inputs": _inputs,
299
+ "_is_browser_agent": _is_browser_agent,
300
+ "_prompt_token_length": _prompt_token_length,
301
+ "best_of": best_of,
302
+ "country": country,
303
+ "cum_logprobs": cum_logprobs,
304
+ "debug_params": debug_params,
239
305
  "disable_search": disable_search,
306
+ "diverse_first_token": diverse_first_token,
240
307
  "enable_search_classifier": enable_search_classifier,
308
+ "file_workspace_id": file_workspace_id,
309
+ "frequency_penalty": frequency_penalty,
310
+ "has_image_url": has_image_url,
311
+ "image_domain_filter": image_domain_filter,
312
+ "image_format_filter": image_format_filter,
241
313
  "last_updated_after_filter": last_updated_after_filter,
242
314
  "last_updated_before_filter": last_updated_before_filter,
315
+ "latitude": latitude,
316
+ "logprobs": logprobs,
317
+ "longitude": longitude,
318
+ "max_tokens": max_tokens,
319
+ "n": n,
320
+ "num_images": num_images,
321
+ "num_search_results": num_search_results,
322
+ "parallel_tool_calls": parallel_tool_calls,
323
+ "presence_penalty": presence_penalty,
324
+ "ranking_model": ranking_model,
243
325
  "reasoning_effort": reasoning_effort,
326
+ "response_format": response_format,
327
+ "response_metadata": response_metadata,
244
328
  "return_images": return_images,
245
329
  "return_related_questions": return_related_questions,
330
+ "return_videos": return_videos,
331
+ "safe_search": safe_search,
246
332
  "search_after_date_filter": search_after_date_filter,
247
333
  "search_before_date_filter": search_before_date_filter,
248
334
  "search_domain_filter": search_domain_filter,
335
+ "search_internal_properties": search_internal_properties,
249
336
  "search_mode": search_mode,
250
337
  "search_recency_filter": search_recency_filter,
338
+ "search_tenant": search_tenant,
339
+ "stop": stop,
340
+ "stream": stream,
341
+ "temperature": temperature,
342
+ "tool_choice": tool_choice,
343
+ "tools": tools,
344
+ "top_k": top_k,
345
+ "top_logprobs": top_logprobs,
346
+ "top_p": top_p,
347
+ "updated_after_timestamp": updated_after_timestamp,
348
+ "updated_before_timestamp": updated_before_timestamp,
251
349
  "web_search_options": web_search_options,
252
350
  },
253
351
  completion_create_params.CompletionCreateParams,