Skip to main content

API Authentication

The Cloudgeni API uses API keys for authentication. This guide covers how to create, manage, and use API keys to access the API securely.

Overview

All API requests require authentication via the X-CLOUDGENI-API-KEY header:
curl -H "X-CLOUDGENI-API-KEY: your-api-key" \
  https://api.cloudgeni.ai/api/v1/organizations
Important: Use the X-CLOUDGENI-API-KEY header, not Authorization or x-api-key.

Creating API Keys

Step 1: Navigate to API Keys

  1. Log in to your Cloudgeni dashboard
  2. Go to SettingsAPI Keys
  3. Click Create API Key

Step 2: Configure the Key

FieldDescription
NameDescriptive name (e.g., “CI/CD Pipeline”, “Local Development”)
ExpirationOptional expiration date
ScopesPermissions for the key (see Scopes section)

Step 3: Save the Key

Copy your API key immediately. It won’t be shown again after creation.

Using API Keys

HTTP Header

Include the API key in every request:
curl -X GET \
  -H "X-CLOUDGENI-API-KEY: cg_live_xxxxxxxxxxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  https://api.cloudgeni.ai/api/v1/organizations

Environment Variable

Set as environment variable for CLI tools:
export CLOUDGENI_API_KEY="cg_live_xxxxxxxxxxxxxxxxxxxx"

# Then use in commands
cloudgeni scan --api-key $CLOUDGENI_API_KEY

Code Examples

const axios = require('axios');

const client = axios.create({
baseURL: 'https://api.cloudgeni.ai/api/v1',
headers: {
'X-CLOUDGENI-API-KEY': process.env.CLOUDGENI_API_KEY,
'Content-Type': 'application/json'
}
});

// Make requests
const response = await client.get('/organizations');


Scopes and Permissions

API keys can have different permission levels:

Read-Only

Access to read data without modification:
  • View organizations and members
  • List repositories and scans
  • Read findings and compliance data
  • View integration status

Read-Write

Full access for automation:
  • All read permissions
  • Trigger scans
  • Create remediations
  • Update finding status

Admin

Full administrative access:
  • All read-write permissions
  • Manage API keys
  • Configure integrations
  • Manage organization settings

Rate Limits

API requests are rate limited to ensure fair usage:
TierRequests per MinuteBurst
Free6010
Pro30050
Enterprise1000100

Rate Limit Headers

Responses include rate limit information:
X-RateLimit-Limit: 300
X-RateLimit-Remaining: 295
X-RateLimit-Reset: 1640000000

Handling Rate Limits

When rate limited, you’ll receive a 429 Too Many Requests response:
{
  "error": "rate_limit_exceeded",
  "message": "Too many requests. Please retry after 60 seconds.",
  "retry_after": 60
}
Best practices:
  • Implement exponential backoff
  • Cache responses where possible
  • Use webhooks instead of polling
async function requestWithRetry(url, options, maxRetries = 3) {
  for (let i = 0; i < maxRetries; i++) {
    const response = await fetch(url, options);

    if (response.status === 429) {
      const retryAfter = response.headers.get("Retry-After") || 60;
      await new Promise((r) => setTimeout(r, retryAfter * 1000));
      continue;
    }

    return response;
  }
  throw new Error("Max retries exceeded");
}

Key Prefixes

API keys have prefixes to identify their type:
PrefixTypeEnvironment
cg_live_ProductionLive data
cg_test_TestSandbox data

Key Management

Listing Keys

View all API keys in SettingsAPI Keys:
  • Key name and creation date
  • Last used timestamp
  • Expiration status
  • Scope/permissions

Rotating Keys

To rotate a key:
  1. Create a new API key
  2. Update your applications to use the new key
  3. Verify the new key works
  4. Delete the old key
Schedule key rotation every 90 days for security best practices.

Revoking Keys

To immediately revoke a key:
  1. Go to SettingsAPI Keys
  2. Find the key to revoke
  3. Click Delete
  4. Confirm deletion
Revoked keys are immediately invalid for all API requests.

Security Best Practices

Never Commit Keys

Never commit API keys to version control.
Use environment variables or secret management:
# .env (add to .gitignore)
CLOUDGENI_API_KEY=cg_live_xxxxxxxxxxxxxxxxxxxx

Use Minimum Permissions

Create keys with only the permissions needed:
  • CI/CD: Read-write for scanning
  • Dashboards: Read-only for viewing
  • Automation: Specific scopes only

Set Expiration

Configure expiration for temporary access:
  • Short-lived for contractors
  • Longer for production systems
  • Review and rotate regularly

Monitor Usage

Track API key usage:
  • Review last used timestamps
  • Monitor for unexpected activity
  • Set up alerts for suspicious patterns

Secure Storage

Use secret management services:
  • AWS Secrets Manager
  • Azure Key Vault
  • HashiCorp Vault
  • GitHub/GitLab secrets

Error Responses

Authentication Errors

401 Unauthorized - Invalid or missing API key:
{
  "error": "unauthorized",
  "message": "Invalid API key provided"
}
403 Forbidden - Valid key but insufficient permissions:
{
  "error": "forbidden",
  "message": "API key does not have permission for this action"
}

Troubleshooting

ErrorCauseSolution
Invalid API keyKey doesn’t exist or was revokedCreate new key
Key expiredExpiration date passedCreate new key
Insufficient permissionsKey scope too limitedCreate key with proper scope
Wrong header nameUsing Authorization instead of X-CLOUDGENI-API-KEYUse correct header