Using the API
Errors
A failed request returns a JSON body with the HTTP status, a short name and a message written for a person. Some errors add a machine-readable code; branch on statusCode and code, not on the message text, which can change.
{
"statusCode": 403,
"error": "Forbidden",
"code": "plan_required",
"message": "This dataset is available on Builder, Commercial and Enterprise plans. See https://cryptoetf.today/en/pricing"
}| Status | code | When | What to do |
|---|---|---|---|
400 | — | Unsupported {asset}, or an unknown ?table= in a CSV request. The message lists the accepted values. | Fix the parameter; retrying the same request will fail again. |
401 | — | The key is missing, unknown or revoked. | Send the key as Authorization: Bearer <key> or X-API-Key; check it in the developer console. |
403 | plan_required | A Free key asked for a paid dataset or for ?format=csv. | Upgrade the plan or use the free endpoints. |
403 | api_key_suspended | The key is suspended, usually because the project details are missing. | Complete the profile in the developer console or contact support. |
404 | — | Unknown fund ticker or filing slug. | Take valid tickers from /v1/funds. |
429 | — | More requests in the current minute than the plan allows: 60 on Free, 300 on Builder and Commercial. | Wait the number of seconds in Retry-After, then retry. |
Handling rate limits
Every response carries X-RateLimit-Remaining, so a client can slow down before it hits the limit. When a 429 does come back, the SDKs raise CryptoETFError with status and the wait in seconds (retryAfter in JavaScript, retry_after in Python). They do not retry on their own.
import { CryptoETF, CryptoETFError } from "cryptoetf";
const etf = new CryptoETF();
async function withRetry(call) {
try {
return await call();
} catch (e) {
if (e instanceof CryptoETFError && e.status === 429) {
await new Promise((r) => setTimeout(r, (e.retryAfter ?? 60) * 1000));
return call();
}
throw e;
}
}
const { days } = await withRetry(() => etf.flows.asset("btc"));import time
from cryptoetf import CryptoETF, CryptoETFError
etf = CryptoETF()
try:
data = etf.flows.asset("btc")
except CryptoETFError as e:
if e.status != 429:
raise
time.sleep(e.retry_after or 60)
data = etf.flows.asset("btc")Without an SDK, read the header yourself:
curl -i https://api.cryptoetf.today/v1/flows/btc -H "Authorization: Bearer $CRYPTOETF_API_KEY"
# HTTP/2 429
# retry-after: 17