Authentication Authentification

All requests must include your API key in the headers. Toutes les requêtes doivent inclure votre clé API dans les headers.

Getting an API Key Obtenir une clé API

Paid service only Service payant uniquement

Unikhorn API keys are exclusively available as a paid service, upon request. Les clés API Unikhorn sont disponibles exclusivement sous forme de service payant, sur demande.

Request via contact form Demande via formulaire de contact

Use the official contact form to request an API key: Utilisez le formulaire de contact officiel pour demander une clé API :

  • Website: unikhorn.io - "Contact" Section Site web : unikhorn.io - Section "Contact"
  • Specify your use case Précisez votre cas d'usage
  • Indicate estimated request volume Indiquez le volume estimé de requêtes
  • Describe your project Décrivez votre projet

Direct email contact Contact direct par email

You can also contact directly: Vous pouvez également contacter directement :

  • Email: elinor@unikhorn.io
  • Subject: "API Key Request" Objet : "Demande de clé API"
  • Cost depends on expected traffic Le coût dépend du trafic prévu
  • Response within 48 business hours Réponse sous 48h ouvrées

Using your API Key Utiliser votre clé API

Authentication Format Format de l'authentification

The API key must be sent in the X-API-Key header of each request: La clé API doit être envoyée dans le header X-API-Key de chaque requête :

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 Avec les SDK

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 Sécurité des clés API

⚠️ Important ⚠️ Important

Never expose your API key in publicly accessible client-side code! Ne jamais exposer votre clé API dans du code côté client accessible publiquement !

✅ Best Practices ✅ Bonnes pratiques

  • Store the key in environment variables Stocker la clé dans des variables d'environnement
  • Use a backend proxy for public apps Utiliser un proxy backend pour les apps publiques
  • Restrict authorized domains Restreindre les domaines autorisés
  • Regenerate keys regularly Régénérer les clés régulièrement
  • Monitor key usage Monitorer l'utilisation des clés

❌ To Avoid ❌ À éviter

  • Include the key in source code Inclure la clé dans le code source
  • Commit the key to Git Commiter la clé sur Git
  • Use the key directly in the frontend Utiliser la clé directement dans le frontend
  • Share the key publicly Partager la clé publiquement
  • Use the same key for all environments Utiliser la même clé pour tous les environnements

Environment Variables Variables d'environnement

.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 Architecture avec proxy backend

For public applications, use a proxy server to protect your API key: Pour les applications publiques, utilisez un serveur proxy pour protéger votre clé API :

Example with Express.js Exemple avec 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) Côté client (sans clé API)

// 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 Limites et quotas

Default Limits Limites par défaut

Plan Plan Requests/hour Requêtes/heure Requests/day Requêtes/jour
Free Gratuit 100 1 000
Standard 1 000 10 000
Premium 10 000 Unlimited Illimité

Response Headers Headers de réponse

The API returns informative headers about your usage: L'API retourne des headers informatifs sur votre utilisation :

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 Gestion des erreurs d'authentification

Error Codes Codes d'erreur

HTTP Code Code HTTP Error Erreur Description Description
401 Unauthorized Missing or invalid API key Clé API manquante ou invalide
403 Forbidden Suspended API key or access denied Clé API suspendue ou accès refusé
429 Too Many Requests Rate limit exceeded Limite de taux dépassée
// Authentication error response example
{
    "error": "API key not found"
}

// Or for invalid request
{
    "error": "Invalid request",
    "message": "Base genetic information is required"
}

💡 Need help? 💡 Besoin d'aide ?

If you encounter authentication issues: Si vous rencontrez des problèmes d'authentification :

  • Check that your API key is correct Vérifiez que votre clé API est correcte
  • Ensure the X-API-Key header is present Assurez-vous que le header X-API-Key est bien présent
  • Check your rate limits Vérifiez vos limites de taux
  • Contact support: api@unikhorn.com Contactez le support : api@unikhorn.com