Skip to content

fix(firecrawl) fix firecrawl scrape credit usage calculation#3583

Merged
TheodoreSpeaks merged 3 commits intostagingfrom
fix/firecrawl-credits
Mar 14, 2026
Merged

fix(firecrawl) fix firecrawl scrape credit usage calculation#3583
TheodoreSpeaks merged 3 commits intostagingfrom
fix/firecrawl-credits

Conversation

@TheodoreSpeaks
Copy link
Collaborator

Summary

Firecrawl creditsUsed is now stored in metadata, not as a root level field. Adjusted block to accomodate.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

Validated that scrape operation now operates without failing on missing creditsUsed. Tested all other operations to ensure this change wasn't made elsewhere.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link

vercel bot commented Mar 14, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 14, 2026 6:09pm

Request Review

@cursor
Copy link

cursor bot commented Mar 14, 2026

PR Summary

Low Risk
Low risk: small, localized change to Firecrawl scrape cost calculation logic and error handling, with no broader data/auth flow changes.

Overview
Fixes Firecrawl scrape pricing to read creditsUsed from output.metadata (instead of a root-level output.creditsUsed) before computing cost, preventing failures when the field is only returned in metadata.

Written by Cursor Bugbot for commit e29e2b9. This will update automatically on new commits. Configure here.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 14, 2026

Greptile Summary

This PR fixes the Firecrawl scrape tool's credit usage calculation by reading creditsUsed from output.metadata instead of the root-level output field, adapting to a Firecrawl API change where the field moved from the response root into the data.metadata object.

Key changes:

  • getCost in scrape.ts now correctly casts output.metadata to { creditsUsed?: number } and reads from there instead of output.creditsUsed

Issues found:

  • transformResponse (line 114) still reads creditsUsed: data.creditsUsed from the root level, which will always be undefined with the new API. The stale assignment should be removed or updated to data.data.metadata.creditsUsed to match the API change
  • The intermediate variable is named creditsUsedString despite being typed as number, which is misleading

Confidence Score: 3/5

  • The fix unblocks the failing scrape operation but leaves a stale root-level creditsUsed read in transformResponse that always resolves to undefined.
  • The getCost fix is logically correct and resolves the reported failure. However, transformResponse still assigns creditsUsed: data.creditsUsed, which is now permanently undefined under the new API. While optional in the type definition and harmless to the cost calculation, it is an incomplete fix and could mislead future readers. Minor naming issue also present.
  • apps/sim/tools/firecrawl/scrape.ts — specifically the transformResponse function at line 114

Important Files Changed

Filename Overview
apps/sim/tools/firecrawl/scrape.ts Fixes credit calculation to read creditsUsed from output.metadata instead of the root output, but transformResponse still assigns creditsUsed: data.creditsUsed (root-level, now always undefined per the API change), and the intermediate variable is misleadingly named creditsUsedString when it holds a number.

Sequence Diagram

sequenceDiagram
    participant Tool as scrapeTool
    participant API as Firecrawl API (v2/scrape)
    participant Transform as transformResponse
    participant Cost as getCost (pricing)

    Tool->>API: POST /v2/scrape
    API-->>Transform: { data: { markdown, html, metadata: { ..., creditsUsed } }, creditsUsed: undefined }
    Transform-->>Tool: output = { markdown, html, metadata: data.data.metadata, creditsUsed: data.creditsUsed (undefined) }
    Note over Transform: ⚠️ data.creditsUsed is now always undefined<br/>(API moved it into data.metadata)
    Tool->>Cost: getCost(_params, output)
    Cost->>Cost: (output.metadata as {creditsUsed?}).creditsUsed ✅
    Cost-->>Tool: { cost: creditsUsed * 0.001, metadata: { creditsUsed } }
Loading

Comments Outside Diff (1)

  1. apps/sim/tools/firecrawl/scrape.ts, line 114 (link)

    Stale data.creditsUsed read still present in transformResponse

    The PR moves creditsUsed from the root-level API response into data.metadata, and the getCost function is correctly updated to read it via output.metadata.creditsUsed. However, transformResponse still reads creditsUsed from data.creditsUsed (root level), which will now always resolve to undefined since the Firecrawl API has moved that field.

    This means output.creditsUsed in the ScrapeResponse will always be undefined after the transformation. While this doesn't break the pricing calculation (since getCost reads from output.metadata), the stale assignment is misleading and leaves the creditsUsed output field permanently unpopulated. It should either be removed or updated to pull from data.data.metadata.creditsUsed for consistency.

Last reviewed commit: fecc435

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Incomplete fix: transformResponse still reads stale root-level creditsUsed
    • Updated scrape transformResponse to read creditsUsed from metadata so the output no longer uses the stale root-level field.

Create PR

Or push these changes by commenting:

@cursor push 01f02f1169
Preview (01f02f1169)
diff --git a/apps/sim/tools/firecrawl/scrape.ts b/apps/sim/tools/firecrawl/scrape.ts
--- a/apps/sim/tools/firecrawl/scrape.ts
+++ b/apps/sim/tools/firecrawl/scrape.ts
@@ -111,7 +111,7 @@
         markdown: data.data.markdown,
         html: data.data.html,
         metadata: data.data.metadata,
-        creditsUsed: data.creditsUsed,
+        creditsUsed: data.data.metadata?.creditsUsed,
       },
     }
   },

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@TheodoreSpeaks TheodoreSpeaks merged commit f347e3f into staging Mar 14, 2026
12 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the fix/firecrawl-credits branch March 14, 2026 18:27
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