Skip to content

feat: add Fireworks AI plugin for usage tracking and billing metrics#359

Open
sayuru-akash wants to merge 5 commits into
robinebers:mainfrom
sayuru-akash:main
Open

feat: add Fireworks AI plugin for usage tracking and billing metrics#359
sayuru-akash wants to merge 5 commits into
robinebers:mainfrom
sayuru-akash:main

Conversation

@sayuru-akash
Copy link
Copy Markdown
Contributor

@sayuru-akash sayuru-akash commented Apr 7, 2026

Description

This pull request introduces a new provider plugin for Fireworks AI, enabling users to track their Fireworks AI usage directly within OpenUsage.

The integration is built on Fireworks AI's official non-browser surfaces and does not depend on browser login or session state. It fetches account details and quotas from the Fireworks API, and uses the official firectl billing export-metrics path to compute rolling token usage for serverless inference.

The provider currently calculates and displays the most truthful metrics available from the validated account shape:

  • Serverless usage
  • Prompt tokens
  • Generated tokens
  • Monthly spend
  • Budget insights
  • Status when the account is not healthy

Authentication is supported via both macOS Keychain and environment variables, ensuring secure and flexible API key management.

A complete plugin manifest, documentation, icon assets, shared host/runtime support, and comprehensive test coverage have also been included.

Fireworks AI Integration

  • Added a new Fireworks AI plugin to fetch:
    • Account details
    • Usage quotas
    • Billing and spend metrics
  • Computed and exposed:
    • Serverless usage
    • Prompt tokens
    • Generated tokens
    • Monthly spend
    • Budget tracking
  • Implemented authentication via:
    • macOS Keychain
    • Environment variables
  • Added plugin manifest defining:
    • Metadata
    • Metrics
    • UI display lines
  • Included SVG icon for provider representation
  • Added detailed documentation for setup and usage
  • Implemented comprehensive test coverage for:
    • API interactions
    • Data parsing
    • Error handling

What Else We Can Do In The Future

  • Add a Fireworks-specific usage chart line backed by the official billing export data
    • This might be the right way to represent the daily serverless token pattern shown in the Fireworks dashboard
    • It should be implemented as a small histogram/sparkbar over a rolling window, not as a fake percentage progress bar

Related Issue

Fixes #352

Type of Change

  • Bug fix
  • New feature
  • New provider plugin
  • Documentation
  • Performance improvement
  • Other (describe below)

Screenshot

Screenshot 2026-04-08 at 01 37 43

Testing

  • I ran bun run build and it succeeded
  • I ran bun run test and all tests pass
  • I tested the change locally with bun tauri dev

Checklist

  • I read CONTRIBUTING.md
  • My PR targets the main branch
  • I did not introduce new dependencies without justification

Summary by cubic

Adds a fireworks-ai provider plugin to track Fireworks usage and billing in OpenUsage with secure CLI-backed token totals and clear fallbacks. Includes a host fireworks.exportBillingMetrics helper with a temporary ~/.fireworks/auth.ini, date-only windows, URL redaction, and a 15s timeout.

  • New Features
    • New fireworks-ai plugin: lists accounts/quotas from https://api.fireworks.ai/v1, selects a healthy account; plan tier inferred from budget cap; API-key auth via macOS Keychain or FIREWORKS_API_KEY.
    • Rolling token totals via fireworks.exportBillingMetrics using firectl billing export-metrics; respects zero-value windows; falls back to token quotas or spend-only with clear reasons; detects missing runner.
    • Helper runs firectl with a temporary ~/.fireworks/auth.ini (no key on argv) and enforces a 15s timeout to avoid hangs.
    • Lines shown: Serverless usage, Prompt tokens, Generated tokens, Month spend, Budget, Status.
    • Host/runtime: allowlists FIREWORKS_API_KEY, redacts /accounts/{id} in URLs, exposes fireworks.exportBillingMetrics with a JS wrapper; added docs, tests, icon, manifest, and README entry.

Written for commit 8676648. Summary will update on new commits.

- Implemented the Fireworks AI plugin to track serverless usage, prompt tokens, generated tokens, monthly spend, and budget.
- Added API calls to list accounts and quotas, and export billing metrics.
- Integrated macOS Keychain and environment variable support for API key management.
- Created a detailed documentation file for the Fireworks AI plugin.
- Added SVG icon for the Fireworks AI plugin.
- Developed comprehensive tests to ensure functionality and error handling.
Copilot AI review requested due to automatic review settings April 7, 2026 20:08
@github-actions github-actions Bot added rust Pull requests that update rust code plugin docs labels Apr 7, 2026
@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Apr 7, 2026

🤖 Augment PR Summary

Summary: Adds a new Fireworks AI provider plugin so OpenUsage can show Fireworks account health, spend/budget, and serverless token usage.

Changes:

  • New plugins/fireworks-ai plugin (manifest + JS probe) that fetches accounts/quotas from Fireworks’ control-plane API
  • Optional rolling token totals computed by parsing CSV from the official firectl billing export-metrics path
  • New provider documentation page and README provider list entry
  • Host runtime support: expose host.fireworks.exportBillingMetrics to plugins and allow FIREWORKS_API_KEY via env allowlist
  • Improve request logging redaction by masking /accounts/{id} path segments
  • Add comprehensive unit tests for plugin behavior, env exposure, wrapper injection, and redaction

Technical Notes: Billing exports use UTC date-only windows ("Last 30 days") and the UI falls back to spend/budget when token exports are unavailable.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

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

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread README.md Outdated
Comment thread docs/providers/fireworks-ai.md Outdated
Comment thread plugins/fireworks-ai/plugin.js Outdated
Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59d328eacb

ℹ️ 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".

Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Fireworks AI provider plugin to OpenUsage, including host/runtime support for pulling usage/billing metrics and documentation so users can configure authentication and understand reported metrics.

Changes:

  • Added a Fireworks AI plugin (manifest, implementation, icon) that queries Fireworks account/quota APIs and optionally computes rolling serverless token usage via firectl billing export-metrics.
  • Extended the Tauri plugin host API to expose host.fireworks.exportBillingMetrics() to plugins, whitelist FIREWORKS_API_KEY, and redact Fireworks account IDs from logged URLs.
  • Added provider docs, README provider list entry, and Vitest coverage for the new plugin + host changes.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src-tauri/src/plugin_engine/runtime.rs Calls the new Fireworks wrapper patch during plugin probe setup.
src-tauri/src/plugin_engine/host_api.rs Adds env allowlist entry, URL redaction for /accounts/{id}, Fireworks host API injection, and firectl runner integration + tests.
README.md Adds Fireworks AI to the provider list.
plugins/test-helpers.js Extends the mock host context with host.fireworks.exportBillingMetrics.
plugins/fireworks-ai/plugin.test.js Comprehensive tests for auth resolution, quota parsing, billing export integration, and error paths.
plugins/fireworks-ai/plugin.json New plugin manifest defining Fireworks AI lines/labels/scopes and metadata.
plugins/fireworks-ai/plugin.js Fireworks AI plugin implementation (accounts, quotas, billing CSV parsing, output formatting).
plugins/fireworks-ai/icon.svg Provider icon asset.
docs/providers/fireworks-ai.md Setup + behavior documentation for the Fireworks AI provider.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src-tauri/src/plugin_engine/host_api.rs
Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Comment thread README.md Outdated
Comment thread docs/providers/fireworks-ai.md
Comment thread docs/providers/fireworks-ai.md
Comment thread plugins/fireworks-ai/plugin.js Outdated
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

6 issues found across 9 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src-tauri/src/plugin_engine/host_api.rs">

<violation number="1" location="src-tauri/src/plugin_engine/host_api.rs:31">
P1: Global allowlisting of `FIREWORKS_API_KEY` exposes a sensitive credential to all plugins because env access is not scoped per plugin.</violation>

<violation number="2" location="src-tauri/src/plugin_engine/host_api.rs:2062">
P1: Fireworks API key is passed in child-process argv (`--api-key <secret>`), creating credential exposure risk via process inspection/log surfaces.</violation>

<violation number="3" location="src-tauri/src/plugin_engine/host_api.rs:2072">
P1: `Command::output()` has no timeout — if `firectl billing export-metrics` hangs (DNS/network issues), the probe thread blocks indefinitely and the batch never finishes. Add bounded wait/kill logic similar to how other external command runners in this codebase handle subprocess timeouts.</violation>
</file>

<file name="README.md">

<violation number="1" location="README.md:34">
P2: README documents Fireworks metrics as TPS, but the plugin and provider docs expose prompt/generated token totals, creating a user-facing contract mismatch.</violation>
</file>

<file name="plugins/fireworks-ai/plugin.js">

<violation number="1" location="plugins/fireworks-ai/plugin.js:36">
P3: `lastFinite()` iterates forward and returns the **first** finite number, not the last. The name is misleading and will confuse future maintainers. Rename to `firstFinite` or change the loop to iterate backwards.</violation>

<violation number="2" location="plugins/fireworks-ai/plugin.js:302">
P2: Zero-token billing exports are incorrectly marked as non-ok, causing valid zero usage to be shown as unavailable/error state.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.

Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
"MINIMAX_CN_API_KEY",
"SYNTHETIC_API_KEY",
"PI_CODING_AGENT_DIR",
"FIREWORKS_API_KEY",
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 7, 2026

Choose a reason for hiding this comment

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

P1: Global allowlisting of FIREWORKS_API_KEY exposes a sensitive credential to all plugins because env access is not scoped per plugin.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src-tauri/src/plugin_engine/host_api.rs, line 31:

<comment>Global allowlisting of `FIREWORKS_API_KEY` exposes a sensitive credential to all plugins because env access is not scoped per plugin.</comment>

<file context>
@@ -28,6 +28,7 @@ const WHITELISTED_ENV_VARS: [&str; 16] = [
     "MINIMAX_CN_API_KEY",
     "SYNTHETIC_API_KEY",
     "PI_CODING_AGENT_DIR",
+    "FIREWORKS_API_KEY",
 ];
 
</file context>
Fix with Cubic

Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Comment thread README.md Outdated
Comment thread plugins/fireworks-ai/plugin.js Outdated
Comment thread plugins/fireworks-ai/plugin.js Outdated
@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59d328eacb

ℹ️ 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".

Comment thread plugins/fireworks-ai/plugin.js Outdated
Comment thread plugins/fireworks-ai/plugin.js Outdated
@sayuru-akash
Copy link
Copy Markdown
Contributor Author

Hi, @validatedev @robinebers ,

Just checking in on this PR, because I didn’t fully understand why it’s still open, as I can see the Fireworks AI plugin has already been added in the latest release, even though this PR hasn’t been merged.

Could we review this and either merge it if it’s still relevant or close it if it’s not relevant? Feel free to let me know if you need any assistance on my end as well. Thanks

@HDash
Copy link
Copy Markdown

HDash commented Apr 27, 2026

Quick check on #359, happy to help!

Copy link
Copy Markdown
Owner

@robinebers robinebers left a comment

Choose a reason for hiding this comment

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

Hey! This is Rob's AI reviewer. Thanks for the contribution!

Fireworks AI plugin looks solid overall. The plugin shape, icon, env whitelist, redaction test, and plugin tests all line up well. Three things to fix before merge:

  1. Add a timeout around firectlexportBillingMetrics runs the Fireworks CLI with .output(), so if firectl hangs, the whole provider probe can hang too. Please add a timeout like the existing ccusage runner uses.

  2. Document the new host helper — this PR adds ctx.host.fireworks.exportBillingMetrics, but docs/plugins/api.md does not explain it yet. Since this is new plugin API surface, please add a short section for it.

  3. Fix the README wording — the README says prompt/generated TPS, but the plugin shows token totals, not tokens-per-second. Please change it to prompt/generated tokens.

Everything else looks good.

@validatedev validatedev requested a review from Copilot May 2, 2026 23:24
@validatedev
Copy link
Copy Markdown
Collaborator

@codex review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Comment thread plugins/fireworks-ai/plugin.js Outdated
Comment thread README.md Outdated
Comment thread plugins/fireworks-ai/plugin.js Outdated
Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e141abcc50

ℹ️ 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".

Comment thread plugins/fireworks-ai/plugin.js Outdated
Comment thread src-tauri/src/plugin_engine/host_api.rs Outdated
@sayuru-akash
Copy link
Copy Markdown
Contributor Author

sayuru-akash commented May 13, 2026

Hi, @validatedev @robinebers ,

Just pinging an update on this PR, cause I did some updates and pushed. You may check. Thanks

@HDash

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

Labels

docs plugin rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New provider request - Fireworks.ai

5 participants