Skip to main content

Create Personal Access Token

Create a personal access token for the authenticated user.

Endpoint

POST /api/v1/auth/tokens

Headers

HeaderRequiredDescription
AuthorizationYesBearer <access_token>
Content-TypeYesapplication/json

Request Body

{
"name": "My API Token",
"scopes": ["read", "write"],
"expires_in_days": 90,
"organization_id": 1
}

Parameters

FieldTypeRequiredDescription
namestringYesToken name/description
scopesarrayYesToken scopes
expires_in_daysintegerNoToken expiration in days (optional)
organization_idintegerNoOrganization ID for org-scoped token

Response

Success (201)

{
"success": true,
"data": {
"id": 1,
"name": "My API Token",
"token": "pat_abc123def456...",
"scopes": ["read", "write"],
"organization_id": 1,
"expires_at": "2024-04-01T12:00:00Z",
"created_at": "2024-01-01T12:00:00Z",
"message": "Personal access token created successfully"
},
"message": "Personal access token created successfully"
}

Error (400)

{
"success": false,
"error": {
"code": "token_creation_failed",
"message": "User is not a member of this organization"
}
}

Features

  • Individual user tokens: No organization_id specified
  • Organization-scoped tokens: Specify organization_id (must be member)
  • Token expiration linked to organization settings for org-scoped tokens
  • Token shown only once at creation
  • Custom expiration support (expires_in_days)

Important Notes

WARNING: Save the token immediately after creation, it won't be shown again!

Example

curl -X POST "https://api.rivergen.com/api/v1/auth/tokens" \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "My API Token",
"scopes": ["read", "write"],
"expires_in_days": 90,
"organization_id": 1
}'