Setting Your API Key
Set theTELNYX_API_KEY environment variable:
Verify Authentication
Test that your credentials are working by running any command:Getting Your API Key
- Log in to the Telnyx Portal
- Navigate to API Keys
- Click Create API Key
- Copy the key (it won’t be shown again)
API keys start with
KEY_. If you’re using a v1 API key (starting with a different prefix), you’ll need to create a new v2 key.Multiple Accounts
If you work with multiple Telnyx accounts (e.g., production and staging), you have several options:Option 1: Shell Aliases
Create aliases for different accounts:Option 2: Separate Terminal Sessions
Set different API keys in different terminal windows:Option 3: Inline Override
Override the API key for a single command:CI/CD Integration
GitHub Actions
GitLab CI
Shell Scripts
Security Best Practices
Never commit API keys to version control
Never commit API keys to version control
Use environment variables or secrets management. Add
.env files to .gitignore.Use separate keys for environments
Use separate keys for environments
Create different API keys for production, staging, and development. This limits blast radius if a key is compromised.
Rotate keys periodically
Rotate keys periodically
Regenerate API keys periodically and update your configurations.
Use secrets managers in CI/CD
Use secrets managers in CI/CD
Store API keys in GitHub Secrets, GitLab CI Variables, AWS Secrets Manager, HashiCorp Vault, etc.
Troubleshooting
”Unauthorized” Error
- Verify your API key is set:
echo $TELNYX_API_KEY - Check if the key starts with
KEY_ - Verify the key hasn’t been revoked in the Portal
- Ensure there are no extra spaces or characters in the key
”No API key” Error
Solutions:- Set the environment variable:
export TELNYX_API_KEY=KEY_xxx - Check for typos in the variable name
- Ensure the variable is exported (not just set)