Overview
AyAgent API uses API key authentication to secure your requests. All API requests must include a valid API key in the request headers. This guide will walk you through obtaining your API key, making authenticated requests, and following security best practices.
Keep your API keys secure and never expose them in client-side code. Always make API calls from your backend server or secure environment.
Getting Your API Key
To obtain your API key, follow these steps:
- Log in to your AyAgent dashboard
- Navigate to Settings → API Keys
- Click "Generate New API Key"
- Give your key a descriptive name
- Copy and securely store your API key
Your API key will only be displayed once. Make sure to copy and store it securely before leaving the page. If you lose your key, you'll need to generate a new one.
Authentication Methods
AyAgent supports the following authentication methods:
API Key in Header
Include your API key in the Authorization
header with the Bearer
prefix:
curl -X GET "https://api.ayagent.com/v1/agents" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json"
API Key in Query Parameter
Alternatively, you can include your API key as a query parameter (not recommended for production):
curl -X GET "https://api.ayagent.com/v1/agents?api_key=YOUR_API_KEY"
Making Authenticated Requests
Here are examples of making authenticated requests in different programming languages:
JavaScript/Node.js
const axios = require('axios');
const apiKey = process.env.AYAGENT_API_KEY;
const baseURL = 'https://api.ayagent.com/v1';
const client = axios.create({
baseURL,
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
});
// Get all agents
async function getAgents() {
try {
const response = await client.get('/agents');
return response.data;
} catch (error) {
console.error('Error:', error.response.data);
}
}
Python
import requests
import os
api_key = os.getenv('AYAGENT_API_KEY')
base_url = 'https://api.ayagent.com/v1'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type': 'application/json'
}
# Get all agents
def get_agents():
response = requests.get(f'{base_url}/agents', headers=headers)
if response.status_code == 200:
return response.json()
else:
print(f'Error: {response.status_code} - {response.text}')
return None
Response Codes
The API returns standard HTTP status codes to indicate the success or failure of requests:
HTTP Status Codes
200
Success - Request completed successfully201
Created - Resource created successfully400
Bad Request - Invalid request parameters401
Unauthorized - Invalid or missing API key403
Forbidden - Insufficient permissions429
Rate Limited - Too many requests500
Server Error - Internal server errorRate Limits
To ensure fair usage and maintain service quality, the AyAgent API implements rate limiting:
- Standard Plan: 1,000 requests per hour
- Pro Plan: 5,000 requests per hour
- Enterprise Plan: 10,000 requests per hour
Rate limit information is included in response headers:
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200
Security Best Practices
- Environment Variables: Store API keys in environment variables, never in code
- Server-Side Only: Never expose API keys in client-side applications
- Rotate Keys: Regularly rotate your API keys
- Monitor Usage: Monitor API usage for unusual activity
- Use HTTPS: Always use HTTPS for API requests
- Restrict Access: Use IP whitelisting when possible