Authentication
Authenticate requests to your mock endpoints using API keys.
Every request to your mock endpoints must include your project's API key. Mockspec supports three authentication methods:
X-API-Key Header (Recommended)
curl -X GET "https://api.mockspec.dev/mock/users" \
-H "X-API-Key: mk_your_api_key_here"TypeScript:
fetch("https://api.mockspec.dev/mock/users", {
headers: { "X-API-Key": "mk_your_api_key_here" }
});Bearer Token
curl -X GET "https://api.mockspec.dev/mock/users" \
-H "Authorization: Bearer mk_your_api_key_here"TypeScript:
fetch("https://api.mockspec.dev/mock/users", {
headers: { "Authorization": "Bearer mk_your_api_key_here" }
});Basic Auth
Use your API key as the username (password can be empty):
curl -X GET "https://api.mockspec.dev/mock/users" \
-H "Authorization: Basic $(echo -n 'mk_your_api_key_here:' | base64)"TypeScript:
const apiKey = "mk_your_api_key_here";
const encoded = btoa(`${apiKey}:`);
fetch("https://api.mockspec.dev/mock/users", {
headers: { "Authorization": `Basic ${encoded}` }
});Rotating API Keys
You can rotate your API key at any time from project settings. The old key is invalidated immediately - update your applications with the new key.
Need help? Contact support