Skip to main content

Know your AI API costs before you spend. Calculate and compare LLM pricing from the terminal.

Project description

apicost

Know your AI API costs before you spend.

Calculate and compare LLM pricing from the terminal. 25+ models, all major providers.

PyPI License Python PRs Welcome


Install

pip install apicost

Usage

Calculate cost for a specific model

$ apicost calc gpt-4o -i 10000 -o 2000

  Model:    gpt-4o (OpenAI)
  Input:    10,000 tokens    $0.0250
  Output:   2,000 tokens     $0.0200
  ─────────────────────────────────
  Total:    $0.0450

Compare costs across ALL models

$ apicost compare -i 10000 -o 2000

  Cost comparison: 10,000 input + 2,000 output tokens

  Model                     Provider        Input        Output       Total
  ───────────────────────── ─────────────── ──────────── ──────────── ────────────
  ollama                    Local (Ollama)  $0.00 (free) $0.00 (free) $0.00 (free)
  mistral-nemo              Mistral         $0.000200    $0.000040    $0.000240
  llama-3.3-70b             Meta (Groq)     $0.000600    $0.000120    $0.000720
  deepseek-v3               DeepSeek        $0.0028      $0.000840    $0.0036
  gpt-4o-mini               OpenAI          $0.0015      $0.0012      $0.0027
  ...
  claude-opus-4-6           Anthropic       $0.0500      $0.0500      $0.10

List all models and pricing

$ apicost list

Use as a Python library

from apicost import calculate_cost, estimate_cost

# Exact token count
result = calculate_cost("gpt-4o", input_tokens=5000, output_tokens=1000)
print(f"Total: ${result['total_cost']:.4f}")

# Estimate from text
result = estimate_cost("claude-sonnet-4-6", input_text="Your prompt here...", output_tokens=500)
print(f"Estimated: ${result['total_cost']:.6f}")

Supported Models

Provider Models
Anthropic Claude Opus 4.6, Sonnet 4.6, Haiku 4.5
OpenAI GPT-5.2, GPT-5.2 Mini, GPT-4o, GPT-4o Mini, o3, o3-mini
Google Gemini 3.1 Pro, 3 Flash, 2.5 Pro, 2.0 Flash, 2.0 Flash-Lite
DeepSeek V3, R1
Mistral Large, Small, Nemo
Meta Llama 4 Maverick, Scout, 3.3 70B (via Groq)
Cohere Command R+, Command R
Local Ollama, any local model ($0)

Commands

apicost calc <model> [-i INPUT] [-o OUTPUT]    # Calculate cost
apicost compare [-i INPUT] [-o OUTPUT]          # Compare all models
apicost list                                     # Show all models + pricing

Why?

Every AI developer asks "how much will this cost?" before making API calls. This tool answers that instantly, from your terminal or Python code, without looking up pricing pages.

Contributing

PRs welcome — especially for adding new models and keeping prices up to date.

License

MIT


If this saves you money, give it a star.


Also By OuterSpacee

Project Description
Awesome AI Tools 200+ AI tools across 22 categories
Build Your Own AI 150+ tutorials for building AI projects from scratch
AI Engineering Handbook Everything you need to build production AI apps
Free AI APIs 100+ free AI APIs for developers
aimsg AI-powered git commit messages — free with Ollama

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apicost-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apicost-1.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file apicost-1.0.0.tar.gz.

File metadata

  • Download URL: apicost-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for apicost-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2f62316e27090e7e0d06ba3f6726d31ae13100f6325e3ff85ae4550adcacbcbd
MD5 ff54ee9d0c282e2bb8391f0bb910ff28
BLAKE2b-256 3ff474c776c7f29a53abfa2b762961d3e406453d5c745d5db003d2a0b25b84ce

See more details on using hashes here.

File details

Details for the file apicost-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: apicost-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for apicost-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44bb4075fdd6f1be2f1af7f124b236dcf589982113dfe748e4fc1be5f9f94a28
MD5 09c559e139dfb0e479118075ff2d2b62
BLAKE2b-256 9ea2e64286d136ea1b3de9ee9b30bbf81113bda8fd0a76ccf475fd1c8cbbe273

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page