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.6.tar.gz (14.6 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.6-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: costimizer-0.1.6.tar.gz
  • Upload date:
  • Size: 14.6 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.6.tar.gz
Algorithm Hash digest
SHA256 de383f6dc1e203b397e4118268b6d6fb4a31d6feec324a00a6397092a5b08383
MD5 0825445ead604b249ba97fdd5d360423
BLAKE2b-256 42a92dcafa3505b42a904c29ac2a5e1f21234b7f2065b961455571b10676b8f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: costimizer-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 19.1 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c169d2c0374a80caa26666ecd210987c4432d4e9d872661a17c608d4015d498a
MD5 93ba008b81b52b86e892d64b1f081a44
BLAKE2b-256 956eb4e71d40ef4f6ee5aa5518acc3b2a584b8b68fa8f35e3f62d939d7ed70d5

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