Authentication All docs

API Key Authentication

Protected dataset endpoints need an API key in the x-api-key header. Keep the key on your server, not in browser code or a repository.

server.js
const res = await fetch('https://api.apifor.dev/v1/countries', {
  headers: { 'x-api-key': process.env.APIFOR_API_KEY },
});
const { data } = await res.json();

GET /v1/catalog and GET /v1/openapi.json are public and need no key. If a key leaks, rotate it in the dashboard.

A missing key returns HTTP 401 with this body:

401 · application/json
{
  "success": false,
  "error": {
    "code": "MISSING_API_KEY",
    "message": "x-api-key header is required"
  }
}