Reference
Error Codes Complete reference of all error codes returned by the HMS Sovereign API with explanations and recommended actions.
This reference lists all error codes returned by the HMS Sovereign API with explanations and recommended actions.
Code Name Description 200OK Request succeeded 201Created Resource created successfully 204No Content Request succeeded, no content returned (delete operations)
Code Name Description 400Bad Request Invalid request format or validation error 401Unauthorized Missing or invalid API key 402Payment Required Insufficient credits balance 403Forbidden Valid API key but no access to this resource 404Not Found Resource doesn't exist 409Conflict The request clashes with the current state: either the resource already exists (a phone number, a domain), or it is still in use and cannot be deleted — deleting a workflow that phone numbers still run returns 409 until you detach them 422Unprocessable Entity Request understood but cannot be processed 429Too Many Requests Rate limit exceeded
Code Name Description 500Internal Server Error Unexpected server error 502Bad Gateway Upstream service unavailable 503Service Unavailable Server temporarily unavailable 504Gateway Timeout Upstream service timeout
All errors follow this format:
{
"error" : {
"code" : "error_code" ,
"message" : "Human readable message" ,
"param" : "field_name" ,
"type" : "error_type"
}
}
Field Description codeMachine-readable error code messageHuman-readable description paramThe field that caused the error (if applicable) typeError category
Code Message Solution unauthorizedInvalid or missing API key Check your API key is correct and included in the Authorization header api_key_expiredAPI key has expired Generate a new API key in the dashboard api_key_revokedAPI key has been revoked Generate a new API key
Code Message Solution invalid_requestRequest body is invalid Check JSON syntax and required fields missing_fieldMissing required field Include all required fields invalid_fieldField value is invalid Check field format (e.g., E.164 for phone numbers) invalid_phone_numberPhone number format invalid Use E.164 format: +31612345678 invalid_uuidInvalid UUID format Provide a valid UUID invalid_urlInvalid URL format Provide a valid HTTPS URL
Code Message Solution not_foundResource not found Verify the resource ID exists already_existsResource already exists The phone number or resource is already registered conflictResource conflict Another resource is using this identifier
Code Message Solution insufficient_creditsInsufficient credits balance Add credits in the billing dashboard payment_requiredPayment required Add credits to make outbound calls
Code Message Solution rate_limit_exceededToo many requests Wait and retry with exponential backoff call_control_limitToo many call control commands Limit to 10 commands per minute per call
Code Message Solution provider_errorExternal provider error Check BYOK configuration and provider status provider_timeoutProvider request timeout Retry the request invalid_api_keyBYOK API key invalid Update the API key via BYOK endpoint
Code Message Solution call_not_foundCall not found Verify the call ID call_not_activeCall is not in-progress Call control only works on active calls invalid_destinationInvalid destination number Check phone number format
async function callApi ( endpoint , options = {}) {
const response = await fetch ( `https://api.hmsovereign.com/api/v1${ endpoint }` , {
... options,
headers: {
'Authorization' : `Bearer ${ API_KEY }` ,
'Content-Type' : 'application/json' ,
... options.headers
}
});
if ( ! response.ok) {
const error = await response. json ();
switch (response.status) {
case 401 :
throw new Error ( 'Invalid API key. Check your credentials.' );
case 402 :
throw new Error ( 'Insufficient credits. Add credits to continue.' );
case 404 :
throw new Error ( `Resource not found: ${ error . error ?. message }` );
case 429 :
// Implement retry with backoff
const retryAfter = response.headers. get ( 'Retry-After' ) || 60 ;
throw new Error ( `Rate limited. Retry after ${ retryAfter } seconds.` );
default :
throw new Error (error.error?.message || 'Unknown error' );
}
}
return response. json ();
}
For transient errors (429, 502, 503, 504), implement exponential backoff:
async function retryWithBackoff ( fn , maxRetries = 3 ) {
for ( let i = 0 ; i < maxRetries; i ++ ) {
try {
return await fn ();
} catch (error) {
if (i === maxRetries - 1 ) throw error;
const delay = Math. min ( 1000 * Math. pow ( 2 , i), 30000 );
await new Promise ( resolve => setTimeout (resolve, delay));
}
}
}