Skip to main content

Description

A custom step for LLM API cost calculation for the distilabel library. This library allows you to calculate API usage costs based on token consumption and supports customizable pricing models for different LLMs.

Requirements

  • Python: ^3.10.15
  • Distilabel: >=1.3.2

Installation

pip install distilabel-cost-calculator

Example

from distilabel_cost_calculator import GenerationCostCalculator

with Pipeline("data_generation_with_cost_calculator") as pipeline:
    model = OpenAILLM(model="gpt-4o-mini", api_key=OPENAI_API_KEY)

    data = LoadDataFromDicts(data=[{"instruction": "Generate me a quote."}])
    task = TextGeneration(name="text-generation", llm=model, num_generations=2)

    # You can provide custom pricing for the API model
    custom_pricing = {
        "input_pricing": 0.15,  # Custom price per token for inputs
        "output_pricing": 0.6  # Custom price per token for outputs
    }

    cost_step = GenerationCostCalculator(
        api_model_name="gpt-4o-mini",
        api_pricing=custom_pricing  # Optional: Override default pricing
    )

    data >> task >> cost_step
pipeline.run(use_cache=False)

# API cost details will be found in the 'api_cost' column in the Distiset.
# 'api_cost': {'inputs': 7.5e-07, 'outputs': 1.019e-05, 'total_cost_str': '0.000011$'}

Metadata

Release files for distilabel-cost-calculator 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for distilabel-cost-calculator 0.2.1
File Size Uploaded
distilabel_cost_calculator-0.2.1.tar.gz 3.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for distilabel-cost-calculator 0.2.1
File Interpreter ABI Platform
distilabel_cost_calculator-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / distilabel_cost_calculator-0.2.1.tar.gz

Download URL distilabel_cost_calculator-0.2.1.tar.gz
Size 3.2 kB
Tags Source
SHA-256 checksum
How to use checksums
88f0d54a8c96cc978b84af1931be7dc93c65eb75c8f2af41534b19aa118b158e
BLAKE2b-256 checksum
How to use checksums
921ffb4f558c0f6262ac0fb83ecdfcee5f83f213bfe163a769ed46ff62988ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.7 Darwin/23.6.0

Release files / distilabel_cost_calculator-0.2.1-py3-none-any.whl

Download URL distilabel_cost_calculator-0.2.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3bd72a1807db52d76d9eabcd708bfb0ff57e1e16fabbfbbe2df6f2dd4f116a9
BLAKE2b-256 checksum
How to use checksums
e1289d847f7e33fbec26e325649726e617e2508f2a6aae8400a661a1abb229e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.7 Darwin/23.6.0

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page