Repository navigation
Finding the costs of extractig a page #1646
Replies: 2 comments 2 replies
|
We just addressed this — PR #1874 adds a To try it now before it's merged: pip install git+https://github.com/hafezparast/crawl4ai.git@fix/token-usage-in-crawl-result-1745Then: result = await crawler.arun(url, config=config)
print(result.token_usage)
# {'prompt_tokens': 1234, 'completion_tokens': 567, 'total_tokens': 1801}If you prefer to stay on the current release, token usage is already tracked on the strategy object — it's just not exposed in strategy = LLMExtractionStrategy(
llm_config=LLMConfig(provider="openai/gpt-4o", api_token="..."),
instruction="...",
)
config = CrawlerRunConfig(extraction_strategy=strategy)
async with AsyncWebCrawler() as crawler:
result = await crawler.arun(url, config=config)
# Token usage is on the strategy object
print(strategy.total_usage) # Accumulated across all chunks
print(strategy.usages) # Per-chunk breakdown
strategy.show_usage() # Pretty-printed summaryFor cost calculation, multiply |
|
@JonasPapinigis for a large seeded extraction, I wrote up the exact setup and what I tested here: #2342. Disclosure: I maintain that gateway (Inferrail, open source). For a provider without a built-in price you add one in the gateway config, so the dollars are your provider's real rates, not an estimate. |
Uh oh!
There was an error while loading. Please reload this page.
I'm looking to use this library on a relatively large scale seeded extraction. I wanted to know there is a way to expose the amount of tokens used in a single-(or even multi-)page extraction/crawl? I know I get the CrawlResult for each page, but I don't see any input/output token consumption metrics anywhere (possibly in metadata?).
My inference provider does not have a way to view EXACT costs, but I want to be able to make something like this for myself: https://github.com/orkunkinay/openai_cost_calculator
Thanks for any help!
All reactions