Skip to content

Commit 6c116df

Browse files
feat(api): add usage to runs and run steps (#1090)
1 parent 05cd753 commit 6c116df

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/openai/types/beta/threads/run.py

+19
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"ToolAssistantToolsCode",
1818
"ToolAssistantToolsRetrieval",
1919
"ToolAssistantToolsFunction",
20+
"Usage",
2021
]
2122

2223

@@ -61,6 +62,17 @@ class ToolAssistantToolsFunction(BaseModel):
6162
Tool = Union[ToolAssistantToolsCode, ToolAssistantToolsRetrieval, ToolAssistantToolsFunction]
6263

6364

65+
class Usage(BaseModel):
66+
completion_tokens: int
67+
"""Number of completion tokens used over the course of the run."""
68+
69+
prompt_tokens: int
70+
"""Number of prompt tokens used over the course of the run."""
71+
72+
total_tokens: int
73+
"""Total number of tokens used (prompt + completion)."""
74+
75+
6476
class Run(BaseModel):
6577
id: str
6678
"""The identifier, which can be referenced in API endpoints."""
@@ -152,3 +164,10 @@ class Run(BaseModel):
152164
[assistant](https://platform.openai.com/docs/api-reference/assistants) used for
153165
this run.
154166
"""
167+
168+
usage: Optional[Usage] = None
169+
"""Usage statistics related to the run.
170+
171+
This value will be `null` if the run is not in a terminal state (i.e.
172+
`in_progress`, `queued`, etc.).
173+
"""

src/openai/types/beta/threads/runs/run_step.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .tool_calls_step_details import ToolCallsStepDetails
99
from .message_creation_step_details import MessageCreationStepDetails
1010

11-
__all__ = ["RunStep", "LastError", "StepDetails"]
11+
__all__ = ["RunStep", "LastError", "StepDetails", "Usage"]
1212

1313

1414
class LastError(BaseModel):
@@ -22,6 +22,17 @@ class LastError(BaseModel):
2222
StepDetails = Union[MessageCreationStepDetails, ToolCallsStepDetails]
2323

2424

25+
class Usage(BaseModel):
26+
completion_tokens: int
27+
"""Number of completion tokens used over the course of the run step."""
28+
29+
prompt_tokens: int
30+
"""Number of prompt tokens used over the course of the run step."""
31+
32+
total_tokens: int
33+
"""Total number of tokens used (prompt + completion)."""
34+
35+
2536
class RunStep(BaseModel):
2637
id: str
2738
"""The identifier of the run step, which can be referenced in API endpoints."""
@@ -91,3 +102,9 @@ class RunStep(BaseModel):
91102

92103
type: Literal["message_creation", "tool_calls"]
93104
"""The type of run step, which can be either `message_creation` or `tool_calls`."""
105+
106+
usage: Optional[Usage] = None
107+
"""Usage statistics related to the run step.
108+
109+
This value will be `null` while the run step's status is `in_progress`.
110+
"""

0 commit comments

Comments
 (0)