Skip to content

Commit 55fc500

Browse files
feat(api): add response tool usage models (#4201)
## Summary Adds optional hosted tool usage to stable and beta Responses, separately from model token usage. ## Changes - Read image tool token totals and input/output details from response tool usage. - Read billable web-search request counts and optional cached image/text token details. - Existing response fields and omission behavior remain unchanged.
1 parent 77fd116 commit 55fc500

5 files changed

Lines changed: 391 additions & 7 deletions

File tree

‎.castiron.stats.yml‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version: 1
2-
generation_id: 45c2be6c-9b78-4bff-b88b-f437435ae397
3-
openapi_spec_hash: 7b8e0964b34b0cf993d2e2946e8eac7a
4-
openapi_transformed_spec_hash: 096782182a5f2b2d0d09fb4822e35e10
2+
generation_id: c181b60a-9c3f-4fab-adb0-ec99e1b9164b
3+
openapi_spec_hash: d86a987b0943f67209611629cfe2926f
4+
openapi_transformed_spec_hash: f98b6939664e5171dadad31a12ecf50a
55
config_hash: 0e042fd083471fc089bcbfe7011a7d01
6-
codegen_sha: 2d3d72e9eb4ebaca41912b7d0ce1bc8733a90569
7-
codegen_hash: fec5e33e84cf8605506e7b95a1dd30735e4cffe16ec560150a65b669d4975ebd
6+
codegen_sha: e7d3eec72178efe4bd1c41d2923c5636e5f41500
7+
codegen_hash: 5808ff69b455e321be73db3a9c2640505dddd64b0418583f71301147baa3171d

‎api_reference/openapi.transformed.yml‎

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64187,6 +64187,21 @@ components:
6418764187
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and [reasoning tokens](https://developers.openai.com/api/docs/guides/reasoning).
6418864188
type: integer
6418964189
- type: 'null'
64190+
tool_usage:
64191+
$ref: '#/components/schemas/ResponseToolUsage'
64192+
description: |
64193+
Usage reported by hosted tools, separate from base model `usage`. The field
64194+
can be omitted when tool usage is unavailable. When present, tool families
64195+
with no recorded usage have zero counts.
64196+
64197+
`image_gen` sums available token counts across image generation calls.
64198+
Calls with missing or incomplete usage records may be skipped. Output
64199+
token details and cached input counts can be omitted. An omitted cache
64200+
count means cache usage is unknown.
64201+
64202+
`web_search.num_requests` counts billable searches. Discounted searches
64203+
and actions such as opening a page are excluded. Use billing records to
64204+
reconcile final charges.
6419064205
required:
6419164206
- access_programs
6419264207
- id
@@ -105084,6 +105099,21 @@ components:
105084105099
An upper bound for the number of tokens that can be generated for a response, including visible output tokens and [reasoning tokens](https://developers.openai.com/api/docs/guides/reasoning).
105085105100
type: integer
105086105101
- type: 'null'
105102+
tool_usage:
105103+
$ref: '#/components/schemas/BetaResponseToolUsage'
105104+
description: |
105105+
Usage reported by hosted tools, separate from base model `usage`. The field
105106+
can be omitted when tool usage is unavailable. When present, tool families
105107+
with no recorded usage have zero counts.
105108+
105109+
`image_gen` sums available token counts across image generation calls.
105110+
Calls with missing or incomplete usage records may be skipped. Output
105111+
token details and cached input counts can be omitted. An omitted cache
105112+
count means cache usage is unknown.
105113+
105114+
`web_search.num_requests` counts billable searches. Discounted searches
105115+
and actions such as opening a page are excluded. Use billing records to
105116+
reconcile final charges.
105087105117
required:
105088105118
- access_programs
105089105119
- id
@@ -110498,6 +110528,156 @@ components:
110498110528
- $ref: '#/components/schemas/BetaResponseCustomToolCallInputDoneEvent'
110499110529
discriminator:
110500110530
propertyName: type
110531+
BetaCachedUsageDetails:
110532+
properties:
110533+
cached_text_tokens:
110534+
type: integer
110535+
cached_image_tokens:
110536+
type: integer
110537+
type: object
110538+
required:
110539+
- cached_text_tokens
110540+
- cached_image_tokens
110541+
BetaImageGenInputUsageDetails:
110542+
properties:
110543+
text_tokens:
110544+
type: integer
110545+
description: The number of text tokens in the input prompt.
110546+
image_tokens:
110547+
type: integer
110548+
description: The number of image tokens in the input prompt.
110549+
type: object
110550+
required:
110551+
- text_tokens
110552+
- image_tokens
110553+
title: Input usage details
110554+
description: The input tokens detailed information for the image generation.
110555+
BetaImageGenOutputTokensDetails:
110556+
properties:
110557+
image_tokens:
110558+
type: integer
110559+
description: The number of image output tokens generated by the model.
110560+
text_tokens:
110561+
type: integer
110562+
description: The number of text output tokens generated by the model.
110563+
type: object
110564+
required:
110565+
- image_tokens
110566+
- text_tokens
110567+
title: Image generation output token details
110568+
description: The output token details for the image generation.
110569+
BetaImageGenToolUsage:
110570+
properties:
110571+
input_tokens:
110572+
type: integer
110573+
description: The number of tokens (images and text) in the input prompt.
110574+
total_tokens:
110575+
type: integer
110576+
description: The total number of tokens (images and text) used for the image generation.
110577+
output_tokens:
110578+
type: integer
110579+
description: The number of output tokens generated by the model.
110580+
output_tokens_details:
110581+
$ref: '#/components/schemas/BetaImageGenOutputTokensDetails'
110582+
input_tokens_details:
110583+
$ref: '#/components/schemas/BetaImageGenInputUsageDetails'
110584+
cached_tokens:
110585+
type: integer
110586+
cached_tokens_details:
110587+
$ref: '#/components/schemas/BetaCachedUsageDetails'
110588+
type: object
110589+
required:
110590+
- input_tokens
110591+
- total_tokens
110592+
- output_tokens
110593+
- input_tokens_details
110594+
title: Image generation tool usage
110595+
description: Token usage for image generation tool calls in a response.
110596+
BetaResponseToolUsage:
110597+
properties:
110598+
image_gen:
110599+
$ref: '#/components/schemas/BetaImageGenToolUsage'
110600+
description: Aggregated usage statistics for image generation tool calls.
110601+
web_search:
110602+
$ref: '#/components/schemas/BetaWebSearchUsage'
110603+
description: Aggregated billable usage statistics for web search tool calls.
110604+
type: object
110605+
required:
110606+
- image_gen
110607+
- web_search
110608+
title: Response tool usage
110609+
description: Aggregated usage details for billable tools that ran while generating the response.
110610+
BetaWebSearchUsage:
110611+
properties:
110612+
num_requests:
110613+
type: integer
110614+
description: The number of billable web search requests issued.
110615+
type: object
110616+
required:
110617+
- num_requests
110618+
title: Web search usage
110619+
description: Usage details for web search requests that ran while generating the response.
110620+
CachedUsageDetails:
110621+
properties:
110622+
cached_text_tokens:
110623+
type: integer
110624+
cached_image_tokens:
110625+
type: integer
110626+
type: object
110627+
required:
110628+
- cached_text_tokens
110629+
- cached_image_tokens
110630+
ImageGenToolUsage:
110631+
properties:
110632+
input_tokens:
110633+
type: integer
110634+
description: The number of tokens (images and text) in the input prompt.
110635+
total_tokens:
110636+
type: integer
110637+
description: The total number of tokens (images and text) used for the image generation.
110638+
output_tokens:
110639+
type: integer
110640+
description: The number of output tokens generated by the model.
110641+
output_tokens_details:
110642+
$ref: '#/components/schemas/ImageGenOutputTokensDetails'
110643+
input_tokens_details:
110644+
$ref: '#/components/schemas/ImageGenInputUsageDetails'
110645+
cached_tokens:
110646+
type: integer
110647+
cached_tokens_details:
110648+
$ref: '#/components/schemas/CachedUsageDetails'
110649+
type: object
110650+
required:
110651+
- input_tokens
110652+
- total_tokens
110653+
- output_tokens
110654+
- input_tokens_details
110655+
title: Image generation tool usage
110656+
description: Token usage for image generation tool calls in a response.
110657+
ResponseToolUsage:
110658+
properties:
110659+
image_gen:
110660+
$ref: '#/components/schemas/ImageGenToolUsage'
110661+
description: Aggregated usage statistics for image generation tool calls.
110662+
web_search:
110663+
$ref: '#/components/schemas/WebSearchUsage'
110664+
description: Aggregated billable usage statistics for web search tool calls.
110665+
type: object
110666+
required:
110667+
- image_gen
110668+
- web_search
110669+
title: Response tool usage
110670+
description: Aggregated usage details for billable tools that ran while generating the response.
110671+
WebSearchUsage:
110672+
properties:
110673+
num_requests:
110674+
type: integer
110675+
description: The number of billable web search requests issued.
110676+
type: object
110677+
required:
110678+
- num_requests
110679+
title: Web search usage
110680+
description: Usage details for web search requests that ran while generating the response.
110501110681
SessionSpendControlResource:
110502110682
type: object
110503110683
properties:

‎scripts/castiron/generated-files.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,7 +2407,7 @@
24072407
},
24082408
"src/openai/types/beta/beta_response.py": {
24092409
"mode": "100644",
2410-
"sha256": "51b540b82d5eabd7aad037a89094abaa9e5ec4d3d4c2aa5226a69ee2dd62311d"
2410+
"sha256": "f9f8e9f29fc43a743592cd89636dfbe967fe189d47914e8c847a2a396d9af45c"
24112411
},
24122412
"src/openai/types/beta/beta_response_apply_patch_tool_call.py": {
24132413
"mode": "100644",
@@ -6047,7 +6047,7 @@
60476047
},
60486048
"src/openai/types/responses/response.py": {
60496049
"mode": "100644",
6050-
"sha256": "fad55bfc5e659ed5ab1bc04c85628c5ba09ac59180e21bdad7620abfc955cc14"
6050+
"sha256": "b7f94706e91b9e0c7e857b74c0ea2430ec4f3a8f645833e9490d33d57f6b8ee0"
60516051
},
60526052
"src/openai/types/responses/response_apply_patch_tool_call.py": {
60536053
"mode": "100644",

‎src/openai/types/beta/beta_response.py‎

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
"PromptCacheDiagnosticsUnavailable",
4545
"PromptCacheOptions",
4646
"Reasoning",
47+
"ToolUsage",
48+
"ToolUsageImageGen",
49+
"ToolUsageImageGenInputTokensDetails",
50+
"ToolUsageImageGenCachedTokensDetails",
51+
"ToolUsageImageGenOutputTokensDetails",
52+
"ToolUsageWebSearch",
4753
]
4854

4955

@@ -313,6 +319,86 @@ class Reasoning(BaseModel):
313319
"""
314320

315321

322+
class ToolUsageImageGenInputTokensDetails(BaseModel):
323+
"""The input tokens detailed information for the image generation."""
324+
325+
image_tokens: int
326+
"""The number of image tokens in the input prompt."""
327+
328+
text_tokens: int
329+
"""The number of text tokens in the input prompt."""
330+
331+
332+
class ToolUsageImageGenCachedTokensDetails(BaseModel):
333+
cached_image_tokens: int
334+
335+
cached_text_tokens: int
336+
337+
338+
class ToolUsageImageGenOutputTokensDetails(BaseModel):
339+
"""The output token details for the image generation."""
340+
341+
image_tokens: int
342+
"""The number of image output tokens generated by the model."""
343+
344+
text_tokens: int
345+
"""The number of text output tokens generated by the model."""
346+
347+
348+
class ToolUsageImageGen(BaseModel):
349+
"""Aggregated usage statistics for image generation tool calls."""
350+
351+
input_tokens: int
352+
"""The number of tokens (images and text) in the input prompt."""
353+
354+
input_tokens_details: ToolUsageImageGenInputTokensDetails
355+
"""The input tokens detailed information for the image generation."""
356+
357+
output_tokens: int
358+
"""The number of output tokens generated by the model."""
359+
360+
total_tokens: int
361+
"""The total number of tokens (images and text) used for the image generation."""
362+
363+
cached_tokens: Optional[int] = None
364+
365+
cached_tokens_details: Optional[ToolUsageImageGenCachedTokensDetails] = None
366+
367+
output_tokens_details: Optional[ToolUsageImageGenOutputTokensDetails] = None
368+
"""The output token details for the image generation."""
369+
370+
371+
class ToolUsageWebSearch(BaseModel):
372+
"""Aggregated billable usage statistics for web search tool calls."""
373+
374+
num_requests: int
375+
"""The number of billable web search requests issued."""
376+
377+
378+
class ToolUsage(BaseModel):
379+
"""Usage reported by hosted tools, separate from base model `usage`.
380+
381+
The field
382+
can be omitted when tool usage is unavailable. When present, tool families
383+
with no recorded usage have zero counts.
384+
385+
`image_gen` sums available token counts across image generation calls.
386+
Calls with missing or incomplete usage records may be skipped. Output
387+
token details and cached input counts can be omitted. An omitted cache
388+
count means cache usage is unknown.
389+
390+
`web_search.num_requests` counts billable searches. Discounted searches
391+
and actions such as opening a page are excluded. Use billing records to
392+
reconcile final charges.
393+
"""
394+
395+
image_gen: ToolUsageImageGen
396+
"""Aggregated usage statistics for image generation tool calls."""
397+
398+
web_search: ToolUsageWebSearch
399+
"""Aggregated billable usage statistics for web search tool calls."""
400+
401+
316402
class BetaResponse(BaseModel):
317403
id: str
318404
"""Unique identifier for this Response."""
@@ -761,6 +847,22 @@ class BetaResponse(BaseModel):
761847
- [Structured Outputs](https://developers.openai.com/api/docs/guides/structured-outputs)
762848
"""
763849

850+
tool_usage: Optional[ToolUsage] = None
851+
"""Usage reported by hosted tools, separate from base model `usage`.
852+
853+
The field can be omitted when tool usage is unavailable. When present, tool
854+
families with no recorded usage have zero counts.
855+
856+
`image_gen` sums available token counts across image generation calls. Calls
857+
with missing or incomplete usage records may be skipped. Output token details
858+
and cached input counts can be omitted. An omitted cache count means cache usage
859+
is unknown.
860+
861+
`web_search.num_requests` counts billable searches. Discounted searches and
862+
actions such as opening a page are excluded. Use billing records to reconcile
863+
final charges.
864+
"""
865+
764866
top_logprobs: Optional[int] = None
765867
"""
766868
An integer between 0 and 20 specifying the maximum number of most likely tokens

0 commit comments

Comments
 (0)