> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sunra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a message

Crea un messaggio utilizzando il formato dell'API Anthropic Messages. Supporta testo, immagini, PDF, strumenti e pensiero esteso.

## Autenticazione

<ParamField header="Authorization" type="string" required>
  Token Bearer. Utilizza la tua chiave API come token Bearer nell'header Authorization.

  Format: `Bearer <SUNRA_KEY>`
</ParamField>

## Richiesta

Questo endpoint si aspetta un oggetto JSON.

<ParamField body="model" type="string" required>
  Il modello da utilizzare per il messaggio. Sfoglia i modelli disponibili su [sunra.ai/models](https://sunra.ai/models).
</ParamField>

<ParamField body="messages" type="object[]" required>
  Lista dei messaggi di input per la conversazione.

  <Expandable title="proprietà">
    <ParamField body="role" type="string" required>
      Il ruolo dell'autore del messaggio. Valori supportati: `user`, `assistant`.
    </ParamField>

    <ParamField body="content" type="string | object[]" required>
      Il contenuto del messaggio. Può essere una stringa o un array di blocchi di contenuto per input multimodale.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="max_tokens" type="integer" required>
  Il numero massimo di token da generare prima dell'arresto.
</ParamField>

<ParamField body="system" type="string">
  Prompt di sistema. Fornisce istruzioni che il modello dovrebbe seguire.
</ParamField>

<ParamField body="stream" type="boolean" default={false}>
  Se trasmettere la risposta in streaming utilizzando Server-Sent Events (SSE).
</ParamField>

<ParamField body="temperature" type="number">
  Quantità di casualità iniettata nella risposta. Varia da 0.0 a 1.0.
</ParamField>

<ParamField body="top_p" type="number">
  Parametro di campionamento nucleus. Utilizza un valore tra 0 e 1.
</ParamField>

<ParamField body="top_k" type="integer">
  Campiona solo dalle prime K opzioni per ogni token successivo. Utilizzato per rimuovere le risposte a bassa probabilità dalla "coda lunga".
</ParamField>

<ParamField body="stop_sequences" type="string[]">
  Sequenze di testo personalizzate che faranno smettere il modello di generare.
</ParamField>

<ParamField body="metadata" type="object">
  Un oggetto che descrive i metadati sulla richiesta.

  <Expandable title="proprietà">
    <ParamField body="user_id" type="string">
      Un identificatore esterno per l'utente associato alla richiesta.
    </ParamField>
  </Expandable>
</ParamField>

## Risposta

Risposta messaggio riuscita.

<ResponseField name="id" type="string">
  Identificatore univoco del messaggio.
</ResponseField>

<ResponseField name="type" type="string">
  Tipo di oggetto. Sempre `message`.
</ResponseField>

<ResponseField name="role" type="string">
  Il ruolo del messaggio generato. Sempre `assistant`.
</ResponseField>

<ResponseField name="content" type="object[]">
  Lista dei blocchi di contenuto nella risposta.

  <Expandable title="proprietà">
    <ResponseField name="type" type="string">
      Il tipo di blocco di contenuto. es. `text`.
    </ResponseField>

    <ResponseField name="text" type="string">
      Il contenuto testuale generato.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="model" type="string">
  Il modello che ha gestito la richiesta.
</ResponseField>

<ResponseField name="stop_reason" type="string">
  Il motivo per cui il modello ha smesso di generare. Può essere `end_turn`, `max_tokens`, `stop_sequence` o `tool_use`.
</ResponseField>

<ResponseField name="stop_sequence" type="string | null">
  La sequenza di arresto che ha causato l'interruzione del modello, se applicabile.
</ResponseField>

<ResponseField name="usage" type="object">
  Statistiche di utilizzo dei token. I tre bucket di input sono mutuamente esclusivi — vedi [Utilizzo dei token](/it/llm/token-usage).

  <Expandable title="proprietà">
    <ResponseField name="input_tokens" type="integer">
      Numero di token di input nuovi elaborati. Esclude entrambi i bucket di cache.
    </ResponseField>

    <ResponseField name="output_tokens" type="integer">
      Numero di token di output generati.
    </ResponseField>

    <ResponseField name="total_tokens" type="integer">
      Tutti i bucket di input più `output_tokens`. Omesso nelle risposte in streaming.
    </ResponseField>

    <ResponseField name="sunra_usage_semantics" type="string | null">
      Presente come `anthropic.exclusive.v1` quando Sunra ha normalizzato questa risposta. Verifica questo valore invece di dedurre la convenzione dai numeri. Vedi [Utilizzo dei token](/it/llm/token-usage).
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api-llm.sunra.ai/v1/messages \
    -H "Authorization: Bearer <SUNRA_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "anthropic/claude-sonnet-4-20250514",
      "max_tokens": 1024,
      "messages": [
        {
          "role": "user",
          "content": "Hello, how are you?"
        }
      ]
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api-llm.sunra.ai/v1/messages",
      headers={
          "Authorization": "Bearer <SUNRA_KEY>",
          "Content-Type": "application/json"
      },
      json={
          "model": "anthropic/claude-sonnet-4-20250514",
          "max_tokens": 1024,
          "messages": [
              {"role": "user", "content": "Hello, how are you?"}
          ]
      }
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch("https://api-llm.sunra.ai/v1/messages", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <SUNRA_KEY>",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      model: "anthropic/claude-sonnet-4-20250514",
      max_tokens: 1024,
      messages: [
        { role: "user", content: "Hello, how are you?" }
      ]
    })
  });
  const data = await response.json();
  console.log(data);
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "msg_abc123",
    "type": "message",
    "role": "assistant",
    "content": [
      {
        "type": "text",
        "text": "Hello! I'm doing well, thank you for asking."
      }
    ],
    "model": "anthropic/claude-sonnet-4-20250514",
    "stop_reason": "end_turn",
    "stop_sequence": null,
    "usage": {
      "input_tokens": 12,
      "output_tokens": 15,
      "total_tokens": 27,
      "sunra_usage_semantics": "anthropic.exclusive.v1"
    }
  }
  ```
</ResponseExample>
