Documentazione dell'API

Tutto quello che serve per integrare AgileLLM: una rotta compatibile con lo standard di mercato delle API di chat (stesse rotte /v1/chat/completions e /v1/models, stessi campi della richiesta e della risposta, streaming SSE), una chiave per prodotto e per tenant, streaming a frase, misura d'uso. La porta è l'unica che sa dire chi ha risposto davvero.

Basi e autenticazione

Base URL: https://api.agilellm.agile.software/v1.

La chiave si passa nell'intestazione Authorization: Bearer <chiave> (quella dei client standard delle API di chat) o X-API-Key: <chiave>. Ogni chiave ha ambiti (chat, uso), un ritmo (richieste al minuto) e una quota di token al mese; si ruota (24 ore di sovrapposizione) e si revoca.

Authorization: Bearer all_…
X-Api-Key: all_…

Endpoint

GET/health — stato del servizio

Senza chiave. Dice se il servo è su (ok, altrimenti 503), lo stato (ok, caricamento, giù), il peso e il contesto caricati, gli slot, la VRAM, le richieste e gli errori del mese. È la rotta che la vigilanza interroga.

GET/v1/models — modelli disponibili

Elenca i modelli realmente disponibili su questa istanza.

POST/v1/chat/completions — la conversazione

Formato standard delle API di chat (stessi campi della richiesta e della risposta), con stream (pezzi SSE data: {…}, chiusi da data: [DONE]) o senza (un JSON solo).

B=https://api.agilellm.agile.software; K=all_…
curl -s -X POST $B/v1/chat/completions -H "Authorization: Bearer $K" \
  -H 'Content-Type: application/json' -d '{
  "model": "agilellm", "stream": true, "max_tokens": 120,
  "messages": [{"role": "system", "content": "Sei Nadia, addetta all'accoglienza."},
               {"role": "user", "content": "Quando siete aperti?"}]}'
import json, urllib.request
corpo = {"model": "agilellm", "stream": True, "max_tokens": 120, "a_frase": True,
         "messages": [{"role": "user", "content": "Quando siete aperti?"}]}
r = urllib.request.Request("https://api.agilellm.agile.software/v1/chat/completions",
        data=json.dumps(corpo).encode(), method="POST",
        headers={"Authorization": "Bearer all_…", "Content-Type": "application/json"})
with urllib.request.urlopen(r) as risposta:
    for riga in risposta:
        riga = riga.decode().strip()
        if not riga.startswith("data: ") or riga == "data: [DONE]":
            continue
        pezzo = json.loads(riga[len("data: "):])
        if pezzo.get("choices") and pezzo["choices"][0]["delta"].get("content"):
            print(pezzo["choices"][0]["delta"]["content"])

GET/v1/chiave — la scheda della chiave

Ambiti, quota, usati e residui (mai il valore della chiave), famiglia.

GET/v1/uso — la misura d'uso del mese

Richieste, errori, token del prompt e della risposta, millisecondi. Si registra solo quando, quale chiave, quale modello e motore, stato, tempi e conteggi: mai i testi, né domanda né risposta.

Con ?persona=<nome> i conti sono di quella sola persona digitale; senza il parametro sono quelli del tenant (tutte le persone sommate) più la ripartizione per_persona. Una persona che la chiave non dichiara è 403.

Streaming a frase

Con "a_frase": true nel corpo (o X-A-Frase: si) i pezzi escono a frasi chiuse, come serve al cervello a flusso di una persona digitale: la voce parte alla prima frase senza aspettare la risposta intera. Ogni pezzo porta agilellm.frase (1, 2, …).

Che cosa torna sempre

Nessun ripiego silenzioso. Un modello che non è qui è 404, mai la risposta di un altro cervello. Se il servo principale non risponde e la sede ha una riserva sovrana (un secondo modello nostro), risponde lei e lo dice: X-Ripiego: riserva: <perché>, X-Motore-Cervello col suo modello, agilellm.ripiego nel corpo. Una chiave può vietarlo (ripiego=nessuno): arriva 502 servo_non_pronto. Mai un fornitore esterno.

Errori

Ogni errore ha la forma standard delle API di chat (un oggetto error con message, type e code), con error.code in italiano.

HTTPcodeche fare
401chiave_mancante, chiave_sconosciuta, chiave_scadutamettere la chiave; dopo una rotazione usare la nuova.
403chiave_revocata, ambito_non_ammessochiedere una chiave nuova o l'ambito che manca.
404modello_sconosciuto, rotta_sconosciutachiedere agilellm.
429troppo_frequente, quota_superatarallentare, o chiedere un ritmo/quota più alti.
400richiesta_non_validail corpo non ha messages; oppure il servo ha rifiutato la richiesta: correggere, non riprovare uguale.
502servo_non_prontoil servo è giù o sta caricando: riprovare fra qualche secondo.
502servo_interrottoil servo si è fermato a metà: nel flusso arriva come ultimo pezzo e senza [DONE].

API documentation

Everything you need to integrate AgileLLM: a route compatible with the market-standard chat API (same routes /v1/chat/completions and /v1/models, same request and response fields, SSE streaming), one key per product and per tenant, sentence streaming, usage metering. The door is the only one that can say who really answered.

Basics and authentication

Base URL: https://api.agilellm.agile.software/v1.

The key is passed in the Authorization: Bearer <key> header (the one standard chat-API clients use) or X-API-Key: <key>. Every key has scopes (chat, uso), a rate (requests per minute) and a monthly token quota; it is rotated (24-hour overlap) and revoked.

Authorization: Bearer all_…
X-Api-Key: all_…

Endpoints

GET/health — service status

No key. It says whether the servo is up (ok, otherwise 503), the status (ok, caricamento, giù), the loaded weight and context, the slots, the VRAM, the requests and errors of the month. It is the route the little server watches.

GET/v1/models — available models

It lists the models really available on this instance.

POST/v1/chat/completions — the conversation

Standard chat-API format (same request and response fields), with stream (SSE pieces data: {…}, closed by data: [DONE]) or without it (a single JSON).

B=https://api.agilellm.agile.software; K=all_…
curl -s -X POST $B/v1/chat/completions -H "Authorization: Bearer $K" \
  -H 'Content-Type: application/json' -d '{
  "model": "agilellm", "stream": true, "max_tokens": 120,
  "messages": [{"role": "system", "content": "You are Nadia, the receptionist."},
               {"role": "user", "content": "What are your opening hours?"}]}'
import json, urllib.request
corpo = {"model": "agilellm", "stream": True, "max_tokens": 120, "a_frase": True,
         "messages": [{"role": "user", "content": "What are your opening hours?"}]}
r = urllib.request.Request("https://api.agilellm.agile.software/v1/chat/completions",
        data=json.dumps(corpo).encode(), method="POST",
        headers={"Authorization": "Bearer all_…", "Content-Type": "application/json"})
with urllib.request.urlopen(r) as risposta:
    for riga in risposta:
        riga = riga.decode().strip()
        if not riga.startswith("data: ") or riga == "data: [DONE]":
            continue
        pezzo = json.loads(riga[len("data: "):])
        if pezzo.get("choices") and pezzo["choices"][0]["delta"].get("content"):
            print(pezzo["choices"][0]["delta"]["content"])

GET/v1/chiave — the key's card

Scopes, quota, used and remaining (never the key's value), family.

GET/v1/uso — the month's usage metering

Requests, errors, prompt and response tokens, milliseconds. It records only when, which key, which model and engine, status, times and counts: never the texts, neither question nor answer.

With ?persona=<name> the counters are those of that single digital person; without the parameter they are the tenant's (all persons summed) plus the per_persona breakdown. A person the key does not declare gets 403.

Sentence streaming

With "a_frase": true in the body (or X-A-Frase: si) the pieces come out as closed sentences, as a digital person's flow brain needs: the voice starts on the first sentence without waiting for the whole answer. Every piece carries agilellm.frase (1, 2, …).

What always comes back

No silent fallback. A model that is not here is 404, never another brain's answer. If the main servo does not answer and the seat has a sovereign reserve (a second model of ours), it answers and says so: X-Ripiego: riserva: <why>, X-Motore-Cervello with its model, agilellm.ripiego in the body. A key can forbid it (ripiego=nessuno): you get 502 servo_non_pronto. Never an external provider.

Errors

Every error has the standard chat-API shape (an error object with message, type and code), with error.code in Italian.

HTTPcodewhat to do
401chiave_mancante, chiave_sconosciuta, chiave_scadutaadd the key; after a rotation use the new one.
403chiave_revocata, ambito_non_ammessoask for a new key or the missing scope.
404modello_sconosciuto, rotta_sconosciutaask for agilellm.
429troppo_frequente, quota_superataslow down, or ask for a higher rate/quota.
400richiesta_non_validathe body has no messages; or the servo refused the request: fix it, do not retry the same.
502servo_non_prontothe servo is down or loading: retry in a few seconds.
502servo_interrottothe servo stopped halfway: in the stream it arrives as the last piece and without [DONE].