Skip to content

Commit 7cf9bba

Browse files
feat(api): search_context_size, background tasks, reasoning effort xhigh + responses.retrieve
API-2610: add search_context_size to Search API (low/medium/high, default low) API-2621: add background tasks (background:true + GET /v1/responses/{id} polling) + add 'minimal' and 'xhigh' to reasoning.effort enum + add 'queued' and 'cancelled' to Status enum
1 parent 69b66cf commit 7cf9bba

8 files changed

Lines changed: 113 additions & 13 deletions

File tree

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 10
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai/perplexity-fcf27eaa172b35187bd87aa80b4d18e2b05c5a8544734d56bd4079064bec4bb4.yml
3-
openapi_spec_hash: 35a516eefbd34cf6620a114bf28c27a5
4-
config_hash: 86d643a5df0d7478c095d3efa13438dd
1+
configured_endpoints: 11
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/perplexity-ai/perplexity-fff71875865f090e567436080392bfe633cefac2a82f5eba143ca6fcfed86a56.yml
3+
openapi_spec_hash: 2cb780b456c70cbdcb1ba0182f424c9b
4+
config_hash: 059988c88f0dc18e9e393daed94b5eb6

api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ Types:
5454
- <code><a href="./src/resources/responses.ts">ResponsesCreateParams</a></code>
5555
- <code><a href="./src/resources/responses.ts">ResponsesUsage</a></code>
5656
- <code><a href="./src/resources/responses.ts">ResponseCreateResponse</a></code>
57+
- <code><a href="./src/resources/responses.ts">ResponseRetrieveResponse</a></code>
5758

5859
Methods:
5960

6061
- <code title="post /v1/responses">client.responses.<a href="./src/resources/responses.ts">create</a>({ ...params }) -> ResponseCreateResponse</code>
62+
- <code title="get /v1/responses/{response_id}">client.responses.<a href="./src/resources/responses.ts">retrieve</a>(responseID) -> ResponseRetrieveResponse</code>
6163

6264
# Embeddings
6365

src/client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
ResponseCreateParamsNonStreaming,
3636
ResponseCreateParamsStreaming,
3737
ResponseCreateResponse,
38+
ResponseRetrieveResponse,
3839
ResponseStreamChunk,
3940
Responses,
4041
ResponsesCreateParams,
@@ -799,6 +800,7 @@ export declare namespace Perplexity {
799800
type ResponsesCreateParams as ResponsesCreateParams,
800801
type ResponsesUsage as ResponsesUsage,
801802
type ResponseCreateResponse as ResponseCreateResponse,
803+
type ResponseRetrieveResponse as ResponseRetrieveResponse,
802804
type ResponseCreateParams as ResponseCreateParams,
803805
type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming,
804806
type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming,

src/resources/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export {
2323
type ResponsesCreateParams,
2424
type ResponsesUsage,
2525
type ResponseCreateResponse,
26+
type ResponseRetrieveResponse,
2627
type ResponseCreateParams,
2728
type ResponseCreateParamsNonStreaming,
2829
type ResponseCreateParamsStreaming,

src/resources/responses.ts

Lines changed: 83 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { APIPromise } from '../core/api-promise';
77
import { Stream } from '../core/streaming';
88
import { RequestOptions } from '../internal/request-options';
99
import { addOutputText } from '../lib/add-output-text';
10+
import { path } from '../internal/utils/path';
1011

1112
export class Responses extends APIResource {
1213
/**
@@ -43,6 +44,13 @@ export class Responses extends APIResource {
4344

4445
return promise as APIPromise<Stream<ResponseStreamChunk>>;
4546
}
47+
48+
/**
49+
* Retrieve a response by its ID. Use this to poll the status of background tasks.
50+
*/
51+
retrieve(responseID: string, options?: RequestOptions): APIPromise<ResponseRetrieveResponse> {
52+
return this._client.get(path`/v1/responses/${responseID}`, options);
53+
}
4654
}
4755

4856
/**
@@ -97,7 +105,7 @@ export interface FunctionCallOutputItem {
97105
/**
98106
* Status of a response or output item
99107
*/
100-
status: 'completed' | 'failed' | 'in_progress' | 'requires_action';
108+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
101109

102110
type: 'function_call';
103111

@@ -227,7 +235,7 @@ export namespace OutputItem {
227235
/**
228236
* Status of a response or output item
229237
*/
230-
status: 'completed' | 'failed' | 'in_progress' | 'requires_action';
238+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
231239

232240
type: 'message';
233241
}
@@ -346,7 +354,12 @@ export namespace ResponseStreamChunk {
346354
/**
347355
* Status of a response or output item
348356
*/
349-
status: 'completed' | 'failed' | 'in_progress' | 'requires_action';
357+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
358+
359+
/**
360+
* Whether the response was created in background mode.
361+
*/
362+
background?: boolean;
350363

351364
error?: ResponsesAPI.ErrorInfo;
352365

@@ -396,7 +409,12 @@ export namespace ResponseStreamChunk {
396409
/**
397410
* Status of a response or output item
398411
*/
399-
status: 'completed' | 'failed' | 'in_progress' | 'requires_action';
412+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
413+
414+
/**
415+
* Whether the response was created in background mode.
416+
*/
417+
background?: boolean;
400418

401419
error?: ResponsesAPI.ErrorInfo;
402420

@@ -445,7 +463,12 @@ export namespace ResponseStreamChunk {
445463
/**
446464
* Status of a response or output item
447465
*/
448-
status: 'completed' | 'failed' | 'in_progress' | 'requires_action';
466+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
467+
468+
/**
469+
* Whether the response was created in background mode.
470+
*/
471+
background?: boolean;
449472

450473
error?: ResponsesAPI.ErrorInfo;
451474

@@ -706,6 +729,13 @@ export interface ResponsesCreateParams {
706729
*/
707730
input: string | Array<InputItem>;
708731

732+
/**
733+
* Run the response asynchronously. When true, the request is queued and the
734+
* response object's `status` will be `queued` or `in_progress`. Poll GET
735+
* /v1/responses/{response_id} to retrieve the final result.
736+
*/
737+
background?: boolean | null;
738+
709739
/**
710740
* System instructions for the model
711741
*/
@@ -778,7 +808,7 @@ export namespace ResponsesCreateParams {
778808
/**
779809
* How much effort the model should spend on reasoning
780810
*/
781-
effort?: 'low' | 'medium' | 'high';
811+
effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
782812
}
783813

784814
export interface WebSearchTool {
@@ -936,7 +966,44 @@ export interface ResponseCreateResponse {
936966
/**
937967
* Status of a response or output item
938968
*/
939-
status: 'completed' | 'failed' | 'in_progress' | 'requires_action';
969+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
970+
971+
/**
972+
* Whether the response was created in background mode.
973+
*/
974+
background?: boolean;
975+
976+
error?: ErrorInfo;
977+
978+
usage?: ResponsesUsage;
979+
}
980+
981+
/**
982+
* Non-streaming response returned when stream is false
983+
*/
984+
export interface ResponseRetrieveResponse {
985+
id: string;
986+
987+
created_at: number;
988+
989+
model: string;
990+
991+
/**
992+
* Object type in API responses
993+
*/
994+
object: 'response';
995+
996+
output: Array<OutputItem>;
997+
998+
/**
999+
* Status of a response or output item
1000+
*/
1001+
status: 'completed' | 'failed' | 'in_progress' | 'queued' | 'cancelled' | 'requires_action';
1002+
1003+
/**
1004+
* Whether the response was created in background mode.
1005+
*/
1006+
background?: boolean;
9401007

9411008
error?: ErrorInfo;
9421009

@@ -957,6 +1024,13 @@ export interface ResponseCreateParamsBase {
9571024
*/
9581025
input: string | Array<InputItem>;
9591026

1027+
/**
1028+
* Run the response asynchronously. When true, the request is queued and the
1029+
* response object's `status` will be `queued` or `in_progress`. Poll GET
1030+
* /v1/responses/{response_id} to retrieve the final result.
1031+
*/
1032+
background?: boolean | null;
1033+
9601034
/**
9611035
* System instructions for the model
9621036
*/
@@ -1029,7 +1103,7 @@ export namespace ResponseCreateParams {
10291103
/**
10301104
* How much effort the model should spend on reasoning
10311105
*/
1032-
effort?: 'low' | 'medium' | 'high';
1106+
effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
10331107
}
10341108

10351109
export interface WebSearchTool {
@@ -1149,6 +1223,7 @@ export declare namespace Responses {
11491223
type ResponsesCreateParams as ResponsesCreateParams,
11501224
type ResponsesUsage as ResponsesUsage,
11511225
type ResponseCreateResponse as ResponseCreateResponse,
1226+
type ResponseRetrieveResponse as ResponseRetrieveResponse,
11521227
type ResponseCreateParams as ResponseCreateParams,
11531228
type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming,
11541229
type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming,

src/resources/search.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export interface SearchCreateParams {
5656

5757
search_before_date_filter?: string | null;
5858

59+
/**
60+
* Controls how much search context is retrieved. Higher values return more content
61+
* per result.
62+
*/
63+
search_context_size?: 'low' | 'medium' | 'high' | null;
64+
5965
search_domain_filter?: Array<string> | null;
6066

6167
search_language_filter?: Array<string> | null;

tests/api-resources/responses.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ describe('resource responses', () => {
2424
test.skip('create: required and optional params', async () => {
2525
const response = await client.responses.create({
2626
input: 'string',
27+
background: true,
2728
instructions: 'instructions',
2829
language_preference: 'language_preference',
2930
max_output_tokens: 1,
3031
max_steps: 1,
3132
model: 'model',
3233
models: ['string'],
3334
preset: 'preset',
34-
reasoning: { effort: 'low' },
35+
reasoning: { effort: 'minimal' },
3536
response_format: {
3637
type: 'json_schema',
3738
json_schema: {
@@ -66,4 +67,16 @@ describe('resource responses', () => {
6667
],
6768
});
6869
});
70+
71+
// Mock server tests are disabled
72+
test.skip('retrieve', async () => {
73+
const responsePromise = client.responses.retrieve('response_id');
74+
const rawResponse = await responsePromise.asResponse();
75+
expect(rawResponse).toBeInstanceOf(Response);
76+
const response = await responsePromise;
77+
expect(response).not.toBeInstanceOf(Response);
78+
const dataAndResponse = await responsePromise.withResponse();
79+
expect(dataAndResponse.data).toBe(response);
80+
expect(dataAndResponse.response).toBe(rawResponse);
81+
});
6982
});

tests/api-resources/search.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('resource search', () => {
3333
max_tokens_per_page: 0,
3434
search_after_date_filter: 'search_after_date_filter',
3535
search_before_date_filter: 'search_before_date_filter',
36+
search_context_size: 'low',
3637
search_domain_filter: ['string'],
3738
search_language_filter: ['string'],
3839
search_mode: 'web',

0 commit comments

Comments
 (0)