Get Your API Key
Sign in to Switchport
Go to switchport.ai and log in to your account.
Set Your API Key
There are two ways to authenticate with the Switchport API:Option 1: Environment Variable (Recommended)
Set theSWITCHPORT_API_KEY environment variable:
Option 2: Pass API Key Directly
Pass the API key when creating the client:Using .env Files
For local development, you can use a.env file with a library like godotenv:
- Install godotenv:
- Create a
.envfile in your project root:
- Load the environment variables in your code:
Add
.env to your .gitignore file to avoid committing secrets to version control.Configure API URL (Optional)
By default, the SDK connects tohttps://switchport-api.vercel.app. For local development or self-hosted instances, you can override this:
Using Environment Variable
Passing to Client
Error Handling
If authentication fails, the SDK returns anAuthenticationError:
- Invalid API key: The API key is incorrect or has been revoked
- Missing API key: No API key provided and
SWITCHPORT_API_KEYis not set - Expired API key: The API key has expired (contact support)
API Key Validation
The SDK validates your API key format when creating the client:- Start with
sp_ - Be non-empty
Security Best Practices
Use environment variables
Use environment variables
Store API keys in environment variables, not in source code.
Rotate keys regularly
Rotate keys regularly
Regularly rotate API keys to minimize risk if a key is compromised.
Use different keys for different environments
Use different keys for different environments
Use separate API keys for development, staging, and production.
Restrict key permissions
Restrict key permissions
If available, use API keys with limited permissions for specific use cases.
Never commit secrets
Never commit secrets
Add
.env and secrets files to .gitignore.Use secrets management in production
Use secrets management in production
In production, use proper secrets management solutions like AWS Secrets Manager, HashiCorp Vault, or Kubernetes secrets.
Next Steps
Execute Prompts
Learn how to execute prompts with the SDK

