# API-Keys | AudioDN Docs

> Erzeugen Sie Client-Side-Player- und Client-Side-Upload-Keys programmatisch von Ihrem Server aus.

Source: https://audiodeliverynetwork.com/de/docs/api/api-keys/

---

# API-Keys

Erstellen Sie neue API-Keys Server-zu-Server mit einem bestehenden **API Access**\-Key. So können Sie **Client-Side Player**\- und **Client-Side Upload**\-Keys bei Bedarf provisionieren — z. B. einen eingeschränkten Player-Key pro Kunde.

#### Inline-Share- und URL-Signing-Keys nur im Dashboard

**Inline Share** (siehe [Inline Share](/docs/api/share)) und **URL Signing** (siehe [Signing Keys](/docs/api/signing-keys)) sind hier zur Referenz dokumentiert, können aber **nicht über die API erstellt oder verwaltet werden**. Sie müssen unter **Settings → API Keys** im [AudioDN-Dashboard](https://account.audiodeliverynetwork.com) erstellt werden, weil sie Edge-Konfiguration (Signing-Regeln) provisionieren, die die API nicht verwaltet.

#### API-Access-Keys werden im Dashboard erstellt

Sie müssen zuerst einen **API Access**\-Key unter **Settings → API Keys** im [AudioDN-Dashboard](https://account.audiodeliverynetwork.com) erstellen. Dieser Key authentifiziert diesen Endpunkt. API-Access-Keys selbst können nicht über die API erstellt werden.

## Erstellbare Key-Typen

-   `player` — Client-Side-Player-Key für die Wiedergabe
-   `uploader` — Client-Side-Upload-Key für Uploads

Die Typen `api` (API Access), `share` (Inline Share) und `signing` (URL Signing) können hier nicht erstellt werden — sie werden nur auf der Dashboard-Seite **Settings → API Keys** verwaltet.

## Ablauf & Geltungsbereich

Über die API ist `expires_at` für beide Key-Typen **optional** — lassen Sie es weg, um einen Key zu erstellen, der zeitlich nie abläuft. Optional können Sie einen Key auf eine bestimmte `collection_id` (und weiter auf eine `track_id`) einschränken. Wenn Ihr API-Access-Key selbst auf eine Sammlung beschränkt ist, kann der neue Key nicht außerhalb davon beschränkt werden.

**Downloads:** Ein Player-Key kann optional Downloads erlauben. Das wird im Dashboard beim Erstellen des Keys gesetzt (der Schalter _Allow downloads_) und ist über diesen API-Endpunkt nicht konfigurierbar. Die Download-Berechtigung des Keys ist maßgeblich: Das Player-Attribut `downloadable` _fordert_ Downloads nur an, und eine Wiedergabesession ist nur dann downloadbar, wenn der Key es erlaubt _und_ die Anfrage zustimmt.

POST `/v1/api_key`

Erstellt einen neuen Player- oder Uploader-API-Key

#### Parameter

| Name | Typ | Erforderlich | Beschreibung |
| --- | --- | --- | --- |
| `title` | string | Erforderlich | Name des API-Keys |
| `api_key_type_id` | string | Erforderlich | Einer der Werte 'player' oder 'uploader'. Share- und Signing-Keys sind nur im Dashboard verfügbar. |
| `collection_id` | uuid | Optional | Key auf eine bestimmte Sammlung beschränken |
| `track_id` | uuid | Optional | Key auf einen bestimmten Track beschränken (erfordert collection\_id) |
| `creator_id` | uuid | Optional | Key auf einen bestimmten Creator beschränken |
| `variants` | array of strings | Optional | Optional. Player-Key auf bestimmte Varianten beschränken. |
| `expires_at` | string | Optional | ISO-8601-Ablaufdatum/-zeit. Optional; weglassen für einen Key, der zeitlich nie abläuft. |

#### Beispielanfrage

    

```
curl -X POST "https://api.audiodelivery.net/v1/api_key" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "title": "Customer Player Key",
  "api_key_type_id": "player",
  "collection_id": "COLLECTION_ID"
}'
```

```
const payload = {
  "title": "Customer Player Key",
  "api_key_type_id": "player",
  "collection_id": "COLLECTION_ID"
};

const response = await fetch('https://api.audiodelivery.net/v1/api_key', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(payload)
});

const data = await response.json();
```

```
import Foundation

func performRequest() async throws {
    var request = URLRequest(url: URL(string: "https://api.audiodelivery.net/v1/api_key")!)
    request.httpMethod = "POST"
    request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    let bodyJSON = """
{
  "title": "Customer Player Key",
  "api_key_type_id": "player",
  "collection_id": "COLLECTION_ID"
}
"""
    request.httpBody = bodyJSON.data(using: .utf8)
    let (data, _) = try await URLSession.shared.data(for: request)
    let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]
    // use json
}
```

```
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody

val client = OkHttpClient()

suspend fun performRequest(): String = withContext(Dispatchers.IO) {
    val body = """{
  "title": "Customer Player Key",
  "api_key_type_id": "player",
  "collection_id": "COLLECTION_ID"
}""".toRequestBody("application/json".toMediaType())
    val request = Request.Builder()
        .url("https://api.audiodelivery.net/v1/api_key")
        .post(body)
        .addHeader("Authorization", "Bearer YOUR_API_KEY")
        .addHeader("Content-Type", "application/json")
        .build()
    val response = client.newCall(request).execute()
    response.body?.string() ?: error("Empty response body")
}
```

```
import 'dart:convert';
import 'package:http/http.dart' as http;

Future<Map<String, dynamic>> performRequest() async {
  final response = await http.post(
    Uri.parse("https://api.audiodelivery.net/v1/api_key"),
    headers: {
      "Authorization": "Bearer YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: jsonEncode({
  "title": "Customer Player Key",
  "api_key_type_id": "player",
  "collection_id": "COLLECTION_ID"
}),
  );
  if (response.statusCode < 200 || response.statusCode >= 300) {
    throw Exception('Request failed: ${response.statusCode}');
  }
  return jsonDecode(response.body) as Map<String, dynamic>;
}
```

#### Antwort

```
{
"ok": true,
"api_request_id": "uuid",
"api_key": "string"
}
```

#### Nur einmal angezeigt

Der vollständige `api_key` wird nur in dieser Antwort zurückgegeben und nie im Klartext gespeichert. Speichern Sie ihn sicher — er kann nicht erneut abgerufen werden.
