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

# API Management

> Manage API keys, enrollment tokens, and driver machines

## Overview

The API Management page is your central hub for:

* **API Keys** - Authenticate external API calls
* **Enrollment Tokens** - Register new driver machines
* **VM Machines** - Monitor connected drivers

<Frame>
  <img src="https://mintcdn.com/granite/KSlfQAiLmsRX4ksG/images/dashboard/api-management.png?fit=max&auto=format&n=KSlfQAiLmsRX4ksG&q=85&s=835a4b4140f9ad8e2ab36da843039564" alt="API Management page" width="1908" height="951" data-path="images/dashboard/api-management.png" />
</Frame>

***

## API Keys

API keys authenticate requests to your public endpoints.

### Creating an API Key

<Steps>
  <Step title="Click Create API Key">
    In the API Keys section, click **+ Create Key**
  </Step>

  <Step title="Name Your Key">
    Give it a descriptive name like "Production Backend" or "CI/CD Pipeline"
  </Step>

  <Step title="Copy the Key">
    **Important:** Copy the key immediately. It's only shown once!

    ```
    gk_live_a1b2c3d4e5f6g7h8i9j0...
    ```
  </Step>
</Steps>

<Warning>
  **Store your API key securely.** It grants full access to run automations. If compromised, revoke it immediately and create a new one.
</Warning>

### Using API Keys

Include the key in the `X-Granite-API-Key` header:

```bash theme={null}
curl -X POST "https://api.getgranite.ai/api/your-org/endpoint" \
  -H "X-Granite-API-Key: gk_live_abc123..."
```

### Managing Keys

| Action     | How                                    |
| ---------- | -------------------------------------- |
| **View**   | See key name, creation date, last used |
| **Revoke** | Click the trash icon to delete         |

<Note>
  You can have multiple API keys for different services or environments.
</Note>

### API Key Best Practices

<AccordionGroup>
  <Accordion title="Use separate keys for different services">
    Create distinct keys for production, staging, and different integrations. If one is compromised, you only revoke that one.
  </Accordion>

  <Accordion title="Rotate keys periodically">
    Every 90 days, create a new key and phase out the old one.
  </Accordion>

  <Accordion title="Never commit keys to git">
    Use environment variables or secret managers instead.
  </Accordion>

  <Accordion title="Monitor usage">
    Check Analytics to see if keys are being used unexpectedly.
  </Accordion>
</AccordionGroup>

***

## Enrollment Tokens

Enrollment tokens are one-time-use codes for registering new driver machines.

### Creating an Enrollment Token

<Steps>
  <Step title="Click Create Token">
    In the Enrollment Tokens section, click **+ Create Token**
  </Step>

  <Step title="Copy the Token">
    A new token is generated:

    ```
    enroll_x7y8z9a1b2c3...
    ```
  </Step>

  <Step title="Use on Driver Machine">
    Run the driver with this token to register it to your organization
  </Step>
</Steps>

### Token Properties

| Property               | Description                         |
| ---------------------- | ----------------------------------- |
| **One-time use**       | Token is consumed after enrollment  |
| **24-hour expiry**     | Unused tokens expire after 24 hours |
| **Organization-bound** | Driver joins your specific org      |

### Revoking Tokens

If a token hasn't been used yet, you can revoke it:

1. Find the token in the list
2. Click the trash icon
3. Confirm revocation

***

## VM Machines (Drivers)

View all driver machines connected to your organization.

### Machine List

Each entry shows:

| Field           | Description                                   |
| --------------- | --------------------------------------------- |
| **Name**        | Machine identifier                            |
| **Status**      | Online (green), Offline (gray), Busy (yellow) |
| **Last Seen**   | When it last communicated                     |
| **Current Job** | What it's working on (if busy)                |

### Machine Status

<CardGroup cols={3}>
  <Card title="Online" icon="circle" color="#22C55E">
    Ready to accept jobs
  </Card>

  <Card title="Busy" icon="circle" color="#F59E0B">
    Currently running an automation
  </Card>

  <Card title="Offline" icon="circle" color="#6B7280">
    Not connected
  </Card>
</CardGroup>

### Managing Machines

From the machine detail view, you can:

* **View details** - IP address, OS version, capabilities
* **See job history** - What it has run recently
* **Remove machine** - Unregister from your organization

<Warning>
  Removing a machine means it can't run automations for your organization anymore. You'll need a new enrollment token to re-add it.
</Warning>

***

## Queue Status

The API Management page also shows queue metrics:

| Metric             | Description                      |
| ------------------ | -------------------------------- |
| **Jobs Queued**    | Automations waiting for a driver |
| **Avg Wait Time**  | How long jobs wait in queue      |
| **Active Drivers** | Number of online machines        |

<Tip>
  If wait times are high and you have many queued jobs, consider adding more driver machines.
</Tip>

***

## SDK Example

Manage API keys programmatically:

```typescript theme={null}
import { client } from '@getgraniteai/ts-sdk';

// List API keys
const keys = await client.listApiKeys({
  organizationId: 'org_123'
});

// Create new key
const newKey = await client.createApiKey({
  organizationId: 'org_123',
  name: 'Production Backend'
});

// Revoke key
await client.revokeApiKey({
  organizationId: 'org_123',
  keyId: 'key_abc'
});
```

***

## Next Steps

<CardGroup cols={2}>
  <Card title="API Endpoints" icon="globe" href="/dashboard/api-endpoints">
    Create endpoints to call
  </Card>

  <Card title="Driver Setup" icon="desktop" href="/driver/installation">
    Add more machines
  </Card>
</CardGroup>
