π Authentication
Nano Studio API uses Bearer token authentication for secure API access.
API Key Authentication
Use Bearer token authentication with your API key for all API requests.
POST /api/generate
Authorization: Bearer your_api_key_here
Content-Type: application/json
Use cases:
- Mobile applications
- Third-party integrations
- Server-to-server communication
- Automated workflows
- Web applications
- Custom integrations
Getting Your API Key
- Sign up for a Nano Studio account at https://nanostudio.cloud
- Navigate to Account Settings β API Keys
- Click βGenerate New Keyβ
- Copy the key and store it securely
- Use the key in your API requests
API Key Security
Best Practices
- Store keys securely - Use environment variables or secure key management
- Rotate keys regularly - Update your API keys periodically
- Use least privilege - Generate separate keys for different applications
- Monitor usage - Track API key usage in your dashboard
- Never commit keys to version control or share publicly
Key Permissions
API keys inherit the permissions of the user account that created them:
- Free Plan keys - 50 transformations per month
- Pro Plan keys - 500 transformations per month
- Enterprise keys - Unlimited transformations
Authentication Examples
cURL Examples
Image Generation with API Key
curl -X POST "https://nanostudio.cloud/api/generate" \
-H "Authorization: Bearer your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"image": "base64_encoded_image_data",
"template": "Joyful Laugh",
"templateType": "expressions"
}'
OCR with API Key
curl -X POST "https://nanostudio.cloud/api/ocr" \
-H "Authorization: Bearer your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"image": "base64_encoded_image_data",
"language": "auto",
"outputFormat": "text"
}'
JavaScript/Node.js Examples
Using Fetch API
const apiKey = 'your_api_key_here';
const imageBase64 = 'base64_encoded_image_data';
const response = await fetch('https://nanostudio.cloud/api/generate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
image: imageBase64,
template: 'Joyful Laugh',
templateType: 'expressions'
})
});
const result = await response.json();
console.log(result);
Using Axios
const axios = require('axios');
const apiKey = 'your_api_key_here';
const imageBase64 = 'base64_encoded_image_data';
try {
const response = await axios.post('https://nanostudio.cloud/api/generate', {
image: imageBase64,
template: 'Joyful Laugh',
templateType: 'expressions'
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
console.log('Success:', response.data);
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
Python Examples
Using Requests
import requests
import base64
api_key = 'your_api_key_here'
image_path = 'path/to/your/image.jpg'
# Read and encode image
with open(image_path, 'rb') as image_file:
image_data = base64.b64encode(image_file.read()).decode('utf-8')
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
data = {
'image': image_data,
'template': 'Joyful Laugh',
'templateType': 'expressions'
}
response = requests.post(
'https://nanostudio.cloud/api/generate',
headers=headers,
json=data
)
if response.status_code == 200:
result = response.json()
print('Success:', result)
else:
print('Error:', response.status_code, response.text)
Error Handling
Authentication Errors
401 Unauthorized
{
"success": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or missing API key"
}
}
Solution: Verify your API key is correct and properly formatted.
403 Forbidden
{
"success": false,
"error": {
"code": "INSUFFICIENT_PERMISSIONS",
"message": "Your plan does not include this feature"
}
}
Solution: Upgrade your subscription plan to access this feature.
429 Rate Limit Exceeded
{
"success": false,
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please try again later."
}
}
Solution: Implement rate limiting in your application or upgrade your plan.
Testing Authentication
Test Your API Key
curl -X GET "https://nanostudio.cloud/api/user/profile" \
-H "Authorization: Bearer your_api_key_here"
If successful, youβll receive your user profile information. If you receive an error, check that your API key is correct and active.
curl -X POST "https://nanostudio.cloud/api/generate" \
-H "Authorization: Bearer your_api_key_here" \
-H "Content-Type: application/json" \
-d '{
"image": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==",
"template": "Joyful Laugh",
"templateType": "expressions"
}'
Rate Limits
| Method | Rate Limit | Burst Limit |
|---|
| API Key | 10 requests/minute | 15 requests/minute |
Rate limits are per API key.
Security Considerations
HTTPS Only
All API requests must be made over HTTPS. HTTP requests will be automatically redirected or rejected.
Key Rotation
Regularly rotate your API keys:
- Generate a new key in your account settings
- Update your applications to use the new key
- Monitor for issues during the transition
- Delete the old key once the transition is complete
Key Compromise
If you suspect your API key has been compromised:
- Immediately delete the compromised key
- Generate a new key
- Update all applications using the old key
- Review usage logs for unauthorized access
Next Steps
π‘ Pro Tip: Use separate API keys for different applications or environments (development, staging, production) to maintain security and track usage effectively.