Skip to content

[Fix] anthropic: Preserve Kimi Messages stream usage - #48765

Open
Jiminator wants to merge 1 commit into
sgl-project:mainfrom
Jiminator:fix/k31-messages-stream-usage
Open

Jiminator wants to merge 1 commit into
sgl-project:mainfrom
Jiminator:fix/k31-messages-stream-usage

Conversation

@Jiminator

@Jiminator Jiminator commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Streaming /v1/messages omits Kimi cache-read counts when --enable-cache-report is disabled. Empty completions can also emit message_start before the final usage summary, reporting zero input tokens even when the backend supplies their count.

Modifications

Preserve Kimi cached-token details in continuous usage so the Anthropic adapter can report uncached input and cache reads separately. Start an empty completion from its usage-only summary when available, retaining the existing [DONE] fallback when no usage is supplied.

For 3,847 prompt tokens with a 3,072-token cache hit, message_start.usage reports input_tokens: 775, cache_read_input_tokens: 3072, and output_tokens: 0. Final output accounting stays in message_delta.

Validation

The diff against main changes two production files and contains no test changes. All 70 Anthropic serving tests and 171 OpenAI serving tests pass. A runtime replay reproduces zero input usage on the previous empty-completion path and verifies the corrected 775/3072 split, including with cache reporting disabled. Generic models retain the cache-report flag behavior.

Applicable pre-commit hooks and git diff --check pass. GitHub lint and all ten hosted CPU CI shards passed for commit 5bc54efa79dcb55623bdb981fd3398eda858af5b.


CI States

Latest PR Test (Base): ❌ Run #42451196701
Latest PR Test (Extra): ❌ Run #42451196711
Latest PR Test (AMD ROCm 10): ❌ Run #42451196957

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on 54d8dad425fd: ❌ View workflow run

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on 084762801bfc: ❌ View workflow run

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on 85a2c3500d20: ❌ View workflow run

@Jiminator Jiminator changed the title [Fix] anthropic: Report Kimi prompt usage at stream start [Fix] anthropic: Preserve Kimi Messages stream usage Nov 8, 2026
@Jiminator
Jiminator changed the base branch from kimi-k3.1-day-0 to main November 8, 2026 05:32

Copy link
Copy Markdown
Collaborator Author

/run-cpu-ci

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Running base-a-test-cpu on 5bc54efa79dc: ✅ View workflow run

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant