Authentication
InstaVM uses API keys for authentication. You can create and manage your API keys through the InstaVM Dashboard.
Getting an API Key
- Sign up at InstaVM Dashboard
- Navigate to the API Keys section
- Click "Create New API Key"
- Copy your API key (it starts with
Iben...
)
Keep Your API Key Secure
Never commit API keys to version control or share them publicly. Treat them like passwords.
Using API Keys
Environment Variables (Recommended)
Store your API key as an environment variable:
export INSTAVM_API_KEY="Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE"
Then use it in your code:
- Python
- JavaScript/Node.js
- Go
import os
from instavm import InstaVM
# Load from environment variable
api_key = os.getenv('INSTAVM_API_KEY')
vm = InstaVM(api_key)
const { InstaVM } = require('instavm');
// Load from environment variable
const apiKey = process.env.INSTAVM_API_KEY;
const vm = new InstaVM(apiKey);
package main
import (
"os"
"github.com/instavm/instavm-go"
)
func main() {
// Load from environment variable
apiKey := os.Getenv("INSTAVM_API_KEY")
client := instavm.New(apiKey)
defer client.Close()
}
Direct Usage
You can also pass the API key directly (not recommended for production):
- Python
- JavaScript/Node.js
- Go
from instavm import InstaVM
vm = InstaVM("Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE")
const { InstaVM } = require('instavm');
const vm = new InstaVM("Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE");
import "github.com/instavm/instavm-go"
client := instavm.New("Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE")
API Key Management
Creating Multiple Keys
You can create multiple API keys for different environments or applications:
- Production:
prod_Iben...
- Development:
dev_Iben...
- Testing:
test_Iben...
Rotating Keys
For security best practices:
- Generate a new API key
- Update your application configuration
- Test the new key works
- Delete the old key
Key Permissions
Currently, all API keys have full access to your account. Future versions will support scoped permissions.
Authentication Errors
Common authentication errors and solutions:
Invalid API Key
AuthenticationError: Invalid API key or session expired
Solutions:
- Verify your API key is correct
- Check for extra spaces or characters
- Ensure the key hasn't been deleted
Session Expired
SessionError: Session expired
Solutions:
- Start a new session
- Check your session timeout settings
Rate Limited
RateLimitError: Rate limit exceeded
Solutions:
- Wait before making more requests
- Implement exponential backoff
- Contact support for higher limits
Security Best Practices
Storage
- ✅ Use environment variables or secure vaults
- ✅ Use configuration files (excluded from version control)
- ❌ Never hardcode in source code
- ❌ Never commit to repositories
Usage
- ✅ Use HTTPS for all API calls (default)
- ✅ Rotate keys regularly
- ✅ Monitor usage for anomalies
- ✅ Delete unused keys
Example: Secure Configuration
- Python
- JavaScript/Node.js
- Go
# config.py
import os
from dataclasses import dataclass
@dataclass
class Config:
instavm_api_key: str = os.getenv('INSTAVM_API_KEY')
def __post_init__(self):
if not self.instavm_api_key:
raise ValueError("INSTAVM_API_KEY environment variable required")
# main.py
from instavm import InstaVM
from config import Config
config = Config()
vm = InstaVM(config.instavm_api_key)
// config.js
require('dotenv').config();
const config = {
instarvmApiKey: process.env.INSTAVM_API_KEY,
};
if (!config.instarvmApiKey) {
throw new Error('INSTAVM_API_KEY environment variable required');
}
module.exports = config;
// main.js
const { InstaVM } = require('instavm');
const config = require('./config');
const vm = new InstaVM(config.instarvmApiKey);
package main
import (
"fmt"
"os"
"github.com/instavm/instavm-go"
)
type Config struct {
InstaVMAPIKey string
}
func LoadConfig() (*Config, error) {
apiKey := os.Getenv("INSTAVM_API_KEY")
if apiKey == "" {
return nil, fmt.Errorf("INSTAVM_API_KEY environment variable required")
}
return &Config{
InstaVMAPIKey: apiKey,
}, nil
}
func main() {
config, err := LoadConfig()
if err != nil {
panic(err)
}
client := instavm.New(config.InstaVMAPIKey)
defer client.Close()
}