Skip to content

Studio: Show token usage and cache stats on connected provider chats - #11717

Merged
Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:provider-stream-usage
Sep 24, 2026
Merged

Lyxot merged 2 commits into
unslothai:mainfrom
NilayYadav:provider-stream-usage

Conversation

@NilayYadav

Copy link
Copy Markdown
Collaborator

When chatting with OpenAI, Anthropic, Gemini, OpenRouter or a custom provider, the token usage bar never showed up and cache stats were missing. Token counts were only rough guesses. Local model chats were fine.

The chat request for providers now asks for usage data, the same way local chats already do. Nothing extra is sent to the provider, and API users who don't ask for usage still don't get it.

…body test

Assert the connected-provider opt-in through the existing AST lookup instead of a regex slice, collapse the route test to one filtering case and one strict-endpoint case, and update the stream_options doc to cover connected providers.
@Lyxot

Lyxot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Pushed fa7dcdc, test and doc cleanup only; the one-line fix in chat-adapter.ts is unchanged.

  • The connected-provider opt-in check moved into external-sampling-payload.test.ts, which already finds this request body by parsing the source, so it now reads the evaluated stream_options value. The regex-based chat-stream-usage-opt-in.test.ts is removed: it would still pass with the line commented out and would fail on a plain reformat.
  • test_external_provider_stream_usage_opt_in.py goes from 8 cases to 2. The route filter has no per-provider branching, so repeating it for three providers added nothing, and the vLLM upstream stream_options check already lives in test_streamed_usage_is_requested_only_where_documented. The remaining two: only an opted-in caller gets the usage chunk (vLLM), and opting in never changes what a custom endpoint receives.
  • The stream_options doc in types/api.ts now says connected-provider chats send it too.

Scope note: providers that are never asked upstream for usage (custom, deepseek, qwen, huggingface, ollama, llama_cpp) show the bar only if their server sends usage unprompted. That is unchanged by this PR.

@Lyxot

Lyxot commented Sep 24, 2026

Copy link
Copy Markdown
Collaborator

Codex converged at fa7dcdc9ba with no findings: Lyxot#82 (comment)

CI on the same head (staging Lyxot#82): 48 passed, 0 failed, 2 skipped (the GPU smoke gate, skipped here as well).

@Lyxot Lyxot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Restores the usage bar and cache stats on connected-provider chats by opting in the same way local chats do; the upstream request is unchanged. Codex converged and staging CI passed at fa7dcdc. The two upstream failures are unrelated: the image-train rail contract test fails on main too, and the Windows Chat UI lane timed out at login before any chat request.

@Lyxot
Lyxot merged commit 06be728 into unslothai:main Sep 24, 2026
49 of 51 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11717)

* Studio: request the stream usage chunk on connected-provider chats

* test(studio): fold the provider usage opt-in check into the external body test

Assert the connected-provider opt-in through the existing AST lookup instead of a regex slice, collapse the route test to one filtering case and one strict-endpoint case, and update the stream_options doc to cover connected providers.

---------

Co-authored-by: Lyxot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants