Skip to main content

LLMKit

Local LLM cost estimates for existing Python SDK calls

PyPI Python versions CI MIT

llmkit-sdk wraps supported HTTP clients, reads token usage from provider responses, and estimates cost from a bundled pricing catalog. Local tracking does not require an LLMKit account or proxy.

pip install llmkit-sdk

Track an existing client

from llmkit import tracked
from openai import OpenAI

costs = []
client = OpenAI(http_client=tracked(on_cost=costs.append))

client.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Explain CQRS."}],
)

print(f"${sum(item.total_cost or 0 for item in costs):.6f}")

The same transport can wrap an Anthropic client:

from anthropic import Anthropic
from llmkit import tracked

costs = []
client = Anthropic(http_client=tracked(on_cost=costs.append))

client.messages.create(
    model="claude-sonnet-4-20250514",
    max_tokens=512,
    messages=[{"role": "user", "content": "Explain event sourcing."}],
)

Estimate a completed response

from llmkit import estimate_cost

cost = estimate_cost(response)
print(f"~${cost.total_cost:.6f}")

LangChain callback

from llmkit.integrations.langchain import LLMKitCallbackHandler

handler = LLMKitCallbackHandler()
chain.invoke("Summarize this report", config={"callbacks": [handler]})
print(f"${handler.total_cost:.4f}")

Framework integrations are optional. Install the framework you use separately.

Sessions and gateway mode

Use the hosted or self-hosted LLMKit gateway when you need shared budgets, request receipts, provider routing, or dashboard analytics:

from llmkit import LLMKit

client = LLMKit(api_key="llmk_your_key_here")
session = client.session()

completion, cost = session.chat(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Draft a release note."}],
)

print(f"${cost.total_cost:.4f} via {cost.provider}")

For an OpenAI-compatible client:

from openai import OpenAI

client = OpenAI(
    base_url="https://api.llmkit.sh/v1",
    api_key="llmk_your_key_here",
)

Async client

from llmkit import AsyncLLMKit

client = AsyncLLMKit(api_key="llmk_your_key_here")
completion, cost = await client.chat(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Summarize this incident."}],
)

Accuracy boundary

  • Local values are estimates derived from response usage metadata and the bundled pricing table.
  • Provider invoice adjustments, account-specific discounts, and pricing changes may differ.
  • Local tracking observes cost; budget rejection requires gateway mode.
  • Streaming cost is final only after the stream completes and usage metadata is available.

LLMKit repository

The LLMKit monorepo also contains the Cloudflare Worker gateway, dashboard, TypeScript SDK, CLI, Vercel AI SDK provider, MCP server, database migrations, and deterministic budget-control fixtures.

License

MIT

Download files

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

Source Distribution

llmkit_sdk-0.1.10.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

llmkit_sdk-0.1.10-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file llmkit_sdk-0.1.10.tar.gz.

File metadata

  • Download URL: llmkit_sdk-0.1.10.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llmkit_sdk-0.1.10.tar.gz
Algorithm Hash digest
SHA256 d99b846a0faa4ca4c8cebbbfe107c44583039a5057be4ffcfd26f1afd973e336
MD5 8027a87d6db55bd18217ec60cba9147f
BLAKE2b-256 04eca7215bc8c6454cf34fa6a9cd15495db07ba4d0c1cec5dd15df0512b62c18

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmkit_sdk-0.1.10.tar.gz:

Publisher: publish-pypi.yml on smigolsmigol/llmkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file llmkit_sdk-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: llmkit_sdk-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for llmkit_sdk-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 338bd986dd8874382979b003579f76662d6e2eabb55928a5738ac77744feb1bf
MD5 ecd1cebf6464ce419003d8fda394443e
BLAKE2b-256 efd71c45381da50d2018b1f05ca4d536885a34c0f99fd6871bf3ef92c168aec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for llmkit_sdk-0.1.10-py3-none-any.whl:

Publisher: publish-pypi.yml on smigolsmigol/llmkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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