TestChatSendsStreamIncludeUsage: servers emit the usage block only when `stream_options.include_usage:true` is in the request; without it the per-turn token counter sits at 0. Every Chat call must ship the flag.
(t *testing.T)
| 344 | // `stream_options.include_usage:true` is in the request; without it the per-turn |
| 345 | // token counter sits at 0. Every Chat call must ship the flag. |
| 346 | func TestChatSendsStreamIncludeUsage(t *testing.T) { |
| 347 | var gotBody string |
| 348 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 349 | b, _ := io.ReadAll(r.Body) |
| 350 | gotBody = string(b) |
| 351 | sseOK(w, []string{`{"choices":[{"delta":{"content":"ok"}}]}`}) |
| 352 | })) |
| 353 | defer srv.Close() |
| 354 | collect(New(srv.URL, "m", "").Chat(context.Background(), nil, nil)) |
| 355 | if !strings.Contains(gotBody, `"stream_options":{"include_usage":true}`) { |
| 356 | t.Fatalf("stream_options.include_usage missing from body: %s", gotBody) |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | // TestChatMidStreamErrorFrameSurfacesAsError: OpenAI-compatible backends (and |
| 361 | // OpenRouter-style proxies like the hosted endpoint) report a post-200 |