Turso.Tokens (turso v0.1.1)
View SourceAPI token management for Turso Cloud Platform.
This module provides functions for managing API tokens that are used to authenticate with the Turso Platform API. These are different from database tokens, which are used for libSQL connections.
Summary
Functions
Creates a new API token.
Lists all API tokens for the authenticated user.
Retrieves information about a specific API token.
Revokes (deletes) an API token.
Validates the current API token.
Types
@type api_result(success_type) :: Turso.api_result(success_type)
@type token() :: Turso.token()
Functions
@spec create(Turso.t(), String.t(), keyword()) :: api_result(token())
Creates a new API token.
Important: The token value is only returned once during creation. Make sure to store it securely as it cannot be retrieved again.
Options
:description(String.t/0) - Optional description for the token.
Examples
# Basic token creation
{:ok, token} = Turso.Tokens.create(client, "my-app-token")
# Token with description
{:ok, token} = Turso.Tokens.create(client, "my-app-token",
description: "Token for production deployment"
)Parameters
client- The Turso clientname- A unique name for the token
Returns
{:ok, token()}- Created token object with the token value{:error, map()}- Error details
Security Note
The returned token object will contain the actual token value in a field
like token or value. This is the only time you'll be able to access
the token value, so store it securely immediately.
@spec list(Turso.t()) :: api_result(map())
Lists all API tokens for the authenticated user.
Examples
{:ok, tokens} = Turso.Tokens.list(client)Returns
{:ok, list(token())}- List of API token objects{:error, map()}- Error details
Token Object
Each token object typically contains:
name- Token name/identifierid- Unique token IDcreated_at- Creation timestamplast_used_at- Last usage timestamp (if available)
@spec retrieve(Turso.t(), String.t()) :: api_result(token())
Retrieves information about a specific API token.
Examples
{:ok, token} = Turso.Tokens.retrieve(client, "my-app-token")Parameters
client- The Turso clientname- The name of the token to retrieve
Returns
{:ok, token()}- Token information (without the token value){:error, map()}- Error details
Note
This endpoint returns metadata about the token but not the actual token value. Token values are only provided during creation and cannot be retrieved later.
@spec revoke(Turso.t(), String.t()) :: api_result(map())
Revokes (deletes) an API token.
Warning: This action is irreversible. The token will be immediately invalidated and cannot be recovered.
Examples
{:ok, _} = Turso.Tokens.revoke(client, "my-app-token")Parameters
client- The Turso clientname- The name of the token to revoke
Returns
{:ok, map()}- Revocation confirmation{:error, map()}- Error details
Security Note
You cannot revoke the token that is currently being used to authenticate the request. Use a different token or the Turso CLI to revoke the current token.
@spec validate(Turso.t()) :: api_result(map())
Validates the current API token.
This endpoint can be used to check if the current token is valid and retrieve information about it.
Examples
{:ok, token_info} = Turso.Tokens.validate(client)Returns
{:ok, map()}- Token validation information{:error, map()}- Error details (likely invalid token)
Validation Response
The validation response typically contains:
valid- Whether the token is validtoken_name- Name of the tokenexpires_at- Token expiration (if applicable)