> ## 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 response

Crea una risposta in streaming o non-streaming utilizzando il formato dell'API OpenAI Responses.

## 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 generare la risposta. Sfoglia i modelli disponibili su [sunra.ai/models](https://sunra.ai/models).
</ParamField>

<ParamField body="input" type="string | object[]">
  Input per la richiesta di risposta. Può essere una stringa o un array di elementi di input.

  <Expandable title="proprietà (quando array)">
    <ParamField body="type" type="string">
      Il tipo di elemento di input. es. `message`.
    </ParamField>

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

    <ParamField body="content" type="string">
      Il contenuto del messaggio di input.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="instructions" type="string">
  Istruzioni a livello di sistema per il modello. Equivalente a un messaggio di sistema.
</ParamField>

<ParamField body="stream" type="boolean" default={false}>
  Se impostato su `true`, la risposta verrà trasmessa in streaming utilizzando Server-Sent Events (SSE).
</ParamField>

<ParamField body="max_output_tokens" type="integer">
  Il numero massimo di token di output da generare.
</ParamField>

<ParamField body="temperature" type="number">
  Temperatura di campionamento tra 0 e 2. Valori più alti aumentano la casualità.
</ParamField>

<ParamField body="top_p" type="number">
  Parametro di campionamento nucleus (0-1).
</ParamField>

<ParamField body="frequency_penalty" type="number">
  Numero tra -2.0 e 2.0. Penalizza i token in base alla loro frequenza esistente.
</ParamField>

<ParamField body="presence_penalty" type="number">
  Numero tra -2.0 e 2.0. Penalizza i token in base alla loro presenza precedente.
</ParamField>

<ParamField body="store" type="boolean" default={true}>
  Se salvare la risposta generata per un recupero successivo.
</ParamField>

## Risposta

Oggetto risposta riuscito.

<ResponseField name="id" type="string">
  Identificatore univoco della risposta.
</ResponseField>

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

<ResponseField name="created_at" type="number">
  Timestamp Unix della creazione.
</ResponseField>

<ResponseField name="status" type="string">
  Lo stato della risposta. Può essere `completed`, `failed`, `in_progress` o `cancelled`.
</ResponseField>

<ResponseField name="model" type="string">
  Il modello utilizzato per la risposta.
</ResponseField>

<ResponseField name="output" type="object[]">
  Lista degli elementi di output generati dal modello.

  <Expandable title="proprietà">
    <ResponseField name="type" type="string">
      Il tipo di elemento di output. es. `message`.
    </ResponseField>

    <ResponseField name="id" type="string">
      Identificatore univoco per l'elemento di output.
    </ResponseField>

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

    <ResponseField name="content" type="object[]">
      Il contenuto dell'output.

      <Expandable title="proprietà">
        <ResponseField name="type" type="string">
          Tipo di contenuto. es. `output_text`.
        </ResponseField>

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

<ResponseField name="usage" type="object">
  Statistiche di utilizzo dei token.

  <Expandable title="proprietà">
    <ResponseField name="input_tokens" type="integer">
      Numero di token di input elaborati.
    </ResponseField>

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

    <ResponseField name="total_tokens" type="integer">
      Numero totale di token utilizzati.
    </ResponseField>
  </Expandable>
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST https://api-llm.sunra.ai/v1/responses \
    -H "Authorization: Bearer <SUNRA_KEY>" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "openai/gpt-4o",
      "input": [
        {
          "type": "message",
          "role": "user",
          "content": "Hello, how are you?"
        }
      ]
    }'
  ```

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

  response = requests.post(
      "https://api-llm.sunra.ai/v1/responses",
      headers={
          "Authorization": "Bearer <SUNRA_KEY>",
          "Content-Type": "application/json"
      },
      json={
          "model": "openai/gpt-4o",
          "input": [
              {
                  "type": "message",
                  "role": "user",
                  "content": "Hello, how are you?"
              }
          ]
      }
  )
  print(response.json())
  ```

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

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "resp-abc123",
    "object": "response",
    "created_at": 1704067200,
    "status": "completed",
    "model": "openai/gpt-4o",
    "output": [
      {
        "type": "message",
        "id": "msg_abc123",
        "role": "assistant",
        "content": [
          {
            "type": "output_text",
            "text": "Hello! I'm doing well, thank you for asking."
          }
        ]
      }
    ],
    "frequency_penalty": 0,
    "presence_penalty": 0,
    "temperature": 1.0,
    "top_p": 1.0,
    "usage": {
      "input_tokens": 15,
      "output_tokens": 12,
      "total_tokens": 27
    }
  }
  ```
</ResponseExample>
