> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 모델 호출 전에 요청 비용 추정하기

> 모델 호출 전에 모델 디렉터리 가격과 입력 크기, 출력 한도 또는 작업 수를 조합해 CometAPI 요청 비용을 추정합니다.

모델 디렉터리 가격과 엔드포인트가 과금하는 단위(토큰(Token), 이미지, 오디오 길이 또는 비디오 작업)를 조합해 모델 호출 전에 비용을 추정하세요. 이 추정값은 예산 보호 장치로 활용하고, 요청이 완료된 후에는 실제 사용량과 청구 기록을 사용하세요.

## 토큰 기반 호출 추정하기

다음 Python 예시는 구성된 가격 값을 기준으로 토큰 기반 요청 비용을 추정합니다:

```python theme={null}
import math
import os

prompt = "Write a short product description for CometAPI."
max_output_tokens = 200

input_price_per_1m = float(os.environ["MODEL_INPUT_PRICE_PER_1M"])
output_price_per_1m = float(os.environ["MODEL_OUTPUT_PRICE_PER_1M"])

estimated_input_tokens = math.ceil(len(prompt) / 4)

estimated_cost = (
    estimated_input_tokens * input_price_per_1m
    + max_output_tokens * output_price_per_1m
) / 1_000_000

print(f"Estimated maximum cost: ${estimated_cost:.6f}")
```

결과는 호출 전 추정값입니다:

```text theme={null}
Estimated maximum cost: $0.000123
```

## 최대 출력 예산 설정하기

다음 요청은 생성되는 출력을 제한해 추정값에 상한선을 둡니다:

```bash theme={null}
curl https://api.cometapi.com/v1/chat/completions \
  -H "Authorization: Bearer $COMETAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-model-id",
    "messages": [
      {
        "role": "user",
        "content": "Write a short product description for CometAPI."
      }
    ],
    "max_completion_tokens": 200
  }'
```

응답에는 모델 호출 후 실제 사용량이 포함됩니다:

```json theme={null}
{
  "usage": {
    "prompt_tokens": 10,
    "completion_tokens": 42,
    "total_tokens": 52
  }
}
```

## 작업 기반 호출 추정하기

다음 JavaScript 예시는 이미지 또는 비디오 생성과 같은 작업 기반 워크플로의 비용을 추정합니다:

```javascript theme={null}
const taskCount = 3;
const pricePerTask = Number(process.env.MODEL_PRICE_PER_TASK);

const estimatedCost = taskCount * pricePerTask;

console.log(`Estimated maximum cost: $${estimatedCost.toFixed(4)}`);
```

결과는 작업 예산입니다:

```text theme={null}
Estimated maximum cost: $0.4500
```

## 일반적인 오류

| Error           | Fix                                             |
| --------------- | ----------------------------------------------- |
| 잘못된 모델의 가격 사용   | 모델 디렉터리에서 같은 model ID의 가격을 복사하세요.               |
| 출력 토큰(Token) 무시 | `max_completion_tokens` 또는 엔드포인트별 출력 한도를 설정하세요. |
| 추정값을 청구서처럼 취급   | 호출 후 실제 사용량과 추정값을 비교하세요.                        |
| 작업 배수 누락        | 이미지, 오디오, 비디오는 작업당, 초당 또는 생성된 자산당 과금인지 확인하세요.   |

## 관련 링크

* [요금](https://www.cometapi.com/pricing/)
* [모델 디렉터리](https://www.cometapi.com/models/)
* [모델 페이지](/ko/overview/models)
* [요금 안내](/ko/pricing/about-pricing)
* [CometAPI 빠른 시작](/ko/overview/quick-start)

<script type="application/ld+json">
  {`
    {
    "@context": "https://schema.org",
    "@graph": [
      {
        "@type": "TechArticle",
        "@id": "https://apidoc.cometapi.com/guides/how-to-estimate-cost-before-calling-a-model",
        "headline": "모델을 호출하기 전에 비용을 어떻게 예상하나요?",
        "description": "모델 디렉터리 요금과 입력 크기, 출력 제한 또는 작업 수를 조합하여 모델 호출 전에 CometAPI 요청 비용을 예상합니다.",
        "url": "https://apidoc.cometapi.com/guides/how-to-estimate-cost-before-calling-a-model",
        "author": {
          "@type": "Organization",
          "name": "CometAPI"
        },
        "publisher": {
          "@type": "Organization",
          "name": "CometAPI",
          "url": "https://www.cometapi.com"
        }
      },
      {
        "@type": "BreadcrumbList",
        "itemListElement": [
          {
            "@type": "ListItem",
            "position": 1,
            "name": "CometAPI 문서",
            "item": "https://apidoc.cometapi.com/"
          },
          {
            "@type": "ListItem",
            "position": 2,
            "name": "가이드",
            "item": "https://apidoc.cometapi.com/guides/use-cometapi-with-openai-sdk"
          },
          {
            "@type": "ListItem",
            "position": 3,
            "name": "모델을 호출하기 전에 비용을 어떻게 예상하나요?",
            "item": "https://apidoc.cometapi.com/guides/how-to-estimate-cost-before-calling-a-model"
          }
        ]
      }
    ]
    }
    `}
</script>
