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

# Autenticazione

> Configura YoukaClient con la tua chiave API

L'SDK autentica ogni richiesta con una chiave API bearer. Crea un `YoukaClient` una sola volta e riutilizzalo per tutta la durata del processo.

## `new YoukaClient(options)`

```ts theme={null}
import { YoukaClient } from "@youka/it/sdk";

const client = new YoukaClient({
  apiKey: process.env.YOUKA_API_KEY!,
});
```

### Opzioni

<ParamField path="apiKey" type="string" required>
  La tua chiave API Youka. Creane una su
  [online.youka.io/account](https://online.youka.io/account) nella sezione **API keys**.
</ParamField>

<ParamField path="fetch" type="typeof fetch">
  Implementazione `fetch` personalizzata. Per impostazione predefinita usa il `fetch` globale. Usala per
  iniettare logging, proxy o middleware di retry personalizzato.
</ParamField>

## Archiviare la chiave API

<Warning>
  Le chiavi API consentono l'accesso alla fatturazione. Non inserirle mai nel controllo versione.
</Warning>

Pattern consigliati:

<Tabs>
  <Tab title="Variabile d'ambiente">
    ```ts theme={null}
    const client = new YoukaClient({
      apiKey: process.env.YOUKA_API_KEY!,
    });
    ```
  </Tab>

  <Tab title="Secret manager">
    ```ts theme={null}
    import { getSecret } from "./my-secret-manager";

    const client = new YoukaClient({
      apiKey: await getSecret("youka-api-key"),
    });
    ```
  </Tab>
</Tabs>

## Iniettare un fetch personalizzato

Ogni metodo dell'SDK usa il `fetch` che passi al costruttore. Questo rende facile aggiungere logging o middleware:

```ts theme={null}
import { YoukaClient } from "@youka/it/sdk";

const instrumentedFetch: typeof fetch = async (input, init) => {
  const start = Date.now();
  const response = await fetch(input, init);
  console.log(
    `${init?.method ?? "GET"} ${input} ${response.status} in ${Date.now() - start}ms`,
  );
  return response;
};

const client = new YoukaClient({
  apiKey: process.env.YOUKA_API_KEY!,
  fetch: instrumentedFetch,
});
```

## Opzioni per richiesta

Ogni metodo accetta un secondo o terzo argomento opzionale con opzioni a livello di richiesta:

```ts theme={null}
await client.projects.create(body, {
  idempotencyKey: "import-2026-04-08-song-001",
  signal: abortController.signal,
});
```

<ParamField path="idempotencyKey" type="string">
  Passata come header `Idempotency-Key`. Riutilizzare la stessa chiave con lo stesso
  payload restituisce il risultato originale invece di creare un duplicato. Vedi [API
  idempotency](/it/api/idempotency).
</ParamField>

<ParamField path="signal" type="AbortSignal">
  Segnale di annullamento standard. Annulla le richieste in corso e i poll di lunga durata
  `client.tasks.wait(...)`, `client.projects.wait(...)` e
  `client.exports.wait(...)`.
</ParamField>

## Cosa c'è dopo

* [Projects](/it/sdk/projects) — crea il tuo primo progetto
* [Errors](/it/sdk/errors) — gestisci i fallimenti di autenticazione
* [API authentication](/it/api/authentication) — dettagli grezzi degli header HTTP
