Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

User tokens

Create, list, retrieve, and delete user API tokens through platform-api to automate token management.

Create and manage API tokens for a DataOS user programmatically, without using the API Tokens panel or the CLI. Use these endpoints to automate token provisioning in onboarding, deployment, or CI workflows. For how tokens work, including scope and expiry, see API tokens.

Method
Path
Use it to

POST

/v1/users/{user_id}/tokens

Create a token

GET

/v1/users/{user_id}/tokens

List a user's tokens

GET

/v1/users/{user_id}/tokens/{token_name}

Retrieve one token

DELETE

/v1/users/{user_id}/tokens/{token_name}

Delete a token

All paths are relative to $BASE_URL (<DATAOS_FQDN>/platform-api). See Authentication.

Authentication and access

Authenticate each request with an apikey header (or a Bearer token). You can manage only the tokens of the user that your API key belongs to. If user_id in the path is a different user, the request returns 403 Forbidden.

Path Parameters

Name
Type
Description

user_id

string

Required. DataOS user ID, e.g. iamgroot

token_name

string

Required for retrieve and delete. Token name, e.g. cli-token

Headers

Name
Value

apikey or Authorization

<your-apikey> or Bearer <access_token>. Required when gateway auth is enabled. See Authentication

Accept

application/json (recommended)

Content-Type

application/json. Required for create

Dataos-Correlation-Id

Optional tracing ID. Echoed back in the response when provided

Create a token

POST /v1/users/{user_id}/tokens

Creates an API token for the user. The token value is returned only in this response.

Request Body

Field
Type
Description

name

string

Required. Token name. Use a name you'll recognize later, because you retrieve and delete tokens by name

description

string

Token description

duration

string

How long the token stays valid, e.g. 24h or 720h (30 days)

type

string

Token type, e.g. apikey

use_existing

boolean

If true and a token with the same name already exists, return that token instead of creating a new one

user_id

string

User ID. Optional; the user_id in the path always takes precedence

cURL:

Response

data.apikey holds the token value. expiration is when the token stops working.

Invalid request body, for example a missing name.

Missing or invalid API key.

The API key is valid but belongs to a different user than user_id.

List tokens

GET /v1/users/{user_id}/tokens

Lists the user's active tokens. Expired and deleted tokens don't appear.

cURL:

Response

An array of token objects. data is empty or omitted, because the token value is not returned after creation.

Missing or invalid API key.

The API key belongs to a different user than user_id.

The user doesn't exist.

Retrieve a token

GET /v1/users/{user_id}/tokens/{token_name}

Returns the metadata for one token: name, description, type, user, and expiration.

cURL:

Response

Same fields as the create response. data is empty or omitted, because the token value is not returned after creation.

The API key belongs to a different user than user_id.

The user or token doesn't exist, or the token was deleted.

Delete a token

DELETE /v1/users/{user_id}/tokens/{token_name}

Deletes the token. Anything using it can no longer authenticate. Deletion can't be undone.

cURL:

Response

No content. The token is deleted. A later request to retrieve it returns 404.

The API key belongs to a different user than user_id.

The user or token doesn't exist.

Token expiry

Set duration when you create a token, for example 24h or 720h. The response's expiration field shows when the token expires. After that time:

  • The token stops authenticating requests.

  • The token no longer appears in List tokens.

Because tokens can't be updated, you can't extend an expiry. To rotate a token, create a new one, switch your integrations to it, then delete the old one.

Errors

All endpoints return errors in this shape:

Status
When it occurs

400

The create request body is invalid

401

The API key is missing or invalid

403

The API key is valid, but belongs to a different user than user_id

404

The user or token doesn't exist, or the token was deleted

500

Internal error

502

The token service is unavailable. Retry the request

Notes

  • The token value is returned only once, in the create response. Store it securely.

  • Tokens can't be updated after creation. Delete and recreate a token to change it.

  • These endpoints manage tokens. They don't change how you authenticate to platform-api.

Last updated

Was this helpful?