Set up your own proxy
Build a thin service that authenticates your users, enforces your rules, forwards to Pikeway with your key, and records the cost of every call.
Create a key for the proxy
In Console → Keys, create a key used only by the proxy. Give it a spend limit as a backstop and, if your proxy has fixed egress IPs, an IP allowlist. Store it as PIKEWAY_API_KEY on the proxy host only.
Write the forwarding service
The proxy keeps Pikeway's paths, so /v1/* and /gw/* requests pass through unchanged. It swaps the user's credential for your key, forwards, and returns the upstream response as-is.
// proxy.mjs: a minimal Pikeway proxy (Node 18+). Run behind your own TLS.
import http from "node:http";
const UPSTREAM = "https://gw.pikeway.ai";
const KEY = process.env.PIKEWAY_API_KEY; // your proxy's own key; never sent to users
const ALLOW = /^\/(v1\/(discover|providers|run|runs)|gw\/(birdeye|coingecko))\b/;
http.createServer(async (req, res) => {
const user = await authenticate(req); // your sessions / API keys / SSO
if (!user) return send(res, 401, { error: "unauthorized" });
if (!ALLOW.test(req.url)) return send(res, 403, { error: "endpoint not allowed" });
if (!(await hasCredit(user))) return send(res, 402, { error: "top up your account" });
const body = ["GET", "HEAD"].includes(req.method) ? undefined : await readBody(req);
const up = await fetch(UPSTREAM + req.url, {
method: req.method,
headers: {
Authorization: `Bearer ${KEY}`,
"Content-Type": req.headers["content-type"] ?? "application/json",
// one key per logical call, so retries are never charged twice
...(req.headers["idempotency-key"] && { "Idempotency-Key": `${user.id}:${req.headers["idempotency-key"]}` }),
},
body,
});
const callId = up.headers.get("X-Pikeway-Call-Id");
const cost = Number(up.headers.get("X-Pikeway-Cost") ?? 0);
if (callId) await recordUsage({ userId: user.id, callId, cost, price: cost * 1.2 }); // your markup
res.writeHead(up.status, { "Content-Type": up.headers.get("content-type") ?? "application/json" });
res.end(Buffer.from(await up.arrayBuffer()));
}).listen(8080);
const send = (res, s, j) => { res.writeHead(s, { "Content-Type": "application/json" }); res.end(JSON.stringify(j)); };
const readBody = (req) => new Promise((ok) => { const c = []; req.on("data", (d) => c.push(d)).on("end", () => ok(Buffer.concat(c))); });authenticate, hasCredit and recordUsage are yours: plug in your user store and billing.
Decide what users can reach
- Allow-list paths and providers (the
ALLOWpattern above). Everything else gets403before it costs you anything. - Optionally inject or strip parameters, e.g. force a chain or cap a page size, before forwarding.
- Rate-limit and quota per user on your side; the key's spend limit is only the last line of defense.
Record the cost of every call
Pikeway reports what each call cost on the response. Store it against the user, then charge whatever you like.
| Header | Meaning |
|---|---|
X-Pikeway-Call-Id | Unique id of the call; the same id appears in your Pikeway ledger and call logs. |
X-Pikeway-Cost | USD charged to your balance for this call. Only 2xx responses are billed; others report 0. |
X-Pikeway-Cache | Present when the response was served from cache. |
Pass an Idempotency-Key per logical call (scoped by user, as above). The same key on the same Pikeway key is forwarded and charged only once, so your retries are safe.
Point clients at the proxy
The Pikeway CLI, SDKs and Skill read PIKEWAY_API_BASE_URL, so they work against your proxy with no code changes.
# Point any Pikeway client at your proxy instead of Pikeway
export PIKEWAY_API_BASE_URL=https://pikeway-proxy.acme.example
export PIKEWAY_API_KEY=acme_user_token_… # your token, checked by your proxy
pikeway discover -q "token price" # → your proxy → Pikeway
pikeway run -p birdeye -e /defi/price -i '{"address":"So111…112"}'Reconcile against your Pikeway ledger
Periodically pull your balance activity and match it to your usage table by call id. Any id you can't match is a call that bypassed your bookkeeping.
# Every charge on your Pikeway balance, newest first (paginate with nextCursor) curl "https://gw.pikeway.ai/v1/wallet/activities?limit=100" \ -H "Authorization: Bearer $PIKEWAY_API_KEY"
/v1/runs/:id through the proxy.