SDK Reference
OpenAI Provider
Drop-in replacement for openai.OpenAI. Wraps chat.completions.create() with automatic cost capture.
Usage
# Before
from openai import OpenAI
# After
from kostrack import OpenAI
client = OpenAI(
tags={"project": "openmanagr", "feature": "gl-classification"}
)
response = client.chat.completions.create(
model="gpt-4o",
max_tokens=512,
messages=[{"role": "user", "content": "Classify this transaction..."}],
)
Streaming
Kostrack automatically injects stream_options={"include_usage": True} into streaming requests so token counts are captured from the final chunk:
for chunk in client.chat.completions.create(
model="gpt-4o", stream=True, messages=[...]
):
print(chunk.choices[0].delta.content, end="")
Supported models
| Model | Input / 1M | Output / 1M | Cached input / 1M |
|---|---|---|---|
| gpt-4o | $2.50 | $10.00 | $1.25 |
| gpt-4o-mini | $0.15 | $0.60 | $0.075 |
| o1 | $15.00 | $60.00 | $7.50 |
| o3-mini | $1.10 | $4.40 | $0.55 |
Token breakdown
| Field | Description |
|---|---|
input_tokens | prompt_tokens from the response |
output_tokens | completion_tokens from the response |
cached_tokens | Cached prompt tokens (50% discount applied) |
token_breakdown.reasoning_tokens | Reasoning tokens for o1/o3 models |