@@ -15,14 +15,16 @@ import (
1515 var probeModels = []string{"gpt-5.1", "claude-sonnet-4-6", "gemini-3-flash", "kimi-k2-thinking"}
1616
1717 type testResult struct {
18- Model string
19- Endpoint string
20- Success bool
21- Error string
22- Latency time.Duration
23- Request string
24- Response string
25- Stream bool
18+ Model string
19+ Endpoint string
20+ Success bool
21+ Error string
22+ Latency time.Duration
23+ Request string
24+ Response string
25+ Stream bool
26+ InputTokens int
27+ OutputTokens int
2628 }
2729
2830 func main() {
@@ -101,11 +103,11 @@ func testStreamParsed(ctx context.Context, client *zen.Client, modelID string) t
101103
102104 deltaCh, errCh, err := client.Stream(ctx, req)
103105 if err != nil {
104- return makeResult(modelID, endpoint, true, string(reqBody), "", err, time.Since(start))
106+ return makeResult(modelID, endpoint, true, string(reqBody), "", err, time.Since(start), 0, 0)
105107 }
106108
107109 var textBuf, reasoningBuf strings.Builder
108- var count int
110+ var count, inTok, outTok int
109111 for d := range deltaCh {
110112 count++
111113 switch d.Type {
@@ -113,14 +115,19 @@ func testStreamParsed(ctx context.Context, client *zen.Client, modelID string) t
113115 textBuf.WriteString(d.Content)
114116 case zen.DeltaReasoning:
115117 reasoningBuf.WriteString(d.Content)
118+ case zen.DeltaUsage:
119+ if d.InputTokens > inTok {
120+ inTok = d.InputTokens
121+ }
122+ outTok += d.OutputTokens
116123 }
117124 }
118125 if streamErr := <-errCh; streamErr != nil {
119- return makeResult(modelID, endpoint, true, string(reqBody), "", streamErr, time.Since(start))
126+ return makeResult(modelID, endpoint, true, string(reqBody), "", streamErr, time.Since(start), 0, 0)
120127 }
121128
122129 resp := fmt.Sprintf("deltas=%d text=%s reasoning=%s", count, truncate(textBuf.String(), 40), truncate(reasoningBuf.String(), 40))
123- return makeResult(modelID, endpoint, true, string(reqBody), resp, nil, time.Since(start))
130+ return makeResult(modelID, endpoint, true, string(reqBody), resp, nil, time.Since(start), inTok, outTok)
124131 }
125132
126133 // toolHistory returns a pre-built two-turn tool-use conversation:
@@ -159,23 +166,29 @@ func testToolHistoryStream(ctx context.Context, client *zen.Client, modelID stri
159166
160167 deltaCh, errCh, err := client.Stream(ctx, req)
161168 if err != nil {
162- return makeResult(modelID, endpoint, true, string(reqBody), "", err, time.Since(start))
169+ return makeResult(modelID, endpoint, true, string(reqBody), "", err, time.Since(start), 0, 0)
163170 }
164171
165172 var textBuf strings.Builder
166- var count int
173+ var count, inTok, outTok int
167174 for d := range deltaCh {
168175 count++
169- if d.Type == zen.DeltaText {
176+ switch d.Type {
177+ case zen.DeltaText:
170178 textBuf.WriteString(d.Content)
179+ case zen.DeltaUsage:
180+ if d.InputTokens > inTok {
181+ inTok = d.InputTokens
182+ }
183+ outTok += d.OutputTokens
171184 }
172185 }
173186 if streamErr := <-errCh; streamErr != nil {
174- return makeResult(modelID, endpoint, true, string(reqBody), "", streamErr, time.Since(start))
187+ return makeResult(modelID, endpoint, true, string(reqBody), "", streamErr, time.Since(start), 0, 0)
175188 }
176189
177190 resp := fmt.Sprintf("deltas=%d text=%s", count, truncate(textBuf.String(), 60))
178- return makeResult(modelID, endpoint, true, string(reqBody), resp, nil, time.Since(start))
191+ return makeResult(modelID, endpoint, true, string(reqBody), resp, nil, time.Since(start), inTok, outTok)
179192 }
180193
181194 func testReasoningStream(ctx context.Context, client *zen.Client, modelID string) testResult {
@@ -190,11 +203,11 @@ func testReasoningStream(ctx context.Context, client *zen.Client, modelID string
190203
191204 deltaCh, errCh, err := client.Stream(ctx, req)
192205 if err != nil {
193- return makeResult(modelID, endpoint, true, string(reqBody), "", err, time.Since(start))
206+ return makeResult(modelID, endpoint, true, string(reqBody), "", err, time.Since(start), 0, 0)
194207 }
195208
196209 var textBuf, reasoningBuf strings.Builder
197- var deltaCount int
210+ var deltaCount, inTok, outTok int
198211 for d := range deltaCh {
199212 deltaCount++
200213 switch d.Type {
@@ -202,30 +215,37 @@ func testReasoningStream(ctx context.Context, client *zen.Client, modelID string
202215 textBuf.WriteString(d.Content)
203216 case zen.DeltaReasoning:
204217 reasoningBuf.WriteString(d.Content)
218+ case zen.DeltaUsage:
219+ if d.InputTokens > inTok {
220+ inTok = d.InputTokens
221+ }
222+ outTok += d.OutputTokens
205223 }
206224 }
207225 if streamErr := <-errCh; streamErr != nil {
208- return makeResult(modelID, endpoint, true, string(reqBody), "", streamErr, time.Since(start))
226+ return makeResult(modelID, endpoint, true, string(reqBody), "", streamErr, time.Since(start), 0, 0)
209227 }
210228
211229 if reasoningBuf.Len() == 0 {
212230 return makeResult(modelID, endpoint, true, string(reqBody),
213231 fmt.Sprintf("deltas=%d text=%s", deltaCount, truncate(textBuf.String(), 60)),
214232 fmt.Errorf("model %s: stream contained no reasoning/thinking deltas", modelID),
215- time.Since(start))
233+ time.Since(start), inTok, outTok)
216234 }
217235 return makeResult(modelID, endpoint, true, string(reqBody),
218236 fmt.Sprintf("deltas=%d reasoning=%s text=%s",
219237 deltaCount,
220238 truncate(reasoningBuf.String(), 40),
221239 truncate(textBuf.String(), 40)),
222- nil, time.Since(start))
240+ nil, time.Since(start), inTok, outTok)
223241 }
224242
225243 // drainUnifiedStream consumes a UnifiedEvent channel and builds a testResult.
244+// StreamEvents operates at the raw event level and does not parse DeltaUsage,
245+// so token counts are not available here.
226246 func drainUnifiedStream(modelID, endpoint, reqBody string, eventCh <-chan zen.UnifiedEvent, errCh <-chan error, initErr error, start time.Time) testResult {
227247 if initErr != nil {
228- return makeResult(modelID, endpoint, true, reqBody, "", initErr, time.Since(start))
248+ return makeResult(modelID, endpoint, true, reqBody, "", initErr, time.Since(start), 0, 0)
229249 }
230250 var count int
231251 var last string
@@ -238,22 +258,24 @@ func drainUnifiedStream(modelID, endpoint, reqBody string, eventCh <-chan zen.Un
238258 }
239259 }
240260 if err := <-errCh; err != nil {
241- return makeResult(modelID, endpoint, true, reqBody, "", err, time.Since(start))
261+ return makeResult(modelID, endpoint, true, reqBody, "", err, time.Since(start), 0, 0)
242262 }
243263 if resolved != "" {
244264 endpoint = resolved
245265 }
246- return makeResult(modelID, endpoint, true, reqBody, fmt.Sprintf("events=%d last=%s", count, truncate(last, 80)), nil, time.Since(start))
266+ return makeResult(modelID, endpoint, true, reqBody, fmt.Sprintf("events=%d last=%s", count, truncate(last, 80)), nil, time.Since(start), 0, 0)
247267 }
248268
249-func makeResult(modelID, endpoint string, stream bool, req, resp string, err error, latency time.Duration) testResult {
269+func makeResult(modelID, endpoint string, stream bool, req, resp string, err error, latency time.Duration, inTok, outTok int) testResult {
250270 r := testResult{
251- Model: modelID,
252- Endpoint: endpoint,
253- Stream: stream,
254- Latency: latency,
255- Request: req,
256- Response: resp,
271+ Model: modelID,
272+ Endpoint: endpoint,
273+ Stream: stream,
274+ Latency: latency,
275+ Request: req,
276+ Response: resp,
277+ InputTokens: inTok,
278+ OutputTokens: outTok,
257279 }
258280 if err != nil {
259281 r.Error = err.Error()
@@ -286,7 +308,11 @@ func printResult(r testResult) {
286308 status = "✗"
287309 }
288310 mode := "stream"
289- fmt.Printf(" %s %-25s [%-15s] [%-10s] %v\n", status, r.Model, r.Endpoint, mode, r.Latency)
311+ usage := "-"
312+ if r.InputTokens > 0 || r.OutputTokens > 0 {
313+ usage = fmt.Sprintf("in=%d out=%d", r.InputTokens, r.OutputTokens)
314+ }
315+ fmt.Printf(" %s %-25s [%-15s] [%-10s] %-20s %v\n", status, r.Model, r.Endpoint, mode, usage, r.Latency)
290316 }
291317
292318 func truncate(s string, max int) string {