Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3caa416

Browse files
authoredJan 20, 2024
feat(api): add usage to runs and run steps (#640)
1 parent c4f8a36 commit 3caa416

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
 

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

+27
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,12 @@ export interface Run {
264264
* this run.
265265
*/
266266
tools: Array<Run.AssistantToolsCode | Run.AssistantToolsRetrieval | Run.AssistantToolsFunction>;
267+
268+
/**
269+
* Usage statistics related to the run. This value will be `null` if the run is not
270+
* in a terminal state (i.e. `in_progress`, `queued`, etc.).
271+
*/
272+
usage: Run.Usage | null;
267273
}
268274

269275
export namespace Run {
@@ -332,6 +338,27 @@ export namespace Run {
332338
*/
333339
type: 'function';
334340
}
341+
342+
/**
343+
* Usage statistics related to the run. This value will be `null` if the run is not
344+
* in a terminal state (i.e. `in_progress`, `queued`, etc.).
345+
*/
346+
export interface Usage {
347+
/**
348+
* Number of completion tokens used over the course of the run.
349+
*/
350+
completion_tokens: number;
351+
352+
/**
353+
* Number of prompt tokens used over the course of the run.
354+
*/
355+
prompt_tokens: number;
356+
357+
/**
358+
* Total number of tokens used (prompt + completion).
359+
*/
360+
total_tokens: number;
361+
}
335362
}
336363

337364
export interface RunCreateParams {

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

+27
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ export interface RunStep {
300300
* The type of run step, which can be either `message_creation` or `tool_calls`.
301301
*/
302302
type: 'message_creation' | 'tool_calls';
303+
304+
/**
305+
* Usage statistics related to the run step. This value will be `null` while the
306+
* run step's status is `in_progress`.
307+
*/
308+
usage: RunStep.Usage | null;
303309
}
304310

305311
export namespace RunStep {
@@ -318,6 +324,27 @@ export namespace RunStep {
318324
*/
319325
message: string;
320326
}
327+
328+
/**
329+
* Usage statistics related to the run step. This value will be `null` while the
330+
* run step's status is `in_progress`.
331+
*/
332+
export interface Usage {
333+
/**
334+
* Number of completion tokens used over the course of the run step.
335+
*/
336+
completion_tokens: number;
337+
338+
/**
339+
* Number of prompt tokens used over the course of the run step.
340+
*/
341+
prompt_tokens: number;
342+
343+
/**
344+
* Total number of tokens used (prompt + completion).
345+
*/
346+
total_tokens: number;
347+
}
321348
}
322349

323350
/**

0 commit comments

Comments
 (0)
Please sign in to comment.