# API-Token erstellen

> Gibt ein neues API-Token zurück, das zu einem Benutzer gehört.
> Canonical HTML: https://tursodb.cn/de/docs/api-reference/tokens/create/
> Upstream Source (MIT): https://docs.turso.tech/api-reference/tokens/create
> Language: de

---
Das Token kann mit drei Einschränkungsstufen erstellt werden, in aufsteigender Reihenfolge der Einschränkung:

- **Organisationsbezogen** — übergeben Sie `organization` und optional `scopes`. Das Token kann nur auf Ressourcen innerhalb dieser Organisation zugreifen. Mit `scopes` kann es ausschließlich die aufgeführten Operationen in jeder Gruppe der Organisation ausführen.
- **Gruppenbezogen** — übergeben Sie `organization`, `group` und `scopes`. Das Token ist an eine einzelne Gruppe innerhalb der Organisation gebunden, und nur die in `scopes` aufgeführten Operationen sind erlaubt. Der Aufrufer muss Administrator oder Eigentümer der Organisation sein.
- **Uneingeschränkt** *(veraltet)* — kein Request-Body. Das Token kann auf jede Organisation zugreifen, zu der der Aufrufer gehört. **Uneingeschränkte Tokens sind veraltet und werden in einer zukünftigen Version entfernt.** Übergeben Sie für neue Tokens immer `organization` und rotieren Sie bestehende uneingeschränkte Tokens zu Tokens mit eingeschränktem Geltungsbereich.

Gruppenbezogene Tokens sind für Automatisierungen gedacht, die Datenbanken innerhalb einer einzelnen Gruppe bereitstellen und verwalten können sollen, ohne auf den Rest der Organisation zugreifen zu können.

<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">WARNUNG</div><div class="doc-callout-body">

Das `token` in der Antwort wird nie erneut angezeigt. Speichern Sie es an einem sicheren Ort und geben Sie es niemals weiter oder committen Sie es in die Versionskontrolle.

</div></div>


<div class="doc-callout doc-callout-warning"><div class="doc-callout-title">WARNUNG</div><div class="doc-callout-body">

**Uneingeschränkte (organisationsübergreifende) Tokens sind veraltet und werden in einer zukünftigen Version entfernt.** Fügen Sie im Request-Body immer mindestens `organization` ein.

</div></div>


```bash cURL (org-scoped)
curl -L -X POST https://api.turso.tech/v1/auth/api-tokens/{tokenName} \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"organization": "my-org"}'
```

```bash cURL (org-scoped, with scopes)
curl -L -X POST https://api.turso.tech/v1/auth/api-tokens/{tokenName} \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "organization": "my-org",
    "scopes": ["org:read"]
  }'
```

```bash cURL (deprecated, unrestricted)
curl -L -X POST https://api.turso.tech/v1/auth/api-tokens/{tokenName} \
  -H 'Authorization: Bearer TOKEN'
```

```bash cURL (group-scoped, presets)
curl -L -X POST https://api.turso.tech/v1/auth/api-tokens/{tokenName} \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "organization": "my-org",
    "group": "default",
    "scopes": ["read-only"]
  }'
```

```bash cURL (group-scoped, fine-grained)
curl -L -X POST https://api.turso.tech/v1/auth/api-tokens/{tokenName} \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "organization": "my-org",
    "group": "default",
    "scopes": ["db:create", "db:configure", "db:mint-token"]
  }'
```

```ts Node.js
import { createClient } from "@tursodatabase/api";

const turso = createClient({
  org: "...",
  token: "",
});

const apiToken = await turso.apiTokens.create("my-token");
```


## OpenAPI

````yaml POST /v1/auth/api-tokens/{tokenName}
openapi: 3.0.1
info:
  title: Turso Platform API
  description: API description here
  license:
    name: MIT
  version: 0.1.0
servers:
  - url: https://api.turso.tech
    description: Turso's Platform API
security: []
paths:
  /v1/auth/api-tokens/{tokenName}:
    post:
      summary: Create API Token
      description: >-
        Returns a new API token belonging to a user.


        The token can be minted at three levels of restriction, in increasing
        order of narrowness:


        - **Organization-scoped** — pass `organization`, and optionally
        `scopes`. The token can only act on resources inside that organization.
        With `scopes`, it can do only the listed operations, in every group of
        the organization.

        - **Group-scoped** — pass `organization`, `group`, and `scopes`. The
        token is pinned to a single group inside the organization and only the
        operations listed in `scopes` are allowed. The caller must be an admin
        or owner of the organization.

        - **Unrestricted** *(deprecated)* — no request body. The token can act
        on every organization the caller belongs to. **Unrestricted tokens are
        deprecated and will be removed in a future release.** Always pass
        `organization` for new tokens and rotate existing unrestricted tokens to
        scoped tokens.


        Group-scoped tokens are designed for automations that should be able to
        provision and manage databases inside a single group without being able
        to touch the rest of the organization.
      operationId: createAPIToken
      parameters:
        - $ref: '#/components/parameters/tokenName'
      requestBody:
        description: >-
          Optional restriction for the token. Omit the body for an unrestricted
          token, pass `organization` (optionally with `scopes`) for an
          org-scoped token, or pass `organization` + `group` + `scopes` for a
          group-scoped token.
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                organization:
                  type: string
                  description: >-
                    The organization slug to restrict this token to. Required
                    when `group` is set.
                  example: my-org
                group:
                  type: string
                  description: >-
                    The group name (inside `organization`) to restrict this
                    token to. Requires `organization` and a non-empty `scopes`
                    list.
                  example: default
                scopes:
                  type: array
                  items:
                    type: string
                    enum:
                      - read
                      - db:create
                      - db:delete
                      - db:configure
                      - db:mint-token
                      - db:rotate-creds
                      - group:configure
                      - group:mint-token
                      - group:rotate-creds
                      - group:create
                      - group:delete
                      - org:read
                      - read-only
                      - full-access
                  description: >-
                    Permissions to grant the token. Each entry is either an
                    individual scope or one of the presets `read-only` (expands
                    to `read`) and `full-access` (expands to every group scope,
                    without `group:create`, `group:delete`, and `org:read`).
                    Required and must be non-empty when `group` is set. Optional
                    for an org-scoped token: without `scopes`, the token can do
                    everything that its user can do in the organization.
                    `group:create`, `group:delete`, and `org:read` are valid
                    only on org-scoped tokens. `db:mint-token` lets the token
                    issue new SQL credentials; `db:rotate-creds` invalidates
                    every existing SQL token for the database — they are
                    deliberately separate because rotation is destructive.
                  example:
                    - db:create
                    - db:configure
                    - db:mint-token
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                properties:
                  name: b0a0a4ff-22dd-479f-9f31-1705bc92d0c3
                  id: 41a60187-13e0-4ce1-86ab-2dc2ed7fbf91
                  token:
                    type: string
                    description: >-
                      The actual token contents as a JWT. This is used with the
                      `Bearer` header, see [Authentication](/authentication) for
                      more details. **This token is never revealed again.**
                    example: ...
components:
  parameters:
    tokenName:
      name: tokenName
      in: path
      required: true
      schema:
        type: string
      description: The name of the api token.

````
