semvec/pypi-packages huggingface dataset:
llm-price 0.1.3
Pricing + release metadata and cost estimation for LLMs
License: MIT
Requires Python: >=3.10

# llm-price

Pricing + release metadata and cost estimation for LLMs (OpenAI + Google Gemini).

## Features

- Model metadata with release dates
- Static pricing in **USD per 1M tokens**
- Cost estimation from **token counts or raw text**
- Any currency output (real-time FX from exchangerate.host, cached)
- CLI for listing models and summing JSONL usage

## Install

```bash
pip install llm-price
```

## Quickstart (Python)

```python
from decimal import Decimal

from llm_price import cost_from_text, cost_from_tokens, get_fx_rate, list_models

models = list_models("openai")
print(models[0])

cost = cost_from_text(
    "openai",
    "gpt-4o-mini",
    prompt="Summarize this text.",
    completion="Here is a summary...",
)
print(cost.total_cost)

cost_in_inr = cost_from_tokens(
    "google",
    "gemini-1.5-flash",
    prompt_tokens=120,
    completion_tokens=40,
    currency="INR",
    fx_rate=Decimal("83.12"),
)
print(cost_in_inr.total_cost)

live_fx = get_fx_rate("USD", "INR")
print("Live USD→INR:", live_fx)
```

## CLI

```bash
llm-price models --provider openai

llm-price cost \
  --provider openai \
  --model gpt-4o-mini \
  --prompt "Hello" \
  --completion "Hi" \
  --currency USD

llm-price cost \
  --provider google \
  --model gemini-1.5-flash \
  --prompt-tokens 100 \
  --completion-tokens 20 \
  --currency INR \
  --fx-rate "83.12"
```

## JSONL Summation

`llm-price sum usage.jsonl` supports lines with:

### Token counts

```json
{"provider":"openai","model":"gpt-4o-mini","prompt_tokens":1200,"completion_tokens":400}
```

### Raw text (tokenized internally)

```json
{"provider":"openai","model":"gpt-4o-mini","prompt":"Hello","completion":"Hi"}
```

### Pre-computed totals

```json
{"total_cost":{"amount":"0.0123","currency":"USD"}}
```

## Example Scripts

Run these from the repo root after installing dependencies:

```bash
python examples/basic_cost.py
python examples/inr_conversion.py
python examples/sum_jsonl.py
```

## Notes

- Pricing data is stored in `src/llm_price/data/models.json` in **USD per 1M tokens**.
- OpenAI pricing is refreshed daily from https://bes-dev.github.io/openai-pricing-api/pricing.json
  via a GitHub Actions workflow.
- OpenAI entries also store `cached_input_per_1m` when available.
- For non-USD output, FX defaults to a real-time rate from exchangerate.host.
- You can override it with `fx_rate` to use a fixed rate.
- Rates are cached in-process for 1 hour by default.
- Gemini token counting uses the official CountTokens API when `GOOGLE_API_KEY` is set; otherwise it falls back to an approximation.

## Development

```bash
pip install -e ".[dev]"
pytest
```

## Release (PyPI)

This project uses GitHub Actions trusted publishing. Create a tag like `v0.1.0`
and push it to GitHub to trigger the publish workflow:

```bash
git tag v0.1.0
git push origin v0.1.0
```

Configure the PyPI Trusted Publisher with:

- **PyPI Project Name**: `llm-price`
- **Owner**: `VA24d`
- **Repository name**: `API-price`
- **Workflow name**: `publish.yml`
- **Environment name**: `pypi`
sqzy 0.2.0
Compress JSON-like API responses before sending to LLMs.
License: MIT
Requires Python: >=3.8
Keywords: json, compression, llm, api, responses

# Sqzy

Sqzy removes irrelevant fields from JSON-like API responses before you send
them to LLMs. It drops nulls, blanks, and empty collections so the context
window is used for meaningful data.

## Install

```bash
pip install sqzy
```

## Quick start

```python
from sqzy import compress_json, compress_response

data = {
    "id": 123,
    "title": "  ",
    "summary": None,
    "tags": ["python", "", None, "llm"],
    "meta": {"page": 1, "next": None, "notes": ""},
}

print(compress_json(data))
# {'id': 123, 'tags': ['python', 'llm'], 'meta': {'page': 1}}
```

Decorator usage:

```python
import requests
from sqzy import compress_response

@compress_response()
def fetch_user(user_id: str):
    res = requests.get(f"https://api.example.com/users/{user_id}")
    return res.json()

clean = fetch_user("42")
```

## API

`compress_json(data, **options)` recursively removes:
- `None` values
- empty strings (including whitespace-only by default)
- empty lists and dicts

`compress_response(**options)` is a decorator that applies `compress_json` to
the return value of the wrapped function.

### Options

- `drop_null` (bool): remove `None` values (default `True`)
- `drop_empty_str` (bool): remove empty strings (default `True`)
- `drop_whitespace_only` (bool): remove strings with only whitespace (default `True`)
- `drop_empty_list` (bool): remove empty lists (default `True`)
- `drop_empty_dict` (bool): remove empty dicts (default `True`)
- `drop_empty_tuple` (bool): remove empty tuples (default `False`)
- `drop_empty_set` (bool): remove empty sets (default `False`)
- `preserve_keys` (set[str] or list[str]): keep values for specific keys
- `preserve_paths` (set[str] or list[str]): keep values for specific dotted paths

## Contributing

Issues and pull requests are welcome. See `CONTRIBUTING.md` for local setup.