# API tokens

A person’s own login for scripts.

An SDK signs every request with your key: [Authentication](https://mailset.app/docs/authentication.md). To sign one yourself, see [Calling the API without an SDK](https://mailset.app/docs/authentication/http.md).

## The API token object

A person’s own login for scripts: its name and when it was used.

### Attributes

- `id` (string): The token’s id: what `tokens revoke` takes.
- `name` (string): The name it was given.
- `createdAt` (number): When it was made, in ms since the epoch.
- `lastSeenAt` (number): When it last made a call, in ms since the epoch.
- `expiresAt` (number): When it stops working, in ms since the epoch.

```json
{
  "id": "out_3f9a1c0e7b2d",
  "name": "Acme API",
  "createdAt": 1796048940000,
  "lastSeenAt": 1796048940000,
  "expiresAt": 1796048940000
}
```

Answered by [tokens.list](https://mailset.app/docs/api/tokens#tokens.list).

## tokens.list

List your API tokens.

`POST /v1/tokens.list`

Any signed-in person, with an API token.

### Parameters

It takes no input: send an empty object.

### Returns

`data` is a list of [API token objects](https://mailset.app/docs/api/tokens#token).

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.tokens.list();
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.tokens.list()
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Tokens.List(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.tokens.list
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->tokens->list();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.Token;
import java.util.List;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

List<Token> answer = mailset.tokens().list();
System.out.println(answer);
```

Rust:

```rust
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.tokens().list().await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/tokens.list \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{}}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset tokens list
```

### Response

```json
{
  "ok": true,
  "data": [
    {
      "id": "out_3f9a1c0e7b2d",
      "name": "Acme API",
      "createdAt": 1796048940000,
      "lastSeenAt": 1796048940000,
      "expiresAt": 1796048940000
    }
  ]
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/tokens#tokens-list)

## tokens.create

Create an API token. It is shown once.

`POST /v1/tokens.create`

Any signed-in person, with an API token. It can stop for a passkey approval.

### Parameters

- `name` (string, required): A name to tell it by, up to 64 characters. At most 64 characters.

Beside `input`:

- `approval` (string, optional): An approval’s id, once someone approved it with their passkey. Without one, the answer is `step_up_required` and names what to approve.

### Returns

`data` is an object with:

- `id` (string): The token’s id: what `tokens revoke` takes.
- `name` (string): The name it was given.
- `token` (string): The token itself, shown this once. It starts with `mst_`.
- `expiresAt` (number): When it stops working, in ms since the epoch: a year from now.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.tokens.create({
	name: "Deploy script",
});
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.tokens.create({"name": "Deploy script"})
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.TokensCreateParams{
		Name: "Deploy script",
	}
	answer, err := client.Tokens.Create(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.tokens.create(name: 'Deploy script')
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->tokens->create([
    'name' => 'Deploy script',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.TokensCreateParams;
import app.mailset.model.TokensCreateResult;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

var params = TokensCreateParams.builder()
        .name("Deploy script")
        .build();
TokensCreateResult answer =
        mailset.tokens().create(params);
System.out.println(answer);
```

Rust:

```rust
use mailset::types::TokensCreateParams;

// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset
    .tokens()
    .create(TokensCreateParams {
        name: "Deploy script".into(),
    })
    .await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/tokens.create \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"name":"Deploy script"}}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset tokens create "Deploy script"
```

### Response

```json
{
  "ok": true,
  "data": {
    "id": "out_3f9a1c0e7b2d",
    "name": "Acme API",
    "token": "text",
    "expiresAt": 1796048940000
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/tokens#tokens-create)

## tokens.revoke

Revoke an API token.

`POST /v1/tokens.revoke`

Any signed-in person, with an API token.

### Parameters

- `id` (string, required): The token’s id, from `tokens list`.

### Returns

`data` is an object with:

- `revoked` (boolean): True when the token was there to revoke.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_TOKEN from the environment.
const mailset = new Mailset();

const answer = await mailset.tokens.revoke({
	id: "d_4b8e2a6c9f1d3057b3e8a2c6",
});
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset()

answer = mailset.tokens.revoke(
    {"id": "d_4b8e2a6c9f1d3057b3e8a2c6"}
)
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.TokensRevokeParams{
		ID: "d_4b8e2a6c9f1d3057b3e8a2c6",
	}
	answer, err := client.Tokens.Revoke(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.tokens.revoke(
  id: 'd_4b8e2a6c9f1d3057b3e8a2c6'
)
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_TOKEN from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->tokens->revoke([
    'id' => 'd_4b8e2a6c9f1d3057b3e8a2c6',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.TokensRevokeParams;
import app.mailset.model.TokensRevokeResult;

// Reads MAILSET_TOKEN from the environment.
Mailset mailset = Mailset.fromEnv();

var params = TokensRevokeParams.builder()
        .id("d_4b8e2a6c9f1d3057b3e8a2c6")
        .build();
TokensRevokeResult answer =
        mailset.tokens().revoke(params);
System.out.println(answer);
```

Rust:

```rust
use mailset::types::TokensRevokeParams;

// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset
    .tokens()
    .revoke(TokensRevokeParams {
        id: "d_4b8e2a6c9f1d3057b3e8a2c6".into(),
    })
    .await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/tokens.revoke \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"id":"d_4b8e2a6c9f1d3057b3e8a2c6"}}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset tokens revoke d_4b8e2a6c9f1d3057b3e8a2c6
```

### Response

```json
{
  "ok": true,
  "data": {
    "revoked": true
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/tokens#tokens-revoke)

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content