Skip to content
Scalekit Docs
Talk to an EngineerDashboard

API tokens

API tokens for service access

Create and validate API tokens for programmatic access to Scalekit APIs.

Use tokens for service access that is not a full end-user session. Create a token, store it securely, and validate it on incoming requests.

clientAPITokenshttps://github.com/scalekit-inc/scalekit-sdk-go/blob/main/token.go
#asyncCreateToken

Runs CreateToken and returns the result.

paramctxcontext.Context

Request context

paramorganizationIdstring

Organization ID.

paramoptionsCreateTokenOptions

Optional request settings.

returnsCreateTokenResponse

The created resource.

expiry := time.Now().Add(24 * time.Hour)
resp, err := scalekitClient.Token().CreateToken(ctx, "org_123", scalekit.CreateTokenOptions{
UserId: "usr_123",
Description: "Service account token",
CustomClaims: map[string]string{
"source": "service",
},
Expiry: &expiry,
})
if err != nil {
// handle
}
_ = resp.Token
clientAPITokenshttps://github.com/scalekit-inc/scalekit-sdk-go/blob/main/token.go
#asyncValidateToken

Runs ValidateToken and returns the result.

paramctxcontext.Context

Request context

paramtokenstring

Token string.

returnsValidateTokenResponse

Verified claims or result.

resp, err := scalekitClient.Token().ValidateToken(ctx, "api_token_here")
if err != nil {
// token is invalid or expired
}
_ = resp.Token
clientAPITokenshttps://github.com/scalekit-inc/scalekit-sdk-go/blob/main/token.go
#asyncInvalidateToken

Runs InvalidateToken and returns the result.

paramctxcontext.Context

Request context

paramtokenstring

Token string.

returnserror

error

if err := scalekitClient.Token().InvalidateToken(ctx, "api_token_here"); err != nil {
// handle
}
clientAPITokenshttps://github.com/scalekit-inc/scalekit-sdk-go/blob/main/token.go
#asyncListTokens

Runs ListTokens and returns the result.

paramctxcontext.Context

Request context

paramorganizationIdstring

Organization ID.

paramoptionsListTokensOptions

Optional request settings.

returnsListTokensResponse

Paginated results.

tokens, err := scalekitClient.Token().ListTokens(ctx, "org_123", scalekit.ListTokensOptions{})
if err != nil {
// handle
}
for _, token := range tokens.Tokens {
_ = token
}
// Filter by user ID
userTokens, err := scalekitClient.Token().ListTokens(ctx, "org_123", scalekit.ListTokensOptions{
UserId: "usr_123",
})
clientAPITokenshttps://github.com/scalekit-inc/scalekit-sdk-go/blob/main/token.go
#asyncUpdateToken

Runs UpdateToken and returns the result.

paramctxcontext.Context

Request context

paramtokenstring

Token string.

paramoptionsUpdateTokenOptions

Optional request settings.

returnsUpdateTokenResponse

The updated resource.