Skip to main content
Layer AI uses API keys to authenticate requests. Your API keys grant access to your gates, usage data, and configuration.

Getting Your API Key

  1. Sign in to your Dashboard
  2. Navigate to API Keys in the sidebar
  3. Click Create New Key
  4. Give your key a descriptive name (e.g., “Production”, “Development”)
  5. Copy the key immediately - you won’t be able to see it again
Keep your API keys secure! Never commit them to version control, share them publicly, or expose them in client-side code.

Using Your API Key

With the SDK

Pass your API key when initializing the Layer client:
import { Layer } from '@layer-ai/sdk';

const layer = new Layer({
  apiKey: 'your-api-key-here'
});

With Environment Variables

Store your API key in environment variables for security:
.env
LAYER_API_KEY=your_api_key_here
Then reference it in your code:
import { Layer } from '@layer-ai/sdk';

const layer = new Layer({
  apiKey: process.env.LAYER_API_KEY
});

With Direct API Calls

Include your API key in the Authorization header:
curl https://api.uselayer.ai/v1/chat/completions \
  -H "Authorization: Bearer your-api-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "gate_id": "your-gate-id",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

Key Management Best Practices

Create new keys and delete old ones periodically to maintain security. Layer AI allows multiple active keys per account.
Create separate keys for development, staging, and production environments. This makes it easier to rotate keys and track usage.
If you suspect a key has been exposed, delete it from your Dashboard immediately and create a new one.
Check your Dashboard regularly to review which keys are being used and their associated costs.

Key Permissions

All Layer AI API keys have full access to your account:
  • Make inference requests through your gates
  • Read and modify gates and configuration
  • Manage API keys
  • Access usage logs and analytics
Since all keys have full permissions, treat them with the same level of security you would treat a password.

Troubleshooting

Invalid API Key Error

If you receive an authentication error:
  1. Verify your API key is correctly copied (no extra spaces)
  2. Check that the key hasn’t been deleted in your Dashboard
  3. Ensure you’re using the correct format: Bearer your-api-key

Rate Limits

API keys are subject to rate limits based on your plan. If you’re hitting rate limits:
  • Implement exponential backoff in your code
  • Consider upgrading your plan for higher limits
  • Contact support for custom rate limits

Next Steps

Create Your First Gate

Set up a gate to start making requests

Make Your First Request

Follow the quickstart guide to make your first API call