Skip to content

Conversation

@Sahil5963
Copy link
Contributor

Summary

  • chat() now returns usage directly in result
  • User strips usage key before sending to Copilot client
  • Removed onFinish callback from chat() (not needed - usage is in result)

Usage

// Usage is included in result - strip before sending to client
const { usage, ...clientResult } = await runtime.chat(body);

if (usage) {
  await billing.recordUsage(userId, usage.total_tokens);
}

res.json(clientResult); // Send without usage

Breaking Change

chat() no longer accepts onFinish callback. Use destructuring to access usage.

Test plan

  • Test chat() returns usage in result
  • Test stripping usage before sending to client
  • Verify docs are updated

🤖 Generated with Claude Code

- chat() now returns usage in result (user strips before sending to client)
- Remove onFinish callback from chat() - usage is in result directly
- Fix generate-result.ts import to use local types
- Update express-demo to demonstrate new pattern
- Update docs with new usage tracking pattern

BREAKING: chat() no longer accepts onFinish callback
Use: const { usage, ...clientResult } = await runtime.chat(body)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Jan 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
copilot-sdk-docs Ready Ready Preview, Comment Jan 28, 2026 0:09am

Request Review

@Rohitjoshi9023 Rohitjoshi9023 merged commit 297e846 into main Jan 28, 2026
2 of 3 checks passed
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.

3 participants