Skip to main content

Costimizer AI observability SDK for LLM FinOps

Project description

Costimizer Python SDK

PyPI

Capture LLM calls and send them to Costimizer FinOps.

Install only the provider client you use

pip install "costimizer[openai]"
pip install "costimizer[openrouter]"
pip install "costimizer[otel-langchain]"   # LangChain auto-instrument
pip install "costimizer[otel-openai]"      # native OpenAI auto-instrument

Core SDK (httpx only) installs with:

pip install costimizer

OpenAI

pip install "costimizer[openai]"
from costimizer import Costimizer
from costimizer.ai.openai import OpenAI

costimizer = Costimizer(
    project_token="fo_ingest_your_key",
    host="https://api.costimizer.ai",
)

client = OpenAI(
    api_key="sk-...",
    costimizer_client=costimizer,
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
    costimizer_trace_name="support-chat",
)
costimizer.shutdown()

OpenRouter

OpenRouter uses the OpenAI-compatible API, so it installs the openai package:

pip install "costimizer[openrouter]"
from costimizer import Costimizer
from costimizer.ai.openrouter import OpenRouter

costimizer = Costimizer(project_token="fo_ingest_your_key")

client = OpenRouter(
    api_key="sk-or-...",
    costimizer_client=costimizer,
)

response = client.chat.completions.create(
    model="anthropic/claude-3.5-sonnet",
    messages=[{"role": "user", "content": "Hello"}],
    costimizer_trace_name="router-chat",
)
costimizer.shutdown()

LangChain (callback)

pip install "costimizer[langchain]"

Manual callback alternative when OTel is not available:

from costimizer import Costimizer
from costimizer.langchain import CostimizerCallbackHandler
from langchain_openai import ChatOpenAI

costimizer = Costimizer(project_token="fo_ingest_your_key")
handler = CostimizerCallbackHandler(
    costimizer,
    trace_name="support-chat",
    distinct_id="user-123",
)

model = ChatOpenAI(model="gpt-4o-mini", temperature=0.7, seed=42)
model.invoke("Hello", config={"callbacks": [handler]})
costimizer.shutdown()

OpenTelemetry (native OpenAI)

pip install "costimizer[otel-openai]"
from costimizer import Costimizer
from costimizer.otel import instrument
import openai

costimizer = Costimizer(project_token="fo_ingest_your_key")
instrument(costimizer, openai=True, trace_name="support-chat")

client = openai.OpenAI()
client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Hello"}],
)
costimizer.shutdown()

Optional tracking fields

All provider wrappers accept the same Costimizer-only kwargs:

Kwarg Purpose
costimizer_trace_name Label for dashboards
costimizer_trace_id Group related calls
costimizer_distinct_id User or session ID
costimizer_properties Custom metadata dict
costimizer_privacy_mode "metadata_only" (default) or "full_content"

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

costimizer-0.1.2.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

costimizer-0.1.2-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file costimizer-0.1.2.tar.gz.

File metadata

  • Download URL: costimizer-0.1.2.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for costimizer-0.1.2.tar.gz
Algorithm Hash digest
SHA256 60b8740203c00f1afdeda0769a649b97bf53362e55a0632ae5a8fa879acd1be2
MD5 6ba40101f4ecccb4d3f19b3783ba09d2
BLAKE2b-256 e269dbce3ca3a8130acb5e1b20c23020d5d10fe773bd19bb3bf1580b8d2653fa

See more details on using hashes here.

File details

Details for the file costimizer-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: costimizer-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 18.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for costimizer-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 86d7539471ee3d5c3e96f570e37538c28187a773137b139dd07866e60d0b8d5e
MD5 6664f664a17d6b890f59f20425479c9c
BLAKE2b-256 d4b1dbcfb7baa29246ce349f2c8c45add923bc1bb1d14d3d339e0cbf4e1750ea

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