API Authentication
Secure authentication is required for all requests to the Cognipeer API. This guide explains how to authenticate your API requests.
Obtaining an API Key
- Log in to your Cognipeer Dashboard
- Navigate to Settings > Tokens
- Click Add Token
- Name your key for tracking purposes
- Copy the generated API key - note that you won't be able to view it again
Using Your API Key
All API requests must include your API key in the Authorization header as a Bearer token:
Authorization: Bearer YOUR_API_KEY
Example Request
fetch('https://api.cognipeer.com/v1/peer', {
method: 'GET',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => console.log(data));
With the Client Library
When using the official client library, you can provide your API key during initialization:
import CognipeerClient from '@cognipeer/client-js';
const client = new CognipeerClient({
token: 'YOUR_API_KEY'
});
// Now you can make authenticated requests
const peers = await client.peer.list();
API Key Security
Treat your API keys like passwords:
- Never share API keys in publicly accessible areas such as GitHub or client-side code
- Use environment variables or secrets management services to handle keys in your applications
- Consider implementing key rotation policies for enhanced security
- Set appropriate permissions for each API key based on your needs
Token Expiration
API keys can be set with an expiration date. After this date, the key will no longer work for authentication. This is useful for temporary access or for implementing key rotation policies.