Authentication
All requests must include your API key in the headers.
Getting an API Key
Paid service only
Unikhorn API keys are exclusively available as a paid service, upon request.
Request via contact form
Use the official contact form to request an API key:
- Website: unikhorn.io - "Contact" Section
- Specify your use case
- Indicate estimated request volume
- Describe your project
Direct email contact
You can also contact directly:
- Email: elinor@unikhorn.io
- Subject: "API Key Request"
- Cost depends on expected traffic
- Response within 48 business hours
Using your API Key
Authentication Format
The API key must be sent in the X-API-Key
header of each request:
curl -X POST https://api.unikhorn.com/coats/result \
-H "X-API-Key: votre-cle-api" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d 'base={"agouti":["A","A"],"extension":["E","E"]}'
With SDKs
PHP
$client = new UnikhornClient([
'api_key' => 'votre-cle-api'
]);
JavaScript
const client = new UnikhornClient({
apiKey: 'votre-cle-api'
});
HTTP Direct
fetch('https://api.unikhorn.com/coats/result', {
method: 'POST',
headers: {
'X-API-Key': 'votre-cle-api',
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'base=' + encodeURIComponent(JSON.stringify({
agouti: ['A','A'],
extension: ['E','E']
}))
});
API Key Security
⚠️ Important
Never expose your API key in publicly accessible client-side code!
✅ Best Practices
- ✓ Store the key in environment variables
- ✓ Use a backend proxy for public apps
- ✓ Restrict authorized domains
- ✓ Regenerate keys regularly
- ✓ Monitor key usage
❌ To Avoid
- ✗ Include the key in source code
- ✗ Commit the key to Git
- ✗ Use the key directly in the frontend
- ✗ Share the key publicly
- ✗ Use the same key for all environments
Environment Variables
.env (local)
# .env
UNIKHORN_API_KEY=votre-cle-api
# .gitignore
.env
Node.js
// Install dotenv: npm install dotenv
require('dotenv').config();
const client = new UnikhornClient({
apiKey: process.env.UNIKHORN_API_KEY
});
PHP
// Avec Symfony
$apiKey = $_ENV['UNIKHORN_API_KEY'];
// Avec vlucas/phpdotenv
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();
$client = new UnikhornClient([
'api_key' => $_ENV['UNIKHORN_API_KEY']
]);
Architecture with Backend Proxy
For public applications, use a proxy server to protect your API key:
Example with Express.js
// server.js
const express = require('express');
const { UnikhornClient } = require('@unikhorn/sdk');
const app = express();
app.use(express.json());
const unikhornClient = new UnikhornClient({
apiKey: process.env.UNIKHORN_API_KEY
});
// Proxy endpoint to calculate a coat
app.post('/api/calculate-coat', async (req, res) => {
try {
// Data validation
if (!req.body.base) {
return res.status(400).json({ error: 'Base genes required' });
}
// Call to Unikhorn API with secure key
const result = await unikhornClient.calculateCoat(req.body);
res.json(result);
} catch (error) {
console.error('Error:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
// Proxy endpoint for offspring generation
app.post('/api/generate-offspring', async (req, res) => {
try {
const result = await unikhornClient.generateOffspring(req.body);
res.json(result);
} catch (error) {
console.error('Error:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
app.listen(3000, () => {
console.log('Proxy server running on port 3000');
});
Client Side (without API key)
// frontend.js
// No exposed API key!
async function calculateCoat(data) {
const response = await fetch('/api/calculate-coat', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
return response.json();
}
// Utilisation
calculateCoat({
base: {
agouti: 'AA',
extension: 'EE'
}
}).then(result => {
console.log('Coat:', result.translate);
});
Limits and Quotas
Default Limits
Plan | Requests/hour | Requests/day |
---|---|---|
Free | 100 | 1 000 |
Standard | 1 000 | 10 000 |
Premium | 10 000 | Unlimited |
Response Headers
The API returns informative headers about your usage:
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640995200
X-API-Version: 1.0.0
Authentication Error Handling
Error Codes
HTTP Code | Error | Description |
---|---|---|
401 |
Unauthorized | Missing or invalid API key |
403 |
Forbidden | Suspended API key or access denied |
429 |
Too Many Requests | Rate limit exceeded |
// Authentication error response example
{
"error": "API key not found"
}
// Or for invalid request
{
"error": "Invalid request",
"message": "Base genetic information is required"
}
💡 Need help?
If you encounter authentication issues:
- Check that your API key is correct
- Ensure the X-API-Key header is present
- Check your rate limits
- Contact support: api@unikhorn.com