Quote catalog prices per 1,000 requests - #12
Merged
Conversation
The gateway publishes every static discovery price in two denominations: `maxUsd` for one request and `maxPer1kUsd` for 1,000 of them, with `failoverMaxPer1kUsd` twinning `failoverMaxUsd`. Per 1,000 requests is the denomination AnyAPI quotes customers in, because most of the catalog costs a fraction of a cent per call and per-request figures cannot be compared by eye. The discovery reader now requires both figures on every offer, so `anyapi describe` prints them and the `anyapi list` / `anyapi search` price column quotes the per-1k rate labeled `/1k req`. The rate is read from the wire and never scaled locally: `0.0966 * 1000` is `96.60000000000001`, and 20 of the 313 live catalog prices behave that way. Payable amounts stay per request. `costUsd` on a completed run and the wallet balance state what a specific call is charged rather than a comparison rate, so they get no per-1k twin. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
formatUsd pads sub-dollar amounts to four decimals because a per-request charge really is that small. A rate for a thousand requests is not: one credit is $0.00001 and lane prices are whole credits, so the rate is always a whole number of cents, and two decimals is exact rather than a rounding. Without this, the cheapest 39 of the catalog's 313 SKUs printed as `USD 0.9000/1k req`. The shared formatter is untouched, so balance and costUsd keep their per-request precision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The gateway publishes every static discovery price in two denominations:
maxUsd(USD billed for one request, unchanged) andmaxPer1kUsd(the same maximum per 1,000 requests), withfailoverMaxPer1kUsdtwinningfailoverMaxUsd. Lane-levelpricingcarriesmaxPer1kUsdtoo. Per 1,000 requests is what AnyAPI quotes customers, because most of the catalog costs a fraction of a cent per call and per-request figures cannot be compared by eye. The website, the gateway's MCP tool descriptions, and the canonical agent skill already quote per-1k and label it/1k req; this brings the CLI in line.What changed
src/types.ts-maxPer1kUsdon both offer shapes,failoverMaxPer1kUsdonDiscoveryPricing.src/discovery.ts- the handwritten discovery reader reads both fields and rejects an offer published without the per-1k rate, so a missing field is a loud contract error rather than a silently blank price.src/format.ts- the catalog price display quotesmaxPer1kUsdlabeled/1k req. A metered offer keeps its per-item rate per item, which is what the customer'slimitactually moves.Where the per-1k figure now appears
anyapi listandanyapi searchshare one price column, andanyapi describeprints the reader's projection, so all three now carry the rate. Live output against production:Read, never multiplied
0.0966 * 1000is96.60000000000001in JavaScript, and 20 of the 313 live catalog prices behave that way. The published field is read straight off the wire; nothing here scales a price by 1,000, and there was no pre-existing local scaling to replace.__tests__/discovery.test.tspins that withexpect(api.pricing.from.maxPer1kUsd).not.toBe(0.0966 * 1000)beside an exact96.6. Both new tests fail against the previous reader and formatter.Payable amounts deliberately left per request
costUsdon a completed run and the wallet balance state what a specific call is charged, not a comparison rate, so they stay per request and gained no per-1k twin. Putting a per-1k figure beside a payable amount invites acting on the wrong number. The CLI has no quote command, so there was nomaxCostUsd/minCostUsdoutput to leave alone.Gate
npm run build && npm testpasses: 10 files, 87 tests.npm run canary:livealso passes against production (313 catalog APIs), which confirms every live/catalog,/catalog/search,/public/try/*/schema, and/v1/apis/*response carries the fields the reader now requires.