UNAUTHORIZED — Missing or invalid API key
Summary
Section titled “Summary”The request reached the API but didn’t include a valid key in the x-api-key header. The most common cause is sending the key in Authorization: Bearer ... instead, or omitting the header entirely.
HTTP status
Section titled “HTTP status”401 Unauthorized. Standard envelope.
Example response
Section titled “Example response”{ "success": false, "error": { "code": "UNAUTHORIZED", "message": "Missing or invalid API key. Pass it in the x-api-key header.", "request_id": "req_01HXJZK4ABCDEF", "doc_url": "https://docs.surveycoder.io/errors/unauthorized" }}Why this happens
Section titled “Why this happens”- The
x-api-keyheader is missing. - The key was sent as
Authorization: Bearer ...(we don’t accept that — keys go inx-api-key). - The key value is malformed (must start with
scp_live_orscp_test_). - A proxy or middleware stripped the custom header before the request hit our edge.
How to fix it
Section titled “How to fix it”- Confirm the header name is exactly
x-api-key(lowercase by convention, but case-insensitive on our side). - Confirm the value starts with
scp_live_(production) orscp_test_(testing) and is 40+ characters long. - If you use a fetch wrapper or HTTP client with
Authorization-only defaults, setx-api-keyexplicitly:
curl https://api.surveycoder.io/v1/usage \ -H "x-api-key: $SCP_API_KEY"await fetch('https://api.surveycoder.io/v1/usage', { headers: { 'x-api-key': process.env.SCP_API_KEY! },});Related
Section titled “Related”AUTH_ERROR— key looks valid but couldn’t be resolvedKEY_REVOKEDKEY_EXPIRED