# Completamenti di testo

> POST /v1/completions per il formato legacy con prompt in ingresso e testo in uscita.


L'endpoint legacy basato su prompt, per gli strumenti che lo usano ancora. Esegue il prompt come un unico messaggio utente sugli stessi modelli. Per qualsiasi cosa nuova, usa le [chat completions](/it/api/chat-completions).

```endpoint
POST https://api.notholy.com/v1/completions
```

## Richiesta

| Campo | Tipo | Obbligatorio | Note |
|---|---|---|---|
| `model` | string | Sì | Un ID di modello |
| `prompt` | string o array | Sì | Una stringa, o un array con una sola stringa |
| `max_tokens` | number | No | Predefinito 16. Limitato all'output massimo del modello |
| `stream` | boolean | No | `true` restituisce chunk `text_completion` e `data: [DONE]` |
| `temperature`, `top_p`, `stop` | | No | Passati al modello |
| `n` | number | No | Solo `1` |

Qui non ci sono strumenti né livello di ragionamento. `echo`, `logprobs` e `suffix` vengono ignorati.

## Risposta

```json
{
  "id": "cmpl-4Qz7",
  "object": "text_completion",
  "created": 1793836800,
  "model": "notholy-specter",
  "choices": [{ "index": 0, "text": " ../../etc/passwd encoded as %2e%2e%2f…", "finish_reason": "length", "logprobs": null }],
  "usage": { "prompt_tokens": 14, "completion_tokens": 60, "total_tokens": 74 }
}
```

- In uno stream, ogni chunk porta `choices[0].text`. L'ultimo chunk ha `finish_reason` e `usage`.

## Esempio

```bash test
curl https://api.notholy.com/v1/completions \
  -H "Authorization: Bearer $NOTHOLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "notholy-specter", "prompt": "A path traversal payload in a file download parameter looks like", "max_tokens": 60}'
```

```python test
import os
from openai import OpenAI

client = OpenAI(base_url="https://api.notholy.com/v1", api_key=os.environ["NOTHOLY_API_KEY"])

r = client.completions.create(model="notholy-specter", prompt="The OWASP category for SSRF is", max_tokens=30)
print(r.choices[0].text)
```

## Errori

`400` `prompt` mancante, più di un prompt o `n` superiore a 1 · `401` chiave non valida · `402` crediti esauriti · `404` modello sconosciuto · `429` occupato · `503` modello non disponibile. Vedi [Errori](/it/guides/errors).
