Skip to content

fix: expose Assistant usage and account model catalog - #154

Merged
Microck merged 1 commit into
mainfrom
fix/assistant-usage-models
Aug 9, 2026
Merged

fix: expose Assistant usage and account model catalog#154
Microck merged 1 commit into
mainfrom
fix/assistant-usage-models

Conversation

@Microck

@Microck Microck commented Aug 9, 2026

Copy link
Copy Markdown
Owner

what changed

  • adds structured token counts and USD cost to final Assistant stream events and completed thread messages
  • reads kagi assistant models from the account-level Assistant catalog instead of the custom-assistant form
  • removes the old HTML model parser and documents the stable JSON shapes

why

the current Assistant adapter dropped usage data from both streaming and thread responses. model discovery also depended on having a saved custom assistant, so accounts without one got an empty catalog.

testing

  • cargo fmt --check
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo check --workspace --all-targets --locked
  • cargo test --workspace --all-targets --locked
  • live account check for the model catalog and thread usage output

Fixes #153

Summary by CodeRabbit

  • New Features
    • Added kagi assistant models to list all base models available to your account, including the default model.
    • Assistant responses, streamed events, and exported threads now include token usage and optional upstream USD cost when available.
  • Documentation
    • Documented the model-listing command and usage metadata in the command reference and output contract.
  • Bug Fixes
    • Improved model catalog retrieval for more complete and accurate account-specific results.

Greptile Summary

The PR exposes Assistant token and cost accounting in completed stream and thread messages, and moves model discovery to the account-level Assistant initialization endpoint.

  • Adds a stable AssistantUsage output shape and maps streaming and persisted-message accounting into it.
  • Replaces HTML model parsing with the /api/init JSON catalog, including the account default model.
  • Updates CLI documentation, output contracts, changelog entries, and integration coverage.

Confidence Score: 5/5

The PR appears safe to merge, with no concrete changed-code failure established.

The new account model endpoint, stream accounting conversion, and thread accounting conversion are consistently represented in the public types, command output, documentation, and integration fixtures.

Important Files Changed

Filename Overview
src/api.rs Replaces HTML model discovery with account-level JSON parsing and maps upstream stream and thread accounting into the public usage structure.
src/types.rs Adds the serialized Assistant usage contract and updates the model catalog to expose a top-level default.
src/parser.rs Removes the obsolete custom-assistant HTML model parser and its tests.
tests/integration-cli.rs Covers model-catalog output plus usage fields in final stream events and thread exports.
docs/reference/output-contract.mdx Documents the new Assistant usage and account model-catalog JSON shapes.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Assistant API] -->|SSE final frame| B[Stream frame parser]
    A -->|Conversation messages| C[Thread message converter]
    B --> D[AssistantUsage]
    C --> D
    D --> E[CLI and MCP JSON output]
    F[Account /api/init] --> G[Model catalog converter]
    G --> H[assistant models output]
Loading

Reviews (1): Last reviewed commit: "fix: expose Assistant usage and account ..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Assistant responses now expose token usage and upstream USD cost when supplied by Kagi. The assistant models command now retrieves all account-available base models and the default model from /api/init.

Changes

Assistant API surfaces

Layer / File(s) Summary
Assistant usage metadata
src/types.rs, src/api.rs, tests/integration-cli.rs, src/main.rs, docs/commands/assistant.mdx, docs/reference/output-contract.mdx, CHANGELOG.md
Assistant stream and historical messages now carry optional prompt, completion, total token, and USD cost data. Tests and documentation cover the new output.
Account model catalog retrieval
src/api.rs, src/types.rs, src/parser.rs, src/cli.rs, tests/integration-cli.rs, docs/commands/assistant.mdx, docs/reference/output-contract.mdx, CHANGELOG.md
assistant models now reads the authenticated /api/init catalog, returns model labels and the default model, and no longer parses custom-assistant HTML.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • Microck/kagi-cli#145: Shares the current Assistant conversation and stream handling in src/api.rs.
🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the two primary changes: Assistant usage exposure and the account model catalog.
Description check ✅ Passed The description explains what changed, why it changed, and testing performed, but omits the template's Docs and Auth / Secrets sections.
Linked Issues check ✅ Passed The changes satisfy issue #153 by exposing usage data, loading the account-wide model catalog, and documenting labels and optional pricing.
Out of Scope Changes check ✅ Passed The implementation, documentation, changelog, and tests are directly related to the objectives in issue #153.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Release Metadata Consistency ✅ Passed Cargo.toml, Cargo.lock's kagi package, and npm/package.json all specify 0.16.0; CHANGELOG.md contains the matching ## [0.16.0] heading.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/assistant-usage-models

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Microck

Microck commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CHANGELOG.md`:
- Around line 10-16: Move the Added and Fixed entries from the Unreleased
section to the changelog heading matching the shared release version metadata,
using the exact ## [X.Y.Z] format. Remove or replace the ## [Unreleased] heading
for these entries while preserving their content.

In `@src/api.rs`:
- Around line 4875-4888: Preserve optional pricing throughout the assistant
model catalog: in src/api.rs lines 4875-4888, update CurrentAssistantModel and
its From conversion to deserialize and map the optional pricing field; in
src/types.rs lines 485-495, add the public optional pricing field configured to
be omitted when unavailable; in tests/integration-cli.rs lines 2073-2100, add
pricing to the catalog fixture and assert it appears in CLI JSON output; in
docs/reference/output-contract.mdx lines 205-217, document the optional pricing
field in the stable catalog response.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c807045-6fb5-48b6-81b1-195e60b62940

📥 Commits

Reviewing files that changed from the base of the PR and between 184c344 and c3b0c22.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • docs/commands/assistant.mdx
  • docs/reference/output-contract.mdx
  • src/api.rs
  • src/cli.rs
  • src/main.rs
  • src/parser.rs
  • src/types.rs
  • tests/integration-cli.rs

Comment thread CHANGELOG.md
Comment thread src/api.rs
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: c3b0c22f67

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Microck
Microck merged commit f2c46c4 into main Aug 9, 2026
8 checks passed
@Microck
Microck deleted the fix/assistant-usage-models branch August 9, 2026 16:50
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.

expose per-message tokens/cost + a real 'list all base models' surface

1 participant