Calculate

Calculate Spend

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
        }
    }
}'
POST/spend/calculate
Authorization
Body
modelModel
messagesMessages
completion_responseCompletion Response
Response

Successful Response

Body
any
Request
const response = await fetch('/spend/calculate', {
    method: 'POST',
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({}),
});
const data = await response.json();
Response
{
  "detail": [
    {
      "loc": [
        "text"
      ],
      "msg": "text",
      "type": "text"
    }
  ]
}