Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| data = { | |
| "OpenAI GPT-4o": {"input": 2.50, "output": 10.00, "context": "128K", "speed": "80 tok/s"}, | |
| "OpenAI GPT-4o-mini": {"input": 0.15, "output": 0.60, "context": "128K", "speed": "100 tok/s"}, | |
| "OpenAI o1": {"input": 15.00, "output": 60.00, "context": "200K", "speed": "30 tok/s"}, | |
| "OpenAI o3-mini": {"input": 1.10, "output": 4.40, "context": "200K", "speed": "60 tok/s"}, | |
| "Anthropic Claude Sonnet 4": {"input": 3.00, "output": 15.00, "context": "200K", "speed": "70 tok/s"}, | |
| "Anthropic Claude Haiku 3.5": {"input": 0.80, "output": 4.00, "context": "200K", "speed": "120 tok/s"}, | |
| "Anthropic Claude Opus 4": {"input": 15.00, "output": 75.00, "context": "200K", "speed": "25 tok/s"}, | |
| "Google Gemini 2.5 Pro": {"input": 1.25, "output": 10.00, "context": "1M", "speed": "60 tok/s"}, | |
| "Google Gemini 2.5 Flash": {"input": 0.15, "output": 0.60, "context": "1M", "speed": "150 tok/s"}, | |
| "Google Gemini 2.0 Flash": {"input": 0.10, "output": 0.40, "context": "1M", "speed": "180 tok/s"}, | |
| "Meta Llama 3.3 70B": {"input": 0.18, "output": 0.18, "context": "131K", "speed": "90 tok/s"}, | |
| "Meta Llama 4 Maverick": {"input": 0.20, "output": 0.20, "context": "1M", "speed": "100 tok/s"}, | |
| "Mistral Large": {"input": 2.00, "output": 6.00, "context": "128K", "speed": "70 tok/s"}, | |
| "Mistral Small": {"input": 0.10, "output": 0.30, "context": "128K", "speed": "130 tok/s"}, | |
| "DeepSeek V3": {"input": 0.27, "output": 1.10, "context": "128K", "speed": "60 tok/s"}, | |
| "DeepSeek R1": {"input": 0.55, "output": 2.19, "context": "128K", "speed": "30 tok/s"}, | |
| "xAI Grok 2": {"input": 2.00, "output": 10.00, "context": "131K", "speed": "50 tok/s"}, | |
| "xAI Grok 3 Mini": {"input": 0.30, "output": 0.50, "context": "131K", "speed": "120 tok/s"}, | |
| "Groq Llama 3.3 70B": {"input": 0.05, "output": 0.05, "context": "131K", "speed": "300 tok/s"}, | |
| "Cohere Command R+": {"input": 2.50, "output": 10.00, "context": "128K", "speed": "55 tok/s"}, | |
| } | |
| model_names = list(data.keys()) | |
| def calculate_cost(model, input_tokens, output_tokens, requests_per_day): | |
| if model not in data: | |
| return "Select a model" | |
| d = data[model] | |
| input_cost = (input_tokens / 1_000_000) * d["input"] | |
| output_cost = (output_tokens / 1_000_000) * d["output"] | |
| per_request = input_cost + output_cost | |
| daily = per_request * requests_per_day | |
| monthly = daily * 30 | |
| results = [] | |
| for name, info in sorted(data.items(), key=lambda x: (input_tokens/1e6)*x[1]["input"] + (output_tokens/1e6)*x[1]["output"]): | |
| ic = (input_tokens / 1_000_000) * info["input"] | |
| oc = (output_tokens / 1_000_000) * info["output"] | |
| total = (ic + oc) * requests_per_day * 30 | |
| marker = " << SELECTED" if name == model else "" | |
| results.append(f"| {name} | ${total:,.2f} | {info['context']} | {info['speed']} |{marker}") | |
| comparison = "\n".join(results) | |
| return f"""## {model} | |
| | Metric | Value | | |
| |--------|-------| | |
| | Per request | ${per_request:.4f} | | |
| | Daily ({requests_per_day} req) | ${daily:.2f} | | |
| | **Monthly** | **${monthly:.2f}** | | |
| | Context window | {d['context']} tokens | | |
| | Speed | {d['speed']} | | |
| | Input price | ${d['input']}/1M tokens | | |
| | Output price | ${d['output']}/1M tokens | | |
| --- | |
| ## All Models (sorted by monthly cost) | |
| | Model | Monthly Cost | Context | Speed | | |
| |-------|-------------|---------|-------| | |
| {comparison} | |
| --- | |
| *Data from [ComparEdge](https://comparedge.com/best/llm) — Updated April 2026* | |
| """ | |
| with gr.Blocks(title="LLM API Cost Calculator 2026") as demo: | |
| gr.Markdown("# LLM API Cost Calculator 2026\nCompare costs across 20 LLM APIs. Data from [ComparEdge](https://comparedge.com/best/llm).") | |
| with gr.Row(): | |
| model = gr.Dropdown(model_names, label="Model", value="OpenAI GPT-4o") | |
| input_tokens = gr.Slider(100, 100000, value=2000, step=100, label="Input tokens/request") | |
| with gr.Row(): | |
| output_tokens = gr.Slider(100, 50000, value=1000, step=100, label="Output tokens/request") | |
| requests = gr.Slider(1, 10000, value=100, step=1, label="Requests/day") | |
| output = gr.Markdown(label="Cost Breakdown") | |
| for inp in [model, input_tokens, output_tokens, requests]: | |
| inp.change(calculate_cost, [model, input_tokens, output_tokens, requests], output) | |
| demo.load(calculate_cost, [model, input_tokens, output_tokens, requests], output) | |
| if __name__ == "__main__": | |
| demo.launch() | |