Start here › Check your key and plan
Check your key and plan
Which plan the key is on, what it reads, its rate limit and what it has used this month. Every tool should print this first.
<?php
// Check your key and plan
const BASE = "https://api.apihorseracing.com";
function get(string $path, array $params = []): array
{
$url = BASE . $path . ($params ? "?" . http_build_query($params) : "");
$ctx = stream_context_create(["http" => [
"header" => "X-API-Key: " . getenv("AHR_KEY"),
"ignore_errors" => true,
]]);
$body = json_decode(file_get_contents($url, false, $ctx), true);
if (isset($body["error"])) {
throw new RuntimeException($body["error"]["code"] . ": " . $body["error"]["message"]);
}
return $body["data"];
}
$data = get("/v1/account/usage");
echo "Plan: ", $data["plan"]["name"] ?? "", "\n";
echo "Reads: ", $data["plan"]["window"] ?? "", "\n";
echo "Rate limit: ", $data["plan"]["rate_limit"] ?? "", "\n";
echo "Used this month: ", $data["this_month"]["requests"] ?? "", "\n";
What the reply holds
- plan.name
- The plan the key is on.
- plan.window
- The dates it reads.
- plan.rate_limit
- Calls a minute.
- this_month.requests
- Calls made this month.
- refused
- Calls your plan could not reach, by address.
When it says no
401no_key The key is missing or mistyped. Every sample reads it from AHR_KEY.403plan_needed Your plan does not reach this. The reply names the plan that does.429rate_limited Too fast. Wait the seconds in Retry-After, then try again.