Funk-lab/admin/ia/litellm.md
alkatrazz 5bcf95b82e docs: réorganisation complète de admin/ en 4 domaines thématiques
Structure avant : 20 fichiers à plat dans admin/ — difficile à naviguer.
Structure après : 4 sous-répertoires thématiques + index clair.

Réorganisation :
  admin/ops/    → cluster.md, ansible.md, systeme.md
  admin/infra/  → reseau.md, nfs.md, dnsmasq.md, ssh.md
  admin/k8s/    → talos.md, argocd.md, monitoring.md
  admin/ia/     → llama_server.md, rocm.md, litellm.md, hermes.md

Suppressions :
  - ask-agent.md : contenu fusionné dans ia/hermes.md (section ask-agent)
  - lm_studio.md : obsolète (LM Studio remplacé par llama-server)

Mises à jour contenu :
  - ia/hermes.md : fusion complète avec ask-agent.md (profils, skills,
    SOUL.md, ask-agent CLI, dépannage) — doc unifiée sans redondance
  - ops/cluster.md : section GitOps réduite à 2 lignes + lien argocd.md
  - incidents.md : tableau de résumé en tête + 4 nouveaux incidents
    (Grafana OOMKilled, AlertManager null receiver, llama-server 501,
    nftables règle après drop)
  - README.md : réécrit — navigation rapide + index par domaine

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 00:47:58 +02:00

4.5 KiB

LiteLLM — Proxy LLM unifié (storage-01)

LiteLLM tourne en service systemd sur storage-01 (127.0.0.1:4000). Il route les requêtes OpenAI-compatibles vers le bon backend selon le modèle demandé.


Flux

Hermes / ask-agent / Open WebUI / n8n
        │
        ▼  http://127.0.0.1:4000/v1  (Authorization: Bearer lm-studio)
   LiteLLM Proxy
        ├── hermes-default       →  qwen3-8b            →  llama-server gpu-01 :1234  (GPU)
        ├── qwen3-8b             →  llama-server gpu-01 :1234  (GPU, gratuit)
        ├── qwen3-1.7b-system    →  llama-server gpu-01 :1236  (CPU 14 threads, gratuit)
        ├── qwen3-1.7b-monitor   →  llama-server gpu-01 :1237  (CPU 14 threads, gratuit)
        ├── claude-sonnet-4-6    →  api.anthropic.com           (cloud, payant)
        └── claude-opus-4-7      →  api.anthropic.com           (cloud, payant)

Service systemd

# Depuis storage-01
sudo systemctl status litellm
sudo systemctl restart litellm
sudo journalctl -u litellm -f
sudo journalctl -u litellm -n 50

Modèles disponibles

Nom dans l'API Backend Coût
hermes-default qwen3-8b sur gpu-01 :1234 (GPU) Gratuit
qwen3-8b llama-server gpu-01 :1234 (ROCm 7.x) Gratuit
qwen3-1.7b-system llama-server gpu-01 :1236 (CPU, 14 threads) Gratuit
qwen3-1.7b-monitor llama-server gpu-01 :1237 (CPU, 14 threads) Gratuit
claude-sonnet-4-6 Anthropic API ~$3/$15 par million tokens in/out
claude-opus-4-7 Anthropic API Plus cher, meilleur raisonnement

qwen3-1.7b-system et qwen3-1.7b-monitor sont utilisés par ask-agent system et ask-agent monitor — voir hermes.md.


Switch rapide avec hermes-switch

Script déployé sur storage-01 :

sudo hermes-switch status    # voir le modèle actuel de hermes-default
sudo hermes-switch qwen      # Qwen2.5-14B local (gratuit, ~35 tok/s)
sudo hermes-switch claude    # Claude Sonnet 4.6 (payant, ~1-2$ par session debug)

Le script modifie /etc/litellm/config.yaml et redémarre litellm automatiquement. Source : roles/litellm/files/hermes-switch.

Coût Claude

Session type Tokens input Coût estimé
Debug simple (5 échanges) ~80k ~$0.24
Debug complexe (10 échanges) ~375k ~$1.12
Utilisation courante Utiliser Qwen

Validation API

# Depuis storage-01 — master_key = lm-studio
curl http://127.0.0.1:4000/v1/models \
  -H "Authorization: Bearer lm-studio" | python3 -m json.tool

# Test inférence Qwen (local)
curl http://127.0.0.1:4000/v1/chat/completions \
  -H "Authorization: Bearer lm-studio" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen2.5-14b-instruct", "messages": [{"role": "user", "content": "Dis bonjour"}], "max_tokens": 30}'

# Test inférence Claude
curl http://127.0.0.1:4000/v1/chat/completions \
  -H "Authorization: Bearer lm-studio" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-sonnet-4-6", "messages": [{"role": "user", "content": "Dis bonjour"}], "max_tokens": 30}'

Configuration

Fichier : /etc/litellm/config.yaml (géré par Ansible, propriété litellm:litellm, mode 0640)

La clé API Anthropic est injectée via ANTHROPIC_API_KEY dans l'unit systemd — elle vient du vault Ansible (vault_anthropic_api_key). Jamais en clair dans config.yaml.

master_key : lm-studio — doit correspondre à LM_API_KEY dans le .env Hermes.


Ajouter un modèle

  1. Modifier roles/litellm/templates/config.yaml.j2 :

    - model_name: claude-haiku-4-5
      litellm_params:
        model: anthropic/claude-haiku-4-5-20251001
        api_key: os.environ/ANTHROPIC_API_KEY
    
  2. Redéployer :

    ansible-playbook -i inventory.yml playbooks/storage-01.yml --tags litellm
    

Points d'attention

Sujet Détail
Accès réseau 127.0.0.1 uniquement — pour exposer au cluster, changer litellm_host: 0.0.0.0 + ouvrir firewall
master_key lm-studio — doit correspondre exactement à LM_API_KEY dans le .env Hermes
Clé Anthropic ANTHROPIC_API_KEY dans l'env systemd — vault Ansible
Coût Claude Surveiller la consommation sur console.anthropic.com
404 /api/v1/models Hermes appelle /api/v1/models à l'init (retourne 404) — normal, ne bloque pas
hermes-switch status Utilise grep -A3 — si le bloc hermes-default a une structure différente, ajuster