Resellers as upstreams
In short
- A reseller is an upstream with its own cost and daily capacity.
- You pay its cost plus the savings fee, never above list.
- Only fixture resellers on this machine.
Fixture only. A reseller can only be a fixture server on this machine: the reseller transport refuses every host that is not loopback. Pointing one at a real reseller is a live-spend change and is blocked by AGENTS.md.
A reseller is any service that sells Claude tokens in the Anthropic Messages format or the OpenAI Chat Completions format (Surplus-style token markets, OpenRouter-style resellers). Each one becomes an ordinary upstream: it goes through the same routing, capacity holds, failover, stale-hold sweeper and 2% seller re-checks as the direct upstreams.
Config
Set PETROVA_RESELLERS_FILE to a JSON file, and each reseller's key in the variable it names:
{
"resellers": [
{
"name": "surplus-a",
"format": "anthropic",
"base_url": "http://127.0.0.1:9101",
"key_env": "SURPLUS_A_KEY",
"trust": "standard",
"capacity_per_day_nusd": "50000000000",
"models": {
"claude-sonnet-5-5": {
"upstream_model": "claude-sonnet-5-5",
"input_per_mtok_nusd": "1000000000",
"output_per_mtok_nusd": "5000000000",
"cache_read_per_mtok_nusd": "50000000",
"cache_write_5m_per_mtok_nusd": "1250000000",
"cache_write_1h_per_mtok_nusd": "2000000000"
}
}
}
]
}
format:anthropic(POST<base_url>/v1/messages, key asx-api-key) oropenai(POST<base_url>/chat/completions, key as a bearer token; translated both ways like Venice).base_url: https, or http on loopback.models: keyed by the catalog model id. The five prices are our cost per million tokens, in nano-USD, each above zero.upstream_modelis the id the reseller uses (default: the same).capacity_per_day_nusd: how much of the reseller's cost we may use per UTC day. Today's capacity row is created at that limit the first time it is needed; an operator can still change a day's row withsetSupplierCapacity.trust:highorstandardresellers are tried before direct;lowones only after direct fails. Re-check sampling: 10% forlow, 2% forstandardandhigh.
The key is held in memory only and never logged.
Money
- The customer pays list. The charge is the existing catalog price for the call's usage plus Petrova's fee (
usageCostNusd+feeNusd), as on the direct route. The quote and hold are unchanged. - Pay per call. There is no prepaid inventory. The reseller's cost for exactly this call is booked as
supplier_payableand written inreseller_calls(list, cost, charged, margin). The settlement'ssupplier_nusdis that cost, so reconciliation against the reseller's invoice works as usual. The margin is booked asplatform_revenue. - Never below cost, refused at startup. If any configured price is above our list price for that token category (the model's cheapest tier), the server does not start.
- Not chosen when the margin is too thin. Per call, a reseller is skipped when its cost ceiling for the request plus our fee is above the list ceiling for the same request. A model the reseller does not sell is skipped too.
- Capacity is held at the reseller's own cost ceiling and settled at its actual cost.
Failover
Order is [high/standard resellers] → [direct upstreams] → [low-trust resellers], with session affinity first as before. A reseller that answers 429/5xx or an overloaded stream event before content is skipped, its capacity freed, and the next upstream tried. A reseller out of capacity for the day is skipped. A suspended reseller (a failed seller re-check) is never routed to, and its charged calls in the last 24 hours are refunded.
Tests
tests/fixtures/reseller-server.ts starts one Anthropic-format and one OpenAI-format fixture reseller on loopback. tests/integration/resellers.test.ts and tests/unit/resellers.test.ts cover pricing, refusal at startup, routing, failover both ways, capacity, re-checks and reconciliation.
Last checked against the code: 16 November 2026. Something wrong? The source of this page is in the repository, so a fix is one edit.