---
title: "Generate Token"
method: PUT
path: "/v2/databases/{db_id}/auth/generate"
tags: ["Database (v2)"]
---

# Generate Token

`PUT /v2/databases/{db_id}/auth/generate`

## Request

- Base URL: `https://api.bunny.net/database`
- URL: `https://api.bunny.net/database/v2/databases/{db_id}/auth/generate`
- Auth: one of:
  - API key in header `Authorization`
  - API key in header `AccessKey`
- TypeScript: <https://skmtc.dev/bunny/apis/bunny-database-backend-api/docs/v2/databases/:db_id/auth/generate/put.ts> (a function with typed inputs; its response is checked against the schema)

Generate a new token for the whole Database

## Path parameters

- `db_id` string, required: [DatabaseId] is a `db_<ulid>`

## Request body

- GenerateTokenDatabaseV2Payload
  - `expires_at` string, date-time, nullable: The expired at date for the token, if not degined the token won't expire until you invalidate the JWT Secrets. Needs to be a date-time under the [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339)
  - `authorization` 'full-access' | 'read-only', required

## Response `200`

- GenerateTokenDatabaseV2Response
  - `token` string, required: The generated JWT for the [Database].
  - `expires_at` string, date-time, nullable: The expired at date for the token. A date-time under the [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339)

## Other responses

- `401`: A default error response for most API errors.
- `403`: A default error response for most API errors.
- `404`: A default error response for most API errors.
- `500`: A default error response for most API errors.

## Changes

- **2026-11-12** `f3bb69bad6b6`: 2 info
  - added the non-success response with the status `403`
  - added the non-success response with the status `404`

[Operation history](https://skmtc.dev/bunny/apis/bunny-database-backend-api/changes/v2/databases/:db_id/auth/generate/put.md)

---

[API](https://skmtc.dev/bunny/apis/bunny-database-backend-api.md) - [All operations](https://skmtc.dev/bunny/apis/bunny-database-backend-api/llms.txt) - [OpenAPI document](https://skmtc.dev/bunny/apis/bunny-database-backend-api/revisions/f3bb69bad6b6?raw)
