Skip to content
Sparecycle

API keys

An API key pays for jobs from your wallet's prepaid balance in the payments contract, without a wallet signature per job. Each key has its own daily cap and can be switched off at once. A key can never withdraw: withdrawals stay a wallet-only, on-chain action, and what you have not spent stays withdrawable by your wallet. The same keys work with the OpenAI-compatible API and the MCP server.

Create a key

The easy way: open Submit a job, connect the wallet you pay from, sign in (a signature, no gas), and use the API keys panel. Creating a key asks your wallet to sign one message; the key is then shown once. Copy it right away: Sparecycle stores only its SHA-256 hash and cannot show it again.

A key looks like sck_<keyId>_<secret>: keyId is 16 hex characters (shown in the panel, not secret), the secret is 43 base64url characters. Send it as Authorization: Bearer sck_….

The message your wallet signs (EIP-191, personal_sign) names the key, its fingerprint (the first 16 hex characters of SHA-256 of the full key) and its cap:

Link message
Sparecycle: allow one API key to pay for jobs from my balance
Chain: 4663
Payments contract: 0x420716931e5ff2a984840c6e95837d826a8be7eb
Key: sck_<keyId>
Key fingerprint: <first 16 hex of sha256(full key)>
Daily cap: <wei> wei per UTC day
Issued: <unix seconds>
This key cannot withdraw. Revoke it at any time.

Plain wallets, ERC-1271 smart wallets and ERC-6492 (not yet deployed) smart wallets are accepted, the same way as the sign-in. A key that is not signed within 10 minutes expires; create a new one.

Daily cap and the on-chain spend limit

Each key has a daily cap in wei. A job counts against the cap of the UTC day it was submitted on; caps reset at 00:00 UTC (08:00 WITA).D12: default, not yet confirmed A job that would go over the cap is refused with 429 key-daily-cap and nothing is queued. A job that ends without agreement (results did not match, no verdict in time, or a rejected image) is never charged and gives its price back to the key's counter.

Lowering a cap, disabling and deleting need only your sign-in. Raising a cap needs a new signature over a link message with the new cap.A3: default, not yet confirmed

Set a spend limit per epoch. The daily cap is enforced by the Sparecycle scheduler. The only ceiling that does not depend on the scheduler is the spend limit per epoch in the payments contract (setSpendLimit, in Your balance on Submit a job). Its default is 0, which means no limit; the keys panel warns while it is 0. A2: default, not yet confirmed

Turn a key off

Disable, delete, or disable all keys from the panel or the API below. It takes effect on the next request: the key is refused with 401. Jobs of that key that are still queued (no node has started them) end as expired with the note cancelled: API key disabled and are never charged. Jobs already running settle normally.

Pay for a job with a key

Send the job request itself to POST /api/v1/jobs, without a payment block. The price is the same as for a wallet-signed job (work units times the price per unit) and the same available-balance check applies. Paid jobs per wallet are limited to 120 per hour, keys included.

curl
curl -s https://sparecycle.tech/api/v1/jobs \
  -H "Authorization: Bearer $SPARECYCLE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"kind":"text","params":{"model":"qwen2.5-1.5b","prompt":"Name three colours.","maxTokens":64}}'

# 201 {"id":"0x…","status":"queued","priceWei":"…"}   (no readSecret: read it with the key)

curl -s https://sparecycle.tech/api/v1/jobs/0x…/result -H "Authorization: Bearer $SPARECYCLE_API_KEY"

A key reads the results of the jobs submitted with that key only, not other jobs of the same wallet (403).A5: default, not yet confirmed Your wallet sign-in still reads every job your wallet paid for. Jobs paid with a key get no per-job read secret.A4: default, not yet confirmed

For text and images in the OpenAI format, use the OpenAI-compatible API; for agents, the MCP server.

What a key changes, and what it cannot do

  • A key can submit and read jobs. It cannot withdraw, cannot change your spend limit, and cannot create or manage keys.
  • The payments contract never sees per-job signatures; it lets the scheduler key charge you up to your balance and your spend limit per epoch, with or without a key. What a key changes is the evidence: for key-paid jobs, the proof that you wanted a job is your one link signature plus the scheduler's records.
  • The scheduler records which key paid for each job, and the key list shows what each key spent today. Charge lists published before job receipts name each charged job with its apiKeyId (/api/v1/epochs/<id>/charges); later ones publish only each wallet's total and the leaves of the jobs tree. Each job's invoice and receipt stay private to you.
  • Anyone holding a key can spend up to its daily cap. Keep keys out of code repositories and browsers; turn a key off as soon as it may have leaked.

Keys pay without a per-job signature after one link signature. D11: default, not yet confirmed A wallet can hold at most 10 active or pending keys. D13: default, not yet confirmed

Managing keys over HTTP

The panel uses these routes; scripts can too. They need the wallet session cookie sc_session from the sign-in (GET /api/v1/auth/nonce, then POST /api/v1/auth/verify with an EIP-4361 message); an API key is not accepted here. Without a session they answer an empty 401. Every answer is Cache-Control: private, no-store.

RouteBodyAnswer
GET /api/v1/keysowner, keys (label, prefix, fingerprint, status, dailyCapWei, spentTodayWei, nextResetAt, …)
POST /api/v1/keys{ label?, dailyCapWei }201: keyId, fingerprint, linkMessage, issued (pending; no secret)
POST /api/v1/keys/:id/activate{ signature }the full key in key, shown once
PATCH /api/v1/keys/:id{ label?, dailyCapWei?, status?: "active" | "disabled" }the key; raising the cap first answers 409 link-signature-required with linkMessage and issued: sign it and send { dailyCapWei, issued, signature }
DELETE /api/v1/keys/:idok; queued jobs cancelled (cancelledJobs)
POST /api/v1/keys/disable-alldisabled, cancelledJobs

Limits: 30 key creations per wallet per hour; 3600 job reads per key per hour on the OpenAI-compatible and MCP routes.

Errors

StatuserrorWhen
401invalid-api-keyunknown, disabled or deleted key, or a wrong secret
402insufficient-balanceyour available balance (balance minus held and pending withdrawal) is below the price
429key-daily-capthe job would take the key over its cap for today (UTC); resetsAt says when it resets
429rate-limitedmore than 120 paid jobs per hour from one wallet
409max-keysthe wallet already has 10 active or pending keys
400bad-link-signaturethe signature is not from the signed-in wallet over that link message
410pending-key-expiredthe key was not signed in time; create a new one