Skip to content

Commit 43b6ff6

Browse files
authored
feat(api): add model and token category to organization costs (#4365)
## Summary Adds billed model and token category details to organization cost line items. ## Changes - Read the billed model and token category when they are available. Co-authored-by: dpiet-oai <326640584+dpiet-oai@users.noreply.github.com>
1 parent 089541c commit 43b6ff6

6 files changed

Lines changed: 377 additions & 10 deletions

File tree

‎.castiron.stats.yml‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
schema_version: 1
2-
generation_id: 8b821b6c-0836-44bb-a4a9-6f62fdac616e
3-
openapi_spec_hash: 6bb5b5586f1ffada85bccfd43170bfa3
4-
openapi_transformed_spec_hash: e15abdc5dfeb4d1b3bc07bf2ba10de1e
5-
config_hash: eb083898f75b3c78d03e3c6d075e53d8
6-
codegen_sha: 3d9c87a0ececa02d59d3755babfce9993e3c0a11
7-
codegen_hash: 1bd1db260d1cf8172d9ef9d6dc02eb205973e3d245b8126f8a30b1ce91f56abe
2+
generation_id: b0f1a2bb-5d48-43d4-a0b8-f050b37cbbd9
3+
openapi_spec_hash: a1dc66efb759a0dc5b3b20904545890f
4+
openapi_transformed_spec_hash: 8e506c394d2f27f9329518058d5aa3b9
5+
config_hash: fb6bc01fab5ad1159ebbfcd9580b679d
6+
codegen_sha: 4a0c1dcef5111e4fdbec4bdbaf957055ec903856
7+
codegen_hash: fb2cfdf4eba8a2a31de14717d791ea94c01a844969ef43a116c576713d8ace9d

‎api.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,11 +1360,11 @@ Types:
13601360
```python
13611361
from openai.types.admin.organization import (
13621362
CostQuantityUnit,
1363+
UsageCostsResponse,
13631364
UsageAudioSpeechesResponse,
13641365
UsageAudioTranscriptionsResponse,
13651366
UsageCodeInterpreterSessionsResponse,
13661367
UsageCompletionsResponse,
1367-
UsageCostsResponse,
13681368
UsageDecisionsResponse,
13691369
UsageEmbeddingsResponse,
13701370
UsageFileSearchCallsResponse,

‎api_reference/openapi.transformed.yml‎

Lines changed: 294 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11178,7 +11178,7 @@ paths:
1117811178
content:
1117911179
application/json:
1118011180
schema:
11181-
$ref: '#/components/schemas/UsageResponse'
11181+
$ref: '#/components/schemas/CostsResponseWithDimensions'
1118211182
'400':
1118311183
description: The request parameters are invalid or the requested operation cannot be performed.
1118411184
content:
@@ -11196,6 +11196,7 @@ paths:
1119611196
x-oaiMeta:
1119711197
group: usage-costs
1119811198
examples:
11199+
- title: Total costs
1119911200
request:
1120011201
curl: |
1120111202
curl "https://api.openai.com/v1/organization/costs?start_time=1730419200&limit=1" \
@@ -11217,6 +11218,8 @@ paths:
1121711218
"currency": "usd"
1121811219
},
1121911220
"line_item": null,
11221+
"model": null,
11222+
"token_type": null,
1122011223
"project_id": null,
1122111224
"api_key_id": null,
1122211225
"quantity": null,
@@ -11228,6 +11231,41 @@ paths:
1122811231
"has_more": false,
1122911232
"next_page": null
1123011233
}
11234+
- title: Costs by line item
11235+
request:
11236+
curl: |
11237+
curl "https://api.openai.com/v1/organization/costs?start_time=1730419200&limit=1&group_by=line_item" \
11238+
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
11239+
-H "Content-Type: application/json"
11240+
response: |
11241+
{
11242+
"object": "page",
11243+
"data": [
11244+
{
11245+
"object": "bucket",
11246+
"start_time": 1730419200,
11247+
"end_time": 1730505600,
11248+
"results": [
11249+
{
11250+
"object": "organization.costs.result",
11251+
"amount": {
11252+
"value": 0.06,
11253+
"currency": "usd"
11254+
},
11255+
"line_item": "gpt-6.2-astra, input_tokens",
11256+
"model": "gpt-6.2-astra",
11257+
"token_type": "input",
11258+
"project_id": null,
11259+
"api_key_id": null,
11260+
"quantity": 10000,
11261+
"quantity_unit": "tokens"
11262+
}
11263+
]
11264+
}
11265+
],
11266+
"has_more": false,
11267+
"next_page": null
11268+
}
1123111269
/organization/data_retention:
1123211270
get:
1123311271
security:
@@ -115267,6 +115305,261 @@ components:
115267115305
- $ref: '#/components/schemas/CreateSpendLimitParams'
115268115306
description: The monthly hard spend limit for the initial API key. You cannot set a spend limit when `create_service_account_only` is `true`.
115269115307
- type: 'null'
115308+
OrganizationCostAmountModel:
115309+
properties:
115310+
value:
115311+
type: number
115312+
currency:
115313+
type: string
115314+
type: object
115315+
required:
115316+
- value
115317+
- currency
115318+
OrganizationCostQuantityUnit:
115319+
anyOf:
115320+
- type: string
115321+
- type: string
115322+
enum:
115323+
- tokens
115324+
- 1000_tokens
115325+
- duration_seconds
115326+
- duration_minutes
115327+
- duration_hours
115328+
- gibibyte_hours
115329+
- images
115330+
- characters
115331+
PublicOrganizationCostBucketModel:
115332+
properties:
115333+
object:
115334+
type: string
115335+
enum:
115336+
- bucket
115337+
default: bucket
115338+
x-stainless-const: true
115339+
start_time:
115340+
type: integer
115341+
end_time:
115342+
type: integer
115343+
results:
115344+
items:
115345+
$ref: '#/components/schemas/PublicOrganizationCostResultModel'
115346+
type: array
115347+
type: object
115348+
required:
115349+
- object
115350+
- start_time
115351+
- end_time
115352+
- results
115353+
PublicOrganizationCostResultModel:
115354+
properties:
115355+
api_source:
115356+
anyOf:
115357+
- type: string
115358+
description: API source (agents_api or unlabeled) when grouped by api_source; otherwise null. Unlabeled includes records without published source attribution.
115359+
- type: 'null'
115360+
object:
115361+
type: string
115362+
enum:
115363+
- organization.costs.result
115364+
default: organization.costs.result
115365+
x-stainless-const: true
115366+
amount:
115367+
$ref: '#/components/schemas/OrganizationCostAmountModel'
115368+
line_item:
115369+
anyOf:
115370+
- type: string
115371+
- type: 'null'
115372+
model:
115373+
anyOf:
115374+
- type: string
115375+
description: The model associated with the billed product, including purchased capacity. This may differ from the model ID used in a request, including fine-tuned model IDs. Null when line_item is null or a model association is unavailable or not applicable.
115376+
- type: 'null'
115377+
token_type:
115378+
anyOf:
115379+
- type: string
115380+
description: 'The billed token category: `input`, `output`, `input_cached`, `input_cache_write_30m`, `input_cache_write_12h`, or `total`. For inference charges, `input` excludes separately billed cache reads and writes. For Scale Tier purchases, these categories describe purchased capacity. Null when line_item is null or when the category is unknown or inapplicable. Additional values may be introduced in the future.'
115381+
- type: 'null'
115382+
project_id:
115383+
anyOf:
115384+
- type: string
115385+
- type: 'null'
115386+
user_id:
115387+
anyOf:
115388+
- type: string
115389+
- type: 'null'
115390+
api_key_id:
115391+
anyOf:
115392+
- type: string
115393+
- type: 'null'
115394+
quantity:
115395+
anyOf:
115396+
- type: number
115397+
- type: 'null'
115398+
quantity_unit:
115399+
anyOf:
115400+
- $ref: '#/components/schemas/OrganizationCostQuantityUnit'
115401+
- type: 'null'
115402+
type: object
115403+
required:
115404+
- object
115405+
- amount
115406+
- line_item
115407+
- project_id
115408+
PublicOrganizationCostsResource:
115409+
properties:
115410+
object:
115411+
type: string
115412+
enum:
115413+
- page
115414+
default: page
115415+
x-stainless-const: true
115416+
data:
115417+
items:
115418+
$ref: '#/components/schemas/PublicOrganizationCostBucketModel'
115419+
type: array
115420+
has_more:
115421+
type: boolean
115422+
next_page:
115423+
anyOf:
115424+
- type: string
115425+
- type: 'null'
115426+
type: object
115427+
required:
115428+
- object
115429+
- data
115430+
- has_more
115431+
- next_page
115432+
CostsResultWithDimensions:
115433+
type: object
115434+
description: The aggregated costs details of the specific time bucket.
115435+
properties:
115436+
api_source:
115437+
description: When grouped by `api_source`, `agents_api` identifies attributed Agents API activity and `unlabeled` includes all records without published source attribution, including historical and unknown origins. Unlabeled does not imply direct API usage. Without source grouping, this field is null.
115438+
anyOf:
115439+
- type: string
115440+
enum:
115441+
- agents_api
115442+
- unlabeled
115443+
- type: 'null'
115444+
object:
115445+
type: string
115446+
const: organization.costs.result
115447+
amount:
115448+
type: object
115449+
description: The monetary value in its associated currency.
115450+
properties:
115451+
value:
115452+
type: number
115453+
description: The numeric value of the cost.
115454+
currency:
115455+
type: string
115456+
description: Lowercase ISO-4217 currency e.g. "usd"
115457+
line_item:
115458+
anyOf:
115459+
- type: string
115460+
description: When `group_by=line_item`, this field provides the line item of the grouped costs result.
115461+
- type: 'null'
115462+
project_id:
115463+
anyOf:
115464+
- type: string
115465+
description: When `group_by=project_id`, this field provides the project ID of the grouped costs result.
115466+
- type: 'null'
115467+
user_id:
115468+
anyOf:
115469+
- type: string
115470+
description: When `group_by=user_id`, this field provides the user ID of the grouped costs result.
115471+
- type: 'null'
115472+
api_key_id:
115473+
anyOf:
115474+
- type: string
115475+
description: When `group_by=api_key_id`, this field provides the API Key ID of the grouped costs result.
115476+
- type: 'null'
115477+
quantity:
115478+
anyOf:
115479+
- type: number
115480+
description: When `group_by=line_item`, this field provides the quantity of the grouped costs result.
115481+
- type: 'null'
115482+
quantity_unit:
115483+
$ref: '#/components/schemas/CostsResult/properties/quantity_unit'
115484+
model:
115485+
anyOf:
115486+
- type: string
115487+
description: The model associated with the billed product, including purchased capacity. This may differ from the model ID used in a request, including fine-tuned model IDs. Null when line_item is null or a model association is unavailable or not applicable.
115488+
- type: 'null'
115489+
token_type:
115490+
anyOf:
115491+
- type: string
115492+
description: 'The billed token category: `input`, `output`, `input_cached`, `input_cache_write_30m`, `input_cache_write_12h`, or `total`. For inference charges, `input` excludes separately billed cache reads and writes. For Scale Tier purchases, these categories describe purchased capacity. Null when line_item is null or when the category is unknown or inapplicable. Additional values may be introduced in the future.'
115493+
- type: 'null'
115494+
required:
115495+
- object
115496+
x-oaiMeta:
115497+
name: Costs object
115498+
example: |
115499+
{
115500+
"object": "organization.costs.result",
115501+
"amount": {
115502+
"value": 0.06,
115503+
"currency": "usd"
115504+
},
115505+
"line_item": "gpt-6.2-astra, input_tokens",
115506+
"project_id": "proj_abc",
115507+
"quantity": 10000,
115508+
"quantity_unit": "tokens"
115509+
}
115510+
CostsTimeBucketWithDimensions:
115511+
type: object
115512+
properties:
115513+
object:
115514+
type: string
115515+
const: bucket
115516+
start_time:
115517+
type: integer
115518+
end_time:
115519+
type: integer
115520+
results:
115521+
type: array
115522+
items:
115523+
discriminator:
115524+
propertyName: object
115525+
anyOf:
115526+
- $ref: '#/components/schemas/UsageCompletionsResult'
115527+
- $ref: '#/components/schemas/UsageEmbeddingsResult'
115528+
- $ref: '#/components/schemas/UsageModerationsResult'
115529+
- $ref: '#/components/schemas/UsageImagesResult'
115530+
- $ref: '#/components/schemas/UsageAudioSpeechesResult'
115531+
- $ref: '#/components/schemas/UsageAudioTranscriptionsResult'
115532+
- $ref: '#/components/schemas/UsageVectorStoresResult'
115533+
- $ref: '#/components/schemas/UsageCodeInterpreterSessionsResult'
115534+
- $ref: '#/components/schemas/UsageFileSearchCallsResult'
115535+
- $ref: '#/components/schemas/UsageWebSearchCallsResult'
115536+
- $ref: '#/components/schemas/CostsResultWithDimensions'
115537+
required:
115538+
- object
115539+
- start_time
115540+
- end_time
115541+
- results
115542+
CostsResponseWithDimensions:
115543+
type: object
115544+
properties:
115545+
object:
115546+
type: string
115547+
const: page
115548+
data:
115549+
type: array
115550+
items:
115551+
$ref: '#/components/schemas/CostsTimeBucketWithDimensions'
115552+
has_more:
115553+
type: boolean
115554+
next_page:
115555+
anyOf:
115556+
- type: string
115557+
- type: 'null'
115558+
required:
115559+
- object
115560+
- data
115561+
- has_more
115562+
- next_page
115270115563
DecisionPromptCacheBreakpoint:
115271115564
type: object
115272115565
properties:

‎scripts/castiron/generated-files.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": {
44
"api.md": {
55
"mode": "100644",
6-
"sha256": "b39761d9a28a009e155bca1d2ffe6f2692f56e297101edbb85c1df52dbc0066b"
6+
"sha256": "4afd58ab9dca50c1a2ca5543cc8d53cbd6268b72be57264f2b838eb3440d5792"
77
},
88
"src/openai/__init__.py": {
99
"mode": "100644",
@@ -1451,7 +1451,7 @@
14511451
},
14521452
"src/openai/types/admin/organization/usage_costs_response.py": {
14531453
"mode": "100644",
1454-
"sha256": "18db984905da2334fde6b0edb2ae04f65b7d4ffe4bb58759f1123ce5bb0f16ff"
1454+
"sha256": "291441b12df73417c2c1a385c8e2492c801f3760f0bcc75338de721bdeb3552d"
14551455
},
14561456
"src/openai/types/admin/organization/usage_decisions_params.py": {
14571457
"mode": "100644",

0 commit comments

Comments
 (0)