LLM Cost Calculator
Estimate prompt and completion costs using reference prices for supported models. Returns token estimates, costs and cheaper options.
Pay by wallet (x402)
llm-cost-calculate Example
Example answer
{
"model": "gpt-4o",
"cost_usd": 0.000027,
"input_tokens": 11,
"total_tokens": 11,
"model_pricing": {
"input_per_1k": 0.0025,
"output_per_1k": 0.01
},
"output_tokens": 0,
"context_window": 128000,
"cheaper_alternatives": [
{
"model": "gemini-1.5-flash",
"cost_usd": 0.000001,
"context_window": 1000000,
"savings_percent": 97
},
{
"model": "gpt-4o-mini",
"cost_usd": 0.000002,
"context_window": 128000,
"savings_percent": 94
},
{
"model": "claude-3-haiku",
"cost_usd": 0.000003,
"context_window": 200000,
"savings_percent": 90
},
{
"model": "gpt-3.5-turbo",
"cost_usd": 0.000006,
"context_window": 16385,
"savings_percent": 80
},
{
"model": "llama-3-70b",
"cost_usd": 0.000006,
"context_window": 8192,
"savings_percent": 76
}
]
} Inputs
| Field | Type | Required | What it is |
|---|---|---|---|
model | string | Yes | — |
prompt_text | string | No | — |
prompt_tokens | integer | No | — |
completion_text | string | No | — |
completion_tokens | integer | No | — |
Output fields
How reliably each field appears in a successful answer.
| Field | Type | Appears |
|---|---|---|
cost_usd | number | Always (present in every successful answer) |
input_tokens | integer | Always (present in every successful answer) |
output_tokens | integer | Always (present in every successful answer) |
cheaper_alternatives | array | Always (present in every successful answer) |
How to call it
The same tool through each route. MCP clients reach it through Strale’s server at https://api.strale.io/mcp; the call below is what the agent sends.
# Needs an API key. max_price_cents caps what this call may cost.
curl -X POST https://api.strale.io/v1/do \
-H "Authorization: Bearer $STRALE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{
"capability_slug": "llm-cost-calculate",
"inputs": {
"model": "gpt-4o",
"prompt_text": "Write a function to validate email addresses"
},
"max_price_cents": 2
}' {
"tool": "strale_execute",
"arguments": {
"slug": "llm-cost-calculate",
"inputs": {
"model": "gpt-4o",
"prompt_text": "Write a function to validate email addresses"
},
"max_price_cents": 2
}
} import { Strale } from "straleio";
const strale = new Strale({ apiKey: process.env.STRALE_API_KEY! });
const result = await strale.do({
capability_slug: "llm-cost-calculate",
inputs: {
"model": "gpt-4o",
"prompt_text": "Write a function to validate email addresses"
},
max_price_cents: 2,
}); import os
from straleio import Strale, DoRequest
strale = Strale(api_key=os.environ["STRALE_API_KEY"])
result = strale.do(DoRequest(
capability_slug="llm-cost-calculate",
inputs={
"model": "gpt-4o",
"prompt_text": "Write a function to validate email addresses",
},
max_price_cents=2,
)) # No account. The first request answers 402 with the price in USDC;
# an x402 client pays it from your wallet and repeats the request.
curl -i 'https://api.strale.io/x402/v2/llm-cost-calculate?model=gpt-4o&prompt_text=Write+a+function+to+validate+email+addresses' Limitations
New models and price changes may be missing
Prices come from a stored reference table. New models or recent price changes may be missing.
What to do instead: Check the provider's current pricing page for models showing unexpected costs, especially after major releases
Related tools
- Agent Trace Analysis €0.20
- API Docs Generator €0.20
- API Mock Responses €0.05
- Changelog Generator €0.03
- Code Converter €0.05
- Commit Message Generator €0.05