Skip to main content

Authentication

All API requests require authentication using your API key. The API key can be found in your Nanonets Dashboard.

Basic Authentication

The API key should be sent as the username in Basic Authentication, with an empty password. Here's how to authenticate:

import requests
from requests.auth import HTTPBasicAuth

API_KEY = 'YOUR_API_KEY'
url = "https://app.nanonets.com/api/v4/workflows"

response = requests.get(
url,
auth=HTTPBasicAuth(API_KEY, '')
)
print(response.json())

Security Best Practices

  1. Keep Your API Key Secure

    • Never share your API key publicly
    • Don't commit API keys to version control
    • Use environment variables to store API keys
  2. API Key Management

    • Rotate API keys periodically
    • Use different API keys for different environments
    • Monitor API key usage for suspicious activity
  3. Request Security

    • Always use HTTPS
    • Validate API responses
    • Implement proper error handling

For more information about best practices, see our Best Practices Guide.

Error Responses

If authentication fails, you'll receive a 401 Unauthorized response:

{
"code": "unauthorized",
"message": "Invalid API key",
"details": {
"error": "Authentication failed"
}
}

Rate Limiting

API requests are subject to rate limiting based on your plan. When you exceed the rate limit, you'll receive a 429 Too Many Requests response:

{
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded",
"details": {
"retry_after": 60
}
}

The retry_after field indicates the number of seconds to wait before making another request.

Best Practices

  1. Environment Variables: Store your API key in environment variables
  2. Key Rotation: Regularly rotate your API keys
  3. Error Handling: Implement proper error handling for authentication failures
  4. Rate Limiting: Implement exponential backoff for rate limit errors
import os
import requests
from requests.auth import HTTPBasicAuth

API_KEY = os.environ.get('NANONETS_API_KEY')
url = "https://app.nanonets.com/api/v4/workflows"
res = requests.get(url, auth=HTTPBasicAuth(API_KEY, ''))