API Authentication

Learn how to authenticate with the DataShows REST API using API keys.

Authentication Methods

DataShows API uses API key authentication. Include your API key in the Authorization header.

bash
curl -X POST https://app.datashows.ai/api/generate-chart \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer dsk_1234567890abcdef" \
  -d '{
    "data": [{"month": "Jan", "sales": 100}],
    "prompt": "Line chart of sales"
  }'

Getting Your API Key

Step 1: Create Account

Sign up for a free DataShows account to get started.

Step 2: Access Dashboard

Navigate to your dashboard and go to the API Keys section.

Step 3: Generate Key

Click "Create API Key" and copy the generated key. Store it securely.

API Key Format

DataShows API keys follow a specific format for easy identification.

Key Format

text
ds_1234567890abcdef

• Starts with ds_ prefix
• 16 characters long
• Contains alphanumeric characters

Making Requests

Include your API key in the Authorization header of all requests.

javascript
// JavaScript/Node.js
const response = await fetch('https://app.datashows.ai/api/generate-chart', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.DATASHOWS_API_KEY}`
  },
  body: JSON.stringify({
    data: yourData,
    prompt: "Your chart description"
  })
});

const result = await response.json();
python
# Python
import requests

headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {api_key}'
}

data = {
    'data': your_data,
    'prompt': 'Your chart description'
}

response = requests.post(
    'https://app.datashows.ai/api/generate-chart',
    headers=headers,
    json=data
)

result = response.json()

Security Best Practices

✅ Do

  • • Store API keys in environment variables
  • • Use HTTPS for all API requests
  • • Rotate API keys regularly
  • • Monitor API key usage
  • • Use different keys for different environments

❌ Don't

  • • Hardcode API keys in your source code
  • • Commit API keys to version control
  • • Share API keys in plain text
  • • Use the same key for all environments
  • • Ignore security warnings

Environment Variables

Store your API key securely using environment variables.

bash
# .env file
DATASHOWS_API_KEY=ds_1234567890abcdef
javascript
// Next.js
// next.config.js
module.exports = {
  env: {
    DATASHOWS_API_KEY: process.env.DATASHOWS_API_KEY,
  },
};
bash
# Vercel Environment Variables
DATASHOWS_API_KEY=ds_1234567890abcdef

Error Responses

The API returns specific error codes for authentication issues.

401 Unauthorized

json
{
  "error": "Invalid API key",
  "code": "INVALID_API_KEY",
  "message": "The provided API key is invalid or has been revoked"
}

403 Forbidden

json
{
  "error": "API key expired",
  "code": "API_KEY_EXPIRED",
  "message": "Your API key has expired. Please generate a new one."
}

Rate Limits

Free Tier

  • • 10 requests per minute
  • • 500 generations per month
  • • $0.02 per extra generation

Pro Tier

  • • 100 requests per minute
  • • Unlimited generations
  • • Priority processing

Testing Your API Key

Test your API key with a simple request to verify authentication.

javascript
// Test your API key by making a chart generation request
const testApiKey = async (apiKey) => {
  try {
    const response = await fetch('https://app.datashows.ai/api/generate-chart', {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${apiKey}`
      },
      body: JSON.stringify({
        data: [{ x: 1, y: 2 }],
        prompt: "Test chart",
        fileType: "png"
      })
    });
    
    if (response.ok) {
      console.log('API key is valid!');
    } else {
      console.error('API key validation failed');
    }
  } catch (error) {
    console.error('Network error:', error);
  }
};