Why Multiple Auth Methods?
Different environments call for different authentication approaches:| Method | Best For | Trade-offs |
|---|---|---|
| Config file | Local development | Persistent, convenient; tied to your machine |
| Environment variable | CI/CD, containers, scripts | Portable, no file needed; must be set each session |
| Command-line flag | Quick one-off commands | Immediate; exposes key in shell history |
Authentication Methods
1. Interactive Setup (Recommended)
The easiest way to configure authentication:~/.config/telnyx/config.json.
2. Environment Variable
Set your API key as an environment variable:- CI/CD pipelines
- Containerized environments
- Temporary overrides
3. Command-Line Flag
Pass the API key directly (not recommended for scripts):Verify Authentication
Check your current authentication status:Multiple Profiles
Use named profiles to manage multiple Telnyx accounts or environments (production, staging, development).When to Use Profiles
Profiles solve common multi-environment challenges:- Separate accounts — If your company has distinct Telnyx accounts for different business units or clients
- Environment isolation — Keep production and staging API keys separate to prevent accidents
- Team workflows — Share profile names (not keys) so scripts work across team members’ machines
Create a Profile
List Profiles
Use a Profile
Specify the profile for any command:Set Default Profile
Delete a Profile
Configuration File
The CLI stores configuration in~/.config/telnyx/config.json:
Environment Variables
| Variable | Description |
|---|---|
TELNYX_API_KEY | API key (overrides config file) |
TELNYX_PROFILE | Default profile name |
TELNYX_CONFIG_DIR | Custom config directory |
Example: CI/CD Usage
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.Security Best Practices
Use environment variables in CI/CD
Use environment variables in CI/CD
Never commit API keys to version control. Use secrets management in your CI/CD platform.
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.
Restrict file permissions
Restrict file permissions
The config file should only be readable by your user:
Troubleshooting
”Unauthorized” Error
- Verify your API key is correct:
telnyx auth status - Check if the key has been revoked in the Portal
- Ensure
TELNYX_API_KEYisn’t set to an old value
Config File Not Found
- Run
telnyx auth setupto create the config - Check if
~/.config/telnyx/config.jsonexists - Verify file permissions
Wrong Profile Being Used
Solutions:- Explicitly specify:
--profile myprofile - Check default:
telnyx profile list - Unset environment variable:
unset TELNYX_PROFILE