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

# Authentifizierung

> Konfiguriere den YoukaClient mit deinem API-Schlüssel

Das SDK authentifiziert jede Anfrage mit einem Bearer-API-Schlüssel. Du erstellst einen `YoukaClient` einmal und verwendest ihn über die gesamte Laufzeit deines Prozesses hinweg erneut.

## `new YoukaClient(options)`

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

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

### Optionen

<ParamField path="apiKey" type="string" required>
  Dein Youka-API-Schlüssel. Erstelle einen unter
  [online.youka.io/account](https://online.youka.io/account) unter **API keys**.
</ParamField>

<ParamField path="fetch" type="typeof fetch">
  Eigene `fetch`-Implementierung. Standardmäßig wird das globale `fetch` verwendet. Nutze dies, um
  Logging, Proxys oder eigene Retry-Middleware einzuschleusen.
</ParamField>

## Den API-Schlüssel speichern

<Warning>
  API-Schlüssel gewähren Zugriff auf deine Abrechnung. Committe sie niemals in die Versionsverwaltung.
</Warning>

Empfohlene Muster:

<Tabs>
  <Tab title="Environment variable">
    ```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>

## Ein eigenes fetch injizieren

Jede SDK-Methode verwendet das `fetch`, das du an den Konstruktor übergibst. Dadurch lassen sich Logging oder Middleware einfach hinzufügen:

```ts theme={null}
import { YoukaClient } from "@youka/de/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,
});
```

## Optionen pro Anfrage

Jede Methode akzeptiert ein optionales zweites oder drittes Argument mit Optionen auf Anfrageebene:

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

<ParamField path="idempotencyKey" type="string">
  Wird als `Idempotency-Key`-Header übergeben. Wenn derselbe Schlüssel mit derselben
  Payload wiederverwendet wird, wird das ursprüngliche Ergebnis zurückgegeben, statt ein Duplikat zu erstellen. Siehe [API
  idempotency](/de/api/idempotency).
</ParamField>

<ParamField path="signal" type="AbortSignal">
  Standardsignal zum Abbrechen. Bricht laufende Anfragen und langlaufende
  `client.tasks.wait(...)`, `client.projects.wait(...)` und
  `client.exports.wait(...)`-Polls ab.
</ParamField>

## Wie geht es weiter

* [Projects](/de/sdk/projects) — erstelle dein erstes Projekt
* [Errors](/de/sdk/errors) — gehe mit Authentifizierungsfehlern um
* [API authentication](/de/api/authentication) — Details zum rohen HTTP-Header
