API Authentication
Daytona API supports two authentication methods: API Key authentication (recommended for most use cases) and OAuth 2.0 / OpenID Connect (for user-facing applications).API Key Authentication
API keys provide the simplest way to authenticate programmatic access to the Daytona API.Creating an API Key
Create an API key using the Daytona dashboard or CLI:Using API Keys
Include your API key in theAuthorization header using the Bearer scheme:
API Key Headers
Bearer token containing your API keyFormat:
Bearer YOUR_API_KEYOrganization ID for multi-org API keys. Required when your API key has access to multiple organizations.
Example: Creating a Sandbox
API Key Permissions
API keys support granular permissions for organization resources:read:sandboxes- List and view sandboxeswrite:sandboxes- Create, update, and delete sandboxesread:snapshots- List and view snapshotswrite:snapshots- Create and delete snapshotsread:volumes- List and view volumeswrite:volumes- Create and delete volumesread:registries- View registry configurationswrite:registries- Manage registry configurationsadmin:organization- Full organization administration
Managing API Keys
List API Keys
Get Current API Key Details
Delete API Key
API Key Expiration
API keys can have optional expiration dates. When an API key expires:- All requests using the key will receive a
401 Unauthorizedresponse - The key is automatically marked as inactive
- You must create a new API key to restore access
- Set expiration dates for temporary access
- Rotate API keys regularly for production use
- Use shorter expiration periods for development/testing
OAuth 2.0 / OpenID Connect
Use OAuth 2.0 for user-facing applications that need to act on behalf of authenticated users.OpenID Connect Configuration
Daytona’s OpenID Connect endpoint is available at:OAuth Scopes
Daytona supports the following OAuth scopes:openid- Required for OpenID Connectprofile- Access to user profile informationemail- Access to user email address
Using JWT Tokens
After completing the OAuth flow, use the JWT token in the Authorization header:Multi-Organization Access
When a JWT token has access to multiple organizations, specify which organization to use:Authentication Errors
401 Unauthorized
Your API key is invalid, expired, or missing.- Verify your API key is correct
- Check if the API key has expired
- Ensure the Authorization header is properly formatted
403 Forbidden
Your API key lacks required permissions.- Review required permissions for the endpoint
- Create a new API key with appropriate permissions
- Contact your organization administrator
Security Best Practices
Secure Storage
Secure Storage
- Store API keys in environment variables or secret management systems
- Never hardcode API keys in source code
- Use different API keys for development and production
- Rotate API keys regularly
Access Control
Access Control
- Grant minimum required permissions
- Create separate API keys for different applications
- Set expiration dates appropriate for use case
- Monitor API key usage and audit logs
Transmission Security
Transmission Security
- Always use HTTPS for API requests
- Avoid logging API keys in application logs
- Don’t send API keys as query parameters
- Revoke compromised keys immediately
Next Steps
Rate Limits
Understand API rate limiting
Create Sandbox
Make your first API request
Error Handling
Handle authentication errors
SDKs
Use official SDK libraries