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
| Property | Value |
|---|---|
| Function Name | validate-telnyx-key |
| HTTP Method | POST |
| Authentication | Supabase JWT (Bearer token) |
| Required Role | Any authenticated user |
Request
Headers
Authorization: Bearer <supabase_jwt_token>
Content-Type: application/json
Body
| Field | Type | Required | Description |
|---|---|---|---|
api_key | string | Yes | The 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
| Status | Condition |
|---|---|
| 400 | API key is missing, not a string, or shorter than 20 characters |
| 400 | API key is invalid or lacks required permissions (returned from Telnyx) |
| 401 | Missing or invalid authorization header |
| 405 | HTTP method is not POST |
| 500 | Internal server error during validation |
Behavior
- Authenticates the user via Supabase JWT
- Validates the
api_keyfield 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]=1using 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
validboolean and optionalaccount_infoorerror - Does not store the key -- this is a validation-only function
External APIs Called
| API | Method | Endpoint | Purpose |
|---|---|---|---|
| Telnyx | GET | /v2/available_phone_numbers?filter[country_code]=US&filter[limit]=1 | Lightweight test to verify API key validity |
Related Functions
- Store Telnyx Credentials -- Validate and store Telnyx API keys
- Validate Ultravox Key -- Validate an Ultravox API key