Skip to main content

πŸ” 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

  1. Sign up for a Nano Studio account at https://nanostudio.cloud
  2. Navigate to Account Settings β†’ API Keys
  3. Click β€œGenerate New Key”
  4. Copy the key and store it securely
  5. 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.

Test a Simple Transformation

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

MethodRate LimitBurst Limit
API Key10 requests/minute15 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:
  1. Generate a new key in your account settings
  2. Update your applications to use the new key
  3. Monitor for issues during the transition
  4. Delete the old key once the transition is complete

Key Compromise

If you suspect your API key has been compromised:
  1. Immediately delete the compromised key
  2. Generate a new key
  3. Update all applications using the old key
  4. 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.