Skip to main content

Python client for ModelPricing.ai cost estimates

Project description

modelpricing-ai

Python client for the ModelPricing.ai API.

Installation

pip install modelpricing-ai

Usage (sync, typed)

from modelpricing_ai import ModelPricingClient

client = ModelPricingClient(api_key="YOUR_API_KEY")

estimate = client.estimate(
    model="gpt-4o-mini",
    tokens_in=125000,
    tokens_out=42000,
    trace_id={"requestId": "abc-123"},
)
print(estimate.total)  # total USD cost
  • Base URL: https://api.modelpricing.ai
  • Auth: Authorization: Bearer <API_KEY>
  • Endpoint: POST /v1/estimate
  • Request body:
{
    "metrics": { "tokensIn": 1000, "tokensOut": 2000 },
    "model": "<model-name>",
    "traceId": { "...": "..." }
}

Error handling

  • 401 Unauthorized: invalid or missing API key
  • 422 Unprocessable Entity: validation error (e.g., invalid model or metrics)
  • Other 4xx/5xx: raised as a generic server error

License

MIT

Async usage (typed)

import asyncio
from modelpricing_ai import AsyncModelPricingClient

async def main():
    client = AsyncModelPricingClient(api_key="YOUR_API_KEY")
    estimate = await client.estimate(
        model="gpt-4o-mini",
        tokens_in=125000,
        tokens_out=42000,
        trace_id={"requestId": "abc-123"},
    )
    print(estimate.total)  # total USD cost

asyncio.run(main())

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

modelpricing_ai-0.0.1a0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

modelpricing_ai-0.0.1a0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file modelpricing_ai-0.0.1a0.tar.gz.

File metadata

  • Download URL: modelpricing_ai-0.0.1a0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for modelpricing_ai-0.0.1a0.tar.gz
Algorithm Hash digest
SHA256 aafe055cdcc5acf6b4c397af2201297d2a6453ed8af2d70b6a56c468c54df702
MD5 7ff1cfe3a1be8ea168021bada8c48d15
BLAKE2b-256 045e6ccaf8998a8b1113d88279f54828c12fab53ccd3c6128c2f5f93f80bd879

See more details on using hashes here.

File details

Details for the file modelpricing_ai-0.0.1a0-py3-none-any.whl.

File metadata

File hashes

Hashes for modelpricing_ai-0.0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 efee0ab0ae9694aedef7b5c9464b23ef916466f27f3b783dc49c043f83600822
MD5 29e70c6ca8d798ca15eff4343a86f0e0
BLAKE2b-256 92261d8ea3220dc07d54c885c40f3ae28f2df10910d9901e8185562764917604

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