@@ -38,12 +38,23 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
3838 expectModel string
3939 expectPromptRecorded string
4040 expectToolRecorded * recorder.ToolUsageRecord
41+ expectTokenUsage * recorder.TokenUsageRecord
4142 }{
4243 {
4344 name : "blocking_simple" ,
4445 fixture : fixtures .OaiResponsesBlockingSimple ,
4546 expectModel : "gpt-4o-mini" ,
4647 expectPromptRecorded : "tell me a joke" ,
48+ expectTokenUsage : & recorder.TokenUsageRecord {
49+ MsgID : "resp_0388c79043df3e3400695f9f83cd6481959062cec6830d8d51" ,
50+ Input : 11 ,
51+ Output : 18 ,
52+ ExtraTokenTypes : map [string ]int64 {
53+ "input_cached" : 0 ,
54+ "output_reasoning" : 0 ,
55+ "total_tokens" : 29 ,
56+ },
57+ },
4758 },
4859 {
4960 name : "blocking_builtin_tool" ,
@@ -56,6 +67,32 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
5667 Args : map [string ]any {"a" : float64 (3 ), "b" : float64 (5 )},
5768 Injected : false ,
5869 },
70+ expectTokenUsage : & recorder.TokenUsageRecord {
71+ MsgID : "resp_0da6045a8b68fa5200695fa23dcc2c81a19c849f627abf8a31" ,
72+ Input : 58 ,
73+ Output : 18 ,
74+ ExtraTokenTypes : map [string ]int64 {
75+ "input_cached" : 0 ,
76+ "output_reasoning" : 0 ,
77+ "total_tokens" : 76 ,
78+ },
79+ },
80+ },
81+ {
82+ name : "blocking_cached_input_tokens" ,
83+ fixture : fixtures .OaiResponsesBlockingCachedInputTokens ,
84+ expectModel : "gpt-4.1" ,
85+ expectPromptRecorded : "This was a large input..." ,
86+ expectTokenUsage : & recorder.TokenUsageRecord {
87+ MsgID : "resp_0cd5d6b8310055d600696a1776b42c81a199fbb02248a8bfa0" ,
88+ Input : 129 , // 12033 input - 11904 cached
89+ Output : 44 ,
90+ ExtraTokenTypes : map [string ]int64 {
91+ "input_cached" : 11904 ,
92+ "output_reasoning" : 0 ,
93+ "total_tokens" : 12077 ,
94+ },
95+ },
5996 },
6097 {
6198 name : "blocking_custom_tool" ,
@@ -68,18 +105,48 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
68105 Args : "print(\" hello world\" )" ,
69106 Injected : false ,
70107 },
108+ expectTokenUsage : & recorder.TokenUsageRecord {
109+ MsgID : "resp_09c614364030cdf000696942589da081a0af07f5859acb7308" ,
110+ Input : 64 ,
111+ Output : 148 ,
112+ ExtraTokenTypes : map [string ]int64 {
113+ "input_cached" : 0 ,
114+ "output_reasoning" : 128 ,
115+ "total_tokens" : 212 ,
116+ },
117+ },
71118 },
72119 {
73120 name : "blocking_conversation" ,
74121 fixture : fixtures .OaiResponsesBlockingConversation ,
75122 expectModel : "gpt-4o-mini" ,
76123 expectPromptRecorded : "explain why this is funny." ,
124+ expectTokenUsage : & recorder.TokenUsageRecord {
125+ MsgID : "resp_0c9f1f0524a858fa00695fa15fc5a081958f4304aafd3bdec2" ,
126+ Input : 48 ,
127+ Output : 116 ,
128+ ExtraTokenTypes : map [string ]int64 {
129+ "input_cached" : 0 ,
130+ "output_reasoning" : 0 ,
131+ "total_tokens" : 164 ,
132+ },
133+ },
77134 },
78135 {
79136 name : "blocking_prev_response_id" ,
80137 fixture : fixtures .OaiResponsesBlockingPrevResponseID ,
81138 expectModel : "gpt-4o-mini" ,
82139 expectPromptRecorded : "explain why this is funny." ,
140+ expectTokenUsage : & recorder.TokenUsageRecord {
141+ MsgID : "resp_0388c79043df3e3400695f9f86cfa08195af1f015c60117a83" ,
142+ Input : 43 ,
143+ Output : 129 ,
144+ ExtraTokenTypes : map [string ]int64 {
145+ "input_cached" : 0 ,
146+ "output_reasoning" : 0 ,
147+ "total_tokens" : 172 ,
148+ },
149+ },
83150 },
84151 {
85152 name : "streaming_simple" ,
@@ -226,6 +293,16 @@ func TestResponsesOutputMatchesUpstream(t *testing.T) {
226293 } else {
227294 require .Empty (t , recordedTools )
228295 }
296+
297+ recordedTokens := mockRecorder .RecordedTokenUsages ()
298+ if tc .expectTokenUsage != nil {
299+ require .Len (t , recordedTokens , 1 )
300+ recordedTokens [0 ].InterceptionID = tc .expectTokenUsage .InterceptionID // ignore interception id
301+ recordedTokens [0 ].CreatedAt = tc .expectTokenUsage .CreatedAt // ignore time
302+ require .Equal (t , tc .expectTokenUsage , recordedTokens [0 ])
303+ } else {
304+ require .Empty (t , recordedTokens )
305+ }
229306 })
230307 }
231308}
0 commit comments