A consumo

Chiave API sul server · wallet · modello scelto dal catalogo.

Cerchi gli SDK in abbonamento?

Quickstart a consumo

Prima richiesta al gateway con chiave API, wallet e modello del catalogo.

Prerequisiti

  1. Un account Pura LLM con API key attiva
  2. La tua API key (inizia con sk-)
  3. Un ID modello dal catalogo Modelli (es. gpt-4o)

Verifica il modello disponibile

Leggi il catalogo con la tua chiave API e sostituisci YOUR_MODEL_ID negli esempi con un ID restituito da questa chiamata. Il wallet deve avere credito disponibile per l’inferenza.

bash
curl https://llm.puradigital.it/v1/models -H "Authorization: Bearer YOUR_API_KEY"

cURL

Il modo più semplice per testare il gateway:

bash
curl https://llm.puradigital.it/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {"role": "user", "content": "Hello from Pura LLM!"}
    ]
  }'

Python (requests)

Usando la libreria requests senza l'SDK OpenAI:

python
import requests

response = requests.post(
    "https://llm.puradigital.it/v1/chat/completions",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "Content-Type": "application/json",
    },
    json={
        "model": "YOUR_MODEL_ID",
        "messages": [
            {"role": "user", "content": "Hello from Pura LLM!"}
        ],
    },
)

print(response.json()["choices"][0]["message"]["content"])

Node.js (fetch)

Usando l'API fetch nativa:

javascript
const response = await fetch("https://llm.puradigital.it/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "YOUR_MODEL_ID",
    messages: [{ role: "user", content: "Hello from Pura LLM!" }],
  }),
});

const data = await response.json();
console.log(data.choices[0].message.content);

Formato risposta

Le risposte seguono lo schema standard OpenAI chat completion:

json
{
  "id": "chatcmpl-...",
  "object": "chat.completion",
  "model": "YOUR_MODEL_ID",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "Hello! How can I help you today?"
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 9,
    "total_tokens": 21
  }
}