---
title: "Calculate Spend"
method: POST
path: "/spend/calculate"
tags: ["Budget & Spend Tracking"]
---

# Calculate Spend

`POST /spend/calculate`

Accepts all the params of completion_cost.

Calculate spend **before** making call:

Note: If you see a spend of $0.0 you need to set custom_pricing for your model: https://docs.litellm.ai/docs/proxy/custom_pricing

```
curl --location 'http://localhost:4000/spend/calculate'
--header 'Authorization: Bearer sk-1234'
--header 'Content-Type: application/json'
--data '{
    "model": "anthropic.claude-v2",
    "messages": [{"role": "user", "content": "Hey, how'''s it going?"}]
}'
```

Calculate spend **after** making call:

```
curl --location 'http://localhost:4000/spend/calculate'
--header 'Authorization: Bearer sk-1234'
--header 'Content-Type: application/json'
--data '{
    "completion_response": {
        "id": "chatcmpl-123",
        "object": "chat.completion",
        "created": 1677652288,
        "model": "gpt-3.5-turbo-0125",
        "system_fingerprint": "fp_44709d6fcb",
        "choices": [{
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "Hello there, how may I assist you today?"
            },
            "logprobs": null,
            "finish_reason": "stop"
        }]
        "usage": {
            "prompt_tokens": 9,
            "completion_tokens": 12,
            "total_tokens": 21
        }
    }
}'
```

## Request body

- SpendCalculateRequest
  - `model` string, nullable
  - `messages` unknown[], nullable
    - unknown
  - `completion_response` object, nullable

## Response `200`

The calculated cost

- object
  - `cost` number — The calculated cost

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/flock/apis/litellm-api.md) · [All operations](https://skmtc.net/flock/apis/litellm-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/flock/litellm-api/revisions/8fbaab4fc7c5/schema)
