Skip to main content

Price GraphQL queries before you run them: calibrate a live API into a static pricing pack, then quote any query offline.

Project description

costQL

CI

Price GraphQL queries before you run them. costQL calibrates a live GraphQL API into a pricing pack, one self-contained JSON file, then quotes any query against that pack fully offline. No server, no network, no measurement.

pip install costql        # Python: build packs + quote
npm install costql        # JS/TS: quote packs (build stays in Python)

60 seconds to a quote (offline)

from costql import PricingPack

pack = PricingPack.demo("tmdb_t3")   # a demo pack bundled in the package
quote = pack.quote('{ movie(id:"27205"){ cast(limit:8){ person{ name } } } }')

quote["price"]        # safe billable ceiling, in cost-units (never dollars)
quote["typical_price"]# fair average estimate
quote["confidence"]   # high | medium | low: cyclic queries are flagged, not billed

Or from the command line:

costql quote --demo tmdb_t3 '{ movie(id:"27205"){ title } }'

(Quoting your own API? Build a pack with costql build and pass it with --pack your_pack.json. The bundled --demo pack is just for the tour.)

Every result follows a frozen output contract (v1.0): price is always present, always a number, always safe to bill on. See docs/contract.md.

How it works

  1. Build (seller side, once per schema): run costql probe <url> to see what your endpoint supports, write a ~90-line adapter that tells costQL where your API is and how to fill in its arguments (or hand that job to a coding agent: see docs/agents.md), then run costql build. costQL introspects the schema, measures a set of clean calibration queries, and fits a per-resolver cost model.
  2. Ship the pack: the output is one static file (schema + fitted costs + any observed outside hosts). Vendor it into any app.
  3. Quote (app side, forever): load the pack, price queries locally; in Python or JavaScript.

One currency, three fidelities

costQL prices in work-ms, the summed duration of the real work a query causes. Three fidelities of one engine, set by how much your API's instrumentation exposes:

Tier Needs Sees Blur it removes
T1 nothing: any GraphQL endpoint you can query whole-request wall-clock none; always available
T2 server emits per-resolver timings each resolver's own work-ms parallelism no longer hides work
T3 server also emits loader keys/cache status sharing observed exactly; batch curves learned; paid hosts named nothing hidden

Honesty first: T1 works black-box against any GraphQL API: the Rick & Morty case study hit ~4% mean error with a 93-line adapter and zero server changes. T2/T3 require your server to emit costQL's cost-trace extension; the demo packs are mostly T3 because we instrumented the demo servers. Your first pack will be T1: that is the designed starting point, and it already gives you a safe billable ceiling.

Measured accuracy

On held-out queries against real backends (methodology in docs/evaluation.md: calibration and evaluation sets are disjoint; there is no query→price lookup):

  • TMDB demo (instrumented): mean error T1 17% / T2 11% / T3 11%
  • Rick & Morty (public API, not ours): ~4% mean error at T1, ceiling never under the real cost
  • Northwind (batch-heavy SQLite): heavy entity sharing is where T3 pays: T2 315% vs T3 12% on hub queries (case study)

Cyclic-recursion queries (whose runtime dedup is unknowable pre-execution) are automatically flagged low confidence and priced as a structural ceiling. Flagged, not silently billed.

What costQL is not

  • Not a service. The pack is static and local by design: no sidecar, no pricing endpoint, no extra API call.
  • Not billing. costQL speaks cost-units, never dollars; converting to money is the consuming app's job.
  • Not a rate limiter. It prices; what you do with the price is up to you.

Docs

Quickstart, the adapter guide, tier fidelity, the output contract, evaluation methodology, and an interactive playground: https://costql.com

License

Apache-2.0

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

costql-0.1.0.tar.gz (58.8 kB view details)

Uploaded Source

Built Distribution

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

costql-0.1.0-py3-none-any.whl (65.9 kB view details)

Uploaded Python 3

File details

Details for the file costql-0.1.0.tar.gz.

File metadata

  • Download URL: costql-0.1.0.tar.gz
  • Upload date:
  • Size: 58.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for costql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9b27ffb39c3c4606ea4a6bc03f6722f15128391e0dcafa80d1ae5a5cadc2799a
MD5 4794cca7c898d828f8a2eb8785ea99bb
BLAKE2b-256 b5eac6a9796984e726dfa71facfa029fd304cc49782e6fabc711e579e77fccae

See more details on using hashes here.

Provenance

The following attestation bundles were made for costql-0.1.0.tar.gz:

Publisher: release.yml on shapemachine/costql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file costql-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: costql-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 65.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for costql-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 889264366a82c86b8d7467be99b77a23fbfe30780857133e39618224b77bf744
MD5 d2d51697e2113c4609a72027c739fb9b
BLAKE2b-256 fee2886a55317da36457e1649479b8b5c07b7f8b9c693612d59601616e45af81

See more details on using hashes here.

Provenance

The following attestation bundles were made for costql-0.1.0-py3-none-any.whl:

Publisher: release.yml on shapemachine/costql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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