Skip to main content

Overview

ManyPi uses API key authentication with Bearer tokens. All API requests must include a valid API key in the Authorization header.
API keys are tied to your account and provide access to all your scrapers. Keep them secure and never commit them to version control.

Getting your API key

1

Navigate to API Keys

Go to SettingsAPI Keys in your dashboard.
2

Create a new key

Click “Create API Key” and give it a descriptive name (e.g., “Production Server”, “Staging Environment”).
3

Copy and store securely

Copy the API key immediately - you won’t be able to see it again!
Store your API key securely. Never commit it to Git or share it publicly.

Making authenticated requests

Basic authentication

Include your API key in the Authorization header as a Bearer token:
cURL
curl -X POST \
  'https://app.manypi.com/api/scrape/YOUR_SCRAPER_ID' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "url": "https://example.com"
  }'

Authentication format

Authorization: Bearer YOUR_API_KEY
  • Scheme: Bearer
  • Token: Your API key (no additional encoding needed)

Code examples

const MANYPI_API_KEY = process.env.MANYPI_API_KEY;

async function scrapeUrl(scraperId, url) {
  const response = await fetch(
    `https://app.manypi.com/api/scrape/${scraperId}`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${MANYPI_API_KEY}`,
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({ url })
    }
  );
  
  if (!response.ok) {
    throw new Error(`HTTP ${response.status}: ${response.statusText}`);
  }
  
  return response.json();
}

Environment variables

Store your API key in environment variables, never hardcode it:
.env
MANYPI_API_KEY=your_api_key_here
Add .env to your .gitignore file!

Authentication errors

401 Unauthorized

Cause: Missing or invalid API key
{
  "success": false,
  "error": "Invalid API key",
  "errorType": "authentication_error"
}
Solutions:
  • Check that the Authorization header is present
  • Verify the API key is correct (no extra spaces or characters)
  • Ensure the API key hasn’t been deleted or revoked
  • Confirm you’re using the Bearer scheme

403 Forbidden

Cause: Valid API key but insufficient permissions or credits
{
  "success": false,
  "error": "Insufficient credits to perform this operation",
  "errorType": "insufficient_credits"
}
Solutions:
  • Check your credit balance in the dashboard
  • Purchase additional credits or upgrade your plan
  • Verify the scraper belongs to your account

Managing API keys

Creating multiple keys

Create separate API keys for different purposes:
Production Server    - For your live application
Staging Environment  - For testing before deployment
CI/CD Pipeline       - For automated testing
Development          - For local development
Partner Integration  - For third-party access
Benefits:
  • Isolate rate limits (60 req/min per key)
  • Easier to rotate keys without downtime
  • Better security through separation
  • Track usage by service

Rotating API keys

1

Create new key

Generate a new API key in the dashboard with a descriptive name.
2

Update your application

Deploy the new key to your application (use blue-green deployment or rolling updates).
3

Monitor

Verify the new key is working correctly in production.
4

Revoke old key

Once confirmed, delete the old API key from the dashboard.
Rotate API keys regularly (every 90 days) as a security best practice.

Revoking compromised keys

If an API key is compromised:
  1. Immediately revoke the key in your dashboard
  2. Create a new key and update your application
  3. Review usage logs for any suspicious activity
  4. Monitor credits for unexpected consumption

Security best practices

.gitignore
# Environment variables
.env
.env.local
.env.*.local

# API keys
**/api-keys.txt
**/credentials.json
Use environment variables or secret management services instead.
For production applications, use dedicated secret management:
  • AWS Secrets Manager
  • HashiCorp Vault
  • Azure Key Vault
  • Google Secret Manager
  • Doppler
  • 1Password Secrets Automation
Set up a rotation schedule:
// Check key age and warn if old
const KEY_MAX_AGE_DAYS = 90;
const keyCreatedAt = new Date('2024-01-01');
const keyAge = (Date.now() - keyCreatedAt.getTime()) / (1000 * 60 * 60 * 24);

if (keyAge > KEY_MAX_AGE_DAYS) {
  console.warn('API key is older than 90 days. Consider rotating.');
}
  • Don’t log API keys
  • Don’t send keys in URLs or query parameters
  • Don’t include keys in client-side code
  • Use server-side proxies for browser applications
Track API key usage to detect anomalies:
// Log API calls for monitoring
function logApiCall(keyId, endpoint, success) {
  console.log({
    timestamp: new Date().toISOString(),
    keyId: keyId.substring(0, 8) + '...', // Partial key for identification
    endpoint,
    success
  });
}

Testing authentication

Verify your API key

Test your API key with a simple request:
curl -X POST \
  'https://app.manypi.com/api/scrape/YOUR_SCRAPER_ID' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"url": "https://example.com"}' \
  -v
Look for:
  • HTTP/1.1 200 OK - Authentication successful
  • HTTP/1.1 401 Unauthorized - Invalid API key
  • HTTP/1.1 403 Forbidden - Valid key but insufficient permissions/credits

Automated testing

describe('API Authentication', () => {
  it('should authenticate with valid API key', async () => {
    const response = await fetch(/* ... */, {
      headers: {
        'Authorization': `Bearer ${process.env.MANYPI_API_KEY}`
      }
    });
    
    expect(response.status).toBe(200);
  });
  
  it('should reject invalid API key', async () => {
    const response = await fetch(/* ... */, {
      headers: {
        'Authorization': 'Bearer invalid_key'
      }
    });
    
    expect(response.status).toBe(401);
  });
  
  it('should reject missing API key', async () => {
    const response = await fetch(/* ... */);
    
    expect(response.status).toBe(401);
  });
});

Next steps