> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-feature-automate-reference-docs-generation.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Costs

## 사용자 정의 비용 추가

<Tabs>
  <Tab title="Python">
    다음을 사용하여 사용자 정의 비용을 추가할 수 있습니다 [`add_cost`](/reference/python-sdk/weave/trace/weave.trace.weave_client#method-add_cost) 메서드.
    필수 필드 세 가지는 `llm_id`, `prompt_token_cost`, 및 `completion_token_cost`입니다.

    `llm_id`는 LLM의 이름입니다(예: `gpt-4o`). `prompt_token_cost` 및 `completion_token_cost`는 LLM의 토큰당 비용입니다(LLM 가격이 백만 토큰당으로 지정된 경우 값을 변환해야 합니다).
    또한 `effective_date`를 datetime으로 설정하여 특정 날짜에 비용이 적용되도록 할 수 있으며, 기본값은 현재 날짜입니다.

    ```python
    import weave
    from datetime import datetime

    client = weave.init("my_custom_cost_model")

    client.add_cost(
        llm_id="your_model_name",
        prompt_token_cost=0.01,
        completion_token_cost=0.02
    )

    client.add_costs(
        llm_id="your_model_name",
        prompt_token_cost=10,
        completion_token_cost=20,
        # If for example I want to raise the price of the model after a certain date
        effective_date=datetime(2025, 4, 22),
    )
    ```
  </Tab>

  <Tab title="TypeScript">
    ```plaintext
    This feature is not available in TypeScript yet.  Stay tuned!
    ```
  </Tab>
</Tabs>

## 비용 쿼리

<Tabs>
  <Tab title="Python">
    다음을 사용하여 비용을 쿼리할 수 있습니다 [`query_costs`](/reference/python-sdk/weave/trace/weave.trace.weave_client#method-query_costs) 메서드.
    비용을 쿼리하는 방법에는 여러 가지가 있으며, 단일 비용 ID 또는 LLM 모델 이름 목록을 전달할 수 있습니다.

    ```python
    import weave

    client = weave.init("my_custom_cost_model")

    costs = client.query_costs(llm_ids=["your_model_name"])

    cost = client.query_costs(costs[0].id)
    ```
  </Tab>

  <Tab title="TypeScript">
    ```plaintext
    This feature is not available in TypeScript yet.  Stay tuned!
    ```
  </Tab>
</Tabs>

## 사용자 정의 비용 제거

<Tabs>
  <Tab title="Python">
    다음을 사용하여 사용자 정의 비용을 제거할 수 있습니다 [`purge_costs`](/reference/python-sdk/weave/trace/weave.trace.weave_client#method-purge_costs) 메서드. 비용 ID 목록을 전달하면 해당 ID를 가진 비용이 제거됩니다.

    ```python
    import weave

    client = weave.init("my_custom_cost_model")

    costs = client.query_costs(llm_ids=["your_model_name"])
    client.purge_costs([cost.id for cost in costs])
    ```
  </Tab>

  <Tab title="TypeScript">
    ```plaintext
    This feature is not available in TypeScript yet.  Stay tuned!
    ```
  </Tab>
</Tabs>

## 프로젝트 비용 계산

<Tabs>
  <Tab title="Python">
    우리의 `calls_query`를 사용하고 `include_costs=True`를 약간의 설정과 함께 추가하여 프로젝트 비용을 계산할 수 있습니다.

    ```python
    import weave

    weave.init("project_costs")
    @weave.op()
    def get_costs_for_project(project_name: str):
        total_cost = 0
        requests = 0

        client = weave.init(project_name)
        # Fetch all the calls in the project
        calls = list(
            client.get_calls(filter={"trace_roots_only": True}, include_costs=True)
        )

        for call in calls:
            # If the call has costs, we add them to the total cost
            if call.summary["weave"] is not None and call.summary["weave"].get("costs", None) is not None:
                for k, cost in call.summary["weave"]["costs"].items():
                    requests += cost["requests"]
                    total_cost += cost["prompt_tokens_total_cost"]
                    total_cost += cost["completion_tokens_total_cost"]

        # We return the total cost, requests, and calls
        return {
            "total_cost": total_cost,
            "requests": requests,
            "calls": len(calls),
        }

    # Since we decorated our function with @weave.op(),
    # our totals are stored in weave for historic cost total calculations
    get_costs_for_project("my_custom_cost_model")
    ```
  </Tab>

  <Tab title="TypeScript">
    ```plaintext
    This feature is not available in TypeScript yet.  Stay tuned!
    ```
  </Tab>
</Tabs>

## 사용자 정의 비용이 있는 사용자 정의 모델 설정

다음에 대한 쿡북을 시도해 보세요 [Setting up costs with a custom model](/ko/cookbooks/custom_model_cost) 또는 <a href="https://colab.research.google.com/github/wandb/weave/blob/master/docs/./notebooks/custom_model_cost.ipynb" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link button button--secondary button--med margin-right--sm notebook-cta-button"><div><img src="https://upload.wikimedia.org/wikipedia/commons/archive/d/d0/20221103151430%21Google_Colaboratory_SVG_Logo.svg" alt="Open In Colab" height="20px" /><div>Open in Colab</div></div></a>
