Verifica accesso…
Integra Emma nelle tue applicazioni. Ti servono una API key e del credito disponibile.
Ogni richiesta include la tua API key nell'header X-API-Key. Il segreto si ottiene creando una chiave in API Keys (è mostrato una sola volta).
X-API-Key: LA_TUA_API_KEY
Generazione in streaming:
POST https://emma.egomnia.com/api/chat/stream
Content-Type: application/json · Risposta: application/x-ndjson (un evento JSON per riga).
Solo message è obbligatorio. Campi principali:
| Campo | Tipo | Default | Note |
|---|---|---|---|
message | string | — | obbligatorio (1–4500 caratteri) |
model_key | string | emma-5 | modello da usare: emma-5 · emma-4 · emma-3 |
history | array | [] | turni {user, assistant}, fino a 6 |
use_history | bool | false | usa la cronologia inviata |
use_rag | bool | true | recupero dal knowledge italiano (attivo di default; il router decide se applicarlo) |
mode | string | raw | raw · assisted |
preset | string | adaptive | adaptive · precise · balanced · creative |
max_new_tokens | int | — | limite token generati |
temperature | float | — | 0.10–1.50 |
Una sequenza di righe JSON (ndjson). Tipi di evento:
meta — info iniziali (es. prompt_tokens).update — testo parziale incrementale in content.done — risposta finale in response + stats (con output_tokens).error — messaggio d'errore in message.{"type": "meta", "prompt_tokens": 20, "mode": "raw", ...}
{"type": "update", "content": "Ciao"}
{"type": "update", "content": "Ciao, come"}
{"type": "done", "response": "Ciao, come stai?", "stats": {"output_tokens": 7, ...}}
curl
curl -N -X POST https://emma.egomnia.com/api/chat/stream \
-H "X-API-Key: LA_TUA_API_KEY" \
-H "Content-Type: application/json" \
-d '{"message": "Ciao, chi sei?"}'
Python
import json, requests
resp = requests.post(
"https://emma.egomnia.com/api/chat/stream",
headers={"X-API-Key": "LA_TUA_API_KEY"},
json={"message": "Ciao, chi sei?"},
stream=True,
)
for line in resp.iter_lines():
if not line:
continue
event = json.loads(line)
if event["type"] == "update":
print(event["content"])
elif event["type"] == "done":
print("Risposta:", event["response"])
JavaScript (fetch)
const res = await fetch("https://emma.egomnia.com/api/chat/stream", {
method: "POST",
headers: { "X-API-Key": "LA_TUA_API_KEY", "Content-Type": "application/json" },
body: JSON.stringify({ message: "Ciao, chi sei?" }),
});
const reader = res.body.getReader();
const decoder = new TextDecoder();
let buf = "";
while (true) {
const { value, done } = await reader.read();
if (done) break;
buf += decoder.decode(value, { stream: true });
const lines = buf.split("\n");
buf = lines.pop();
for (const line of lines) {
if (!line.trim()) continue;
const ev = JSON.parse(line);
if (ev.type === "update") console.log(ev.content);
if (ev.type === "done") console.log("Risposta:", ev.response);
}
}
Ogni chiamata via API consuma crediti in base ai token (input + output) e al listino corrente. Il saldo è in Crediti; lo storico dei movimenti in Fatturazione.
La chat sul sito è gratuita: il consumo di crediti avviene solo via API key.
| Codice | Significato |
|---|---|
401 | API key assente o non valida |
402 | Saldo crediti insufficiente |
422 | Corpo della richiesta non valido |