> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokencraft.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Tokenset

> Create a new tokenset in a workspace

# Create Tokenset

Creates a new tokenset within a workspace.

<Note>
  **Write access policy** - This endpoint requires the `write:tokens` scope.

  * TEAM-owned workspace: `owner`, `admin`, `editor` can write; `viewer` is blocked (`403`).
  * Non-TEAM workspace: only the workspace owner can write.
  * If the workspace owner plan has no API write access (for example FREE), write is blocked.
</Note>

## Endpoint

```
POST /workspaces/{id}/tokensets
```

## Authentication

Requires a valid API token in the Authorization header.

## Request

### Headers

| Header          | Value            | Required |
| --------------- | ---------------- | -------- |
| `Authorization` | Bearer token     | Yes      |
| `Content-Type`  | application/json | Yes      |

### Path Parameters

| Parameter | Type   | Required | Description  |
| --------- | ------ | -------- | ------------ |
| `id`      | string | Yes      | Workspace ID |

### Body Parameters

| Parameter     | Type   | Required | Description                        |
| ------------- | ------ | -------- | ---------------------------------- |
| `name`        | string | Yes      | Tokenset name (max 255 characters) |
| `description` | string | No       | Optional description               |

### Request Body

```json theme={null}
{
  "name": "Colors",
  "description": "Color tokens for the design system"
}
```

## Response

### Success Response

**Status:** `201 Created`

```json theme={null}
{
  "id": "tokenset-123",
  "workspace_id": "550e8400-e29b-41d4-a716-446655440000",
  "name": "Colors",
  "description": "Color tokens for the design system",
  "created_at": "2025-01-15T10:00:00Z",
  "updated_at": "2025-01-15T10:00:00Z"
}
```

## Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST https://app.tokencraft.dev/api/v1/workspaces/550e8400-e29b-41d4-a716-446655440000/tokensets \
    -H "Authorization: Bearer tkc_your_token_here" \
    -H "Content-Type: application/json" \
    -d '{
      "name": "Colors",
      "description": "Color tokens for the design system"
    }'
  ```

  ```javascript JavaScript theme={null}
  const workspaceId = '550e8400-e29b-41d4-a716-446655440000';

  const response = await fetch(
    `https://app.tokencraft.dev/api/v1/workspaces/${workspaceId}/tokensets`,
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer tkc_your_token_here',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        name: 'Colors',
        description: 'Color tokens for the design system'
      })
    }
  );

  const tokenset = await response.json();
  console.log('Created tokenset:', tokenset.id);
  ```

  ```python Python theme={null}
  workspace_id = '550e8400-e29b-41d4-a716-446655440000'

  response = requests.post(
      f'https://app.tokencraft.dev/api/v1/workspaces/{workspace_id}/tokensets',
      headers={
          'Authorization': 'Bearer tkc_your_token_here',
          'Content-Type': 'application/json'
      },
      json={
          'name': 'Colors',
          'description': 'Color tokens for the design system'
      }
  )

  tokenset = response.json()
  print(f"Created tokenset: {tokenset['id']}")
  ```
</CodeGroup>

## Error Responses

### 400 Bad Request

```json theme={null}
{
  "error": "Name is required and must be a non-empty string"
}
```

### 404 Not Found

```json theme={null}
{
  "error": "Workspace not found"
}
```

**Causes:**

* Workspace ID doesn't exist
* You do not have access to this workspace

## Use Cases

### 1. Create Multiple Tokensets

```javascript theme={null}
const categories = ['Colors', 'Typography', 'Spacing', 'Shadows'];

for (const category of categories) {
  await createTokenset(workspaceId, {
    name: category,
    description: `${category} tokens`
  });
}
```

### 2. Create with Default Mode

After creating a tokenset, you may want to create modes:

```javascript theme={null}
const tokenset = await createTokenset(workspaceId, {
  name: 'Colors'
});

// Create light and dark modes
await createMode(tokenset.id, { name: 'Light', is_default: true });
await createMode(tokenset.id, { name: 'Dark' });
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Update Tokenset" icon="pen" href="/api-reference/tokensets/update">
    Update tokenset details
  </Card>

  <Card title="Create Mode" icon="moon" href="/api-reference/modes/create">
    Add modes to your tokenset
  </Card>
</CardGroup>
