Skip to main content

Validate Telnyx Key

Validates a Telnyx API key by making a lightweight phone number search request against the Telnyx API. Returns detailed validation results including account status information.

Endpoint

PropertyValue
Function Namevalidate-telnyx-key
HTTP MethodPOST
AuthenticationSupabase JWT (Bearer token)
Required RoleAny authenticated user

Request

Headers

Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json

Body

FieldTypeRequiredDescription
api_keystringYesThe Telnyx API key to validate (must be at least 20 characters)

Response

Valid Key (200)

{
"valid": true,
"account_info": {
"has_balance": true
}
}

Invalid Key (400)

{
"valid": false,
"error": "Invalid API key"
}

Error Responses

StatusCondition
400API key is missing, not a string, or shorter than 20 characters
400API key is invalid or lacks required permissions (returned from Telnyx)
401Missing or invalid authorization header
405HTTP method is not POST
500Internal server error during validation

Behavior

  • Authenticates the user via Supabase JWT
  • Validates the api_key field is present, is a string, and is at least 20 characters long
  • Makes a test request to GET https://api.telnyx.com/v2/available_phone_numbers?filter[country_code]=US&filter[limit]=1 using Bearer token authentication
  • Interprets the response:
    • HTTP 200: Key is valid and account is active
    • HTTP 401: Invalid API key
    • HTTP 403: API key lacks required permissions
    • HTTP 429: Rate limited, but key is valid (returns valid: true)
    • Other errors: Returns the Telnyx error detail message
  • Returns the validation result with a valid boolean and optional account_info or error
  • Does not store the key -- this is a validation-only function

External APIs Called

APIMethodEndpointPurpose
TelnyxGET/v2/available_phone_numbers?filter[country_code]=US&filter[limit]=1Lightweight test to verify API key validity