Skip to content

Commit e8d2092

Browse files
docs: add examples to tsdocs
1 parent bbf5d45 commit e8d2092

20 files changed

+423
-0
lines changed

src/resources/audio/speech.ts

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import { type Response } from '../../_shims/index';
77
export class Speech extends APIResource {
88
/**
99
* Generates audio from the input text.
10+
*
11+
* @example
12+
* ```ts
13+
* const speech = await client.audio.speech.create({
14+
* input: 'input',
15+
* model: 'string',
16+
* voice: 'ash',
17+
* });
18+
*
19+
* const content = await speech.blob();
20+
* console.log(content);
21+
* ```
1022
*/
1123
create(body: SpeechCreateParams, options?: Core.RequestOptions): Core.APIPromise<Response> {
1224
return this._client.post('/audio/speech', {

src/resources/audio/transcriptions.ts

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ import { Stream } from '../../streaming';
99
export class Transcriptions extends APIResource {
1010
/**
1111
* Transcribes audio into the input language.
12+
*
13+
* @example
14+
* ```ts
15+
* const transcription =
16+
* await client.audio.transcriptions.create({
17+
* file: fs.createReadStream('speech.mp3'),
18+
* model: 'gpt-4o-transcribe',
19+
* });
20+
* ```
1221
*/
1322
create(
1423
body: TranscriptionCreateParamsNonStreaming<'json' | undefined>,

src/resources/audio/translations.ts

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import * as TranscriptionsAPI from './transcriptions';
88
export class Translations extends APIResource {
99
/**
1010
* Translates audio into English.
11+
*
12+
* @example
13+
* ```ts
14+
* const translation = await client.audio.translations.create({
15+
* file: fs.createReadStream('speech.mp3'),
16+
* model: 'whisper-1',
17+
* });
18+
* ```
1119
*/
1220
create(
1321
body: TranslationCreateParams<'json' | undefined>,

src/resources/beta/assistants.ts

+36
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ import { AssistantStream } from '../../lib/AssistantStream';
1414
export class Assistants extends APIResource {
1515
/**
1616
* Create an assistant with a model and instructions.
17+
*
18+
* @example
19+
* ```ts
20+
* const assistant = await client.beta.assistants.create({
21+
* model: 'gpt-4o',
22+
* });
23+
* ```
1724
*/
1825
create(body: AssistantCreateParams, options?: Core.RequestOptions): Core.APIPromise<Assistant> {
1926
return this._client.post('/assistants', {
@@ -25,6 +32,13 @@ export class Assistants extends APIResource {
2532

2633
/**
2734
* Retrieves an assistant.
35+
*
36+
* @example
37+
* ```ts
38+
* const assistant = await client.beta.assistants.retrieve(
39+
* 'assistant_id',
40+
* );
41+
* ```
2842
*/
2943
retrieve(assistantId: string, options?: Core.RequestOptions): Core.APIPromise<Assistant> {
3044
return this._client.get(`/assistants/${assistantId}`, {
@@ -35,6 +49,13 @@ export class Assistants extends APIResource {
3549

3650
/**
3751
* Modifies an assistant.
52+
*
53+
* @example
54+
* ```ts
55+
* const assistant = await client.beta.assistants.update(
56+
* 'assistant_id',
57+
* );
58+
* ```
3859
*/
3960
update(
4061
assistantId: string,
@@ -50,6 +71,14 @@ export class Assistants extends APIResource {
5071

5172
/**
5273
* Returns a list of assistants.
74+
*
75+
* @example
76+
* ```ts
77+
* // Automatically fetches more pages as needed.
78+
* for await (const assistant of client.beta.assistants.list()) {
79+
* // ...
80+
* }
81+
* ```
5382
*/
5483
list(
5584
query?: AssistantListParams,
@@ -72,6 +101,13 @@ export class Assistants extends APIResource {
72101

73102
/**
74103
* Delete an assistant.
104+
*
105+
* @example
106+
* ```ts
107+
* const assistantDeleted = await client.beta.assistants.del(
108+
* 'assistant_id',
109+
* );
110+
* ```
75111
*/
76112
del(assistantId: string, options?: Core.RequestOptions): Core.APIPromise<AssistantDeleted> {
77113
return this._client.delete(`/assistants/${assistantId}`, {

src/resources/beta/realtime/sessions.ts

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export class Sessions extends APIResource {
1212
* It responds with a session object, plus a `client_secret` key which contains a
1313
* usable ephemeral API token that can be used to authenticate browser clients for
1414
* the Realtime API.
15+
*
16+
* @example
17+
* ```ts
18+
* const session =
19+
* await client.beta.realtime.sessions.create();
20+
* ```
1521
*/
1622
create(body: SessionCreateParams, options?: Core.RequestOptions): Core.APIPromise<SessionCreateResponse> {
1723
return this._client.post('/realtime/sessions', {

src/resources/beta/realtime/transcription-sessions.ts

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ export class TranscriptionSessions extends APIResource {
1212
* It responds with a session object, plus a `client_secret` key which contains a
1313
* usable ephemeral API token that can be used to authenticate browser clients for
1414
* the Realtime API.
15+
*
16+
* @example
17+
* ```ts
18+
* const transcriptionSession =
19+
* await client.beta.realtime.transcriptionSessions.create();
20+
* ```
1521
*/
1622
create(
1723
body: TranscriptionSessionCreateParams,

src/resources/beta/threads/messages.ts

+43
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ import { CursorPage, type CursorPageParams } from '../../../pagination';
1010
export class Messages extends APIResource {
1111
/**
1212
* Create a message.
13+
*
14+
* @example
15+
* ```ts
16+
* const message = await client.beta.threads.messages.create(
17+
* 'thread_id',
18+
* { content: 'string', role: 'user' },
19+
* );
20+
* ```
1321
*/
1422
create(
1523
threadId: string,
@@ -25,6 +33,14 @@ export class Messages extends APIResource {
2533

2634
/**
2735
* Retrieve a message.
36+
*
37+
* @example
38+
* ```ts
39+
* const message = await client.beta.threads.messages.retrieve(
40+
* 'thread_id',
41+
* 'message_id',
42+
* );
43+
* ```
2844
*/
2945
retrieve(threadId: string, messageId: string, options?: Core.RequestOptions): Core.APIPromise<Message> {
3046
return this._client.get(`/threads/${threadId}/messages/${messageId}`, {
@@ -35,6 +51,14 @@ export class Messages extends APIResource {
3551

3652
/**
3753
* Modifies a message.
54+
*
55+
* @example
56+
* ```ts
57+
* const message = await client.beta.threads.messages.update(
58+
* 'thread_id',
59+
* 'message_id',
60+
* );
61+
* ```
3862
*/
3963
update(
4064
threadId: string,
@@ -51,6 +75,16 @@ export class Messages extends APIResource {
5175

5276
/**
5377
* Returns a list of messages for a given thread.
78+
*
79+
* @example
80+
* ```ts
81+
* // Automatically fetches more pages as needed.
82+
* for await (const message of client.beta.threads.messages.list(
83+
* 'thread_id',
84+
* )) {
85+
* // ...
86+
* }
87+
* ```
5488
*/
5589
list(
5690
threadId: string,
@@ -75,6 +109,15 @@ export class Messages extends APIResource {
75109

76110
/**
77111
* Deletes a message.
112+
*
113+
* @example
114+
* ```ts
115+
* const messageDeleted =
116+
* await client.beta.threads.messages.del(
117+
* 'thread_id',
118+
* 'message_id',
119+
* );
120+
* ```
78121
*/
79122
del(threadId: string, messageId: string, options?: Core.RequestOptions): Core.APIPromise<MessageDeleted> {
80123
return this._client.delete(`/threads/${threadId}/messages/${messageId}`, {

src/resources/beta/threads/runs/runs.ts

+52
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ export class Runs extends APIResource {
4545

4646
/**
4747
* Create a run.
48+
*
49+
* @example
50+
* ```ts
51+
* const run = await client.beta.threads.runs.create(
52+
* 'thread_id',
53+
* { assistant_id: 'assistant_id' },
54+
* );
55+
* ```
4856
*/
4957
create(
5058
threadId: string,
@@ -78,6 +86,14 @@ export class Runs extends APIResource {
7886

7987
/**
8088
* Retrieves a run.
89+
*
90+
* @example
91+
* ```ts
92+
* const run = await client.beta.threads.runs.retrieve(
93+
* 'thread_id',
94+
* 'run_id',
95+
* );
96+
* ```
8197
*/
8298
retrieve(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise<Run> {
8399
return this._client.get(`/threads/${threadId}/runs/${runId}`, {
@@ -88,6 +104,14 @@ export class Runs extends APIResource {
88104

89105
/**
90106
* Modifies a run.
107+
*
108+
* @example
109+
* ```ts
110+
* const run = await client.beta.threads.runs.update(
111+
* 'thread_id',
112+
* 'run_id',
113+
* );
114+
* ```
91115
*/
92116
update(
93117
threadId: string,
@@ -104,6 +128,16 @@ export class Runs extends APIResource {
104128

105129
/**
106130
* Returns a list of runs belonging to a thread.
131+
*
132+
* @example
133+
* ```ts
134+
* // Automatically fetches more pages as needed.
135+
* for await (const run of client.beta.threads.runs.list(
136+
* 'thread_id',
137+
* )) {
138+
* // ...
139+
* }
140+
* ```
107141
*/
108142
list(
109143
threadId: string,
@@ -128,6 +162,14 @@ export class Runs extends APIResource {
128162

129163
/**
130164
* Cancels a run that is `in_progress`.
165+
*
166+
* @example
167+
* ```ts
168+
* const run = await client.beta.threads.runs.cancel(
169+
* 'thread_id',
170+
* 'run_id',
171+
* );
172+
* ```
131173
*/
132174
cancel(threadId: string, runId: string, options?: Core.RequestOptions): Core.APIPromise<Run> {
133175
return this._client.post(`/threads/${threadId}/runs/${runId}/cancel`, {
@@ -229,6 +271,16 @@ export class Runs extends APIResource {
229271
* `submit_tool_outputs`, this endpoint can be used to submit the outputs from the
230272
* tool calls once they're all completed. All outputs must be submitted in a single
231273
* request.
274+
*
275+
* @example
276+
* ```ts
277+
* const run =
278+
* await client.beta.threads.runs.submitToolOutputs(
279+
* 'thread_id',
280+
* 'run_id',
281+
* { tool_outputs: [{}] },
282+
* );
283+
* ```
232284
*/
233285
submitToolOutputs(
234286
threadId: string,

src/resources/beta/threads/runs/steps.ts

+21
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import { CursorPage, type CursorPageParams } from '../../../../pagination';
1010
export class Steps extends APIResource {
1111
/**
1212
* Retrieves a run step.
13+
*
14+
* @example
15+
* ```ts
16+
* const runStep =
17+
* await client.beta.threads.runs.steps.retrieve(
18+
* 'thread_id',
19+
* 'run_id',
20+
* 'step_id',
21+
* );
22+
* ```
1323
*/
1424
retrieve(
1525
threadId: string,
@@ -43,6 +53,17 @@ export class Steps extends APIResource {
4353

4454
/**
4555
* Returns a list of run steps belonging to a run.
56+
*
57+
* @example
58+
* ```ts
59+
* // Automatically fetches more pages as needed.
60+
* for await (const runStep of client.beta.threads.runs.steps.list(
61+
* 'thread_id',
62+
* 'run_id',
63+
* )) {
64+
* // ...
65+
* }
66+
* ```
4667
*/
4768
list(
4869
threadId: string,

0 commit comments

Comments
 (0)