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

# API Keys and Service Accounts

> Create personal API keys and service accounts, choose what each key can reach, set daily limits, and replace or revoke keys.

An API key lets your own code call the [ClarityQ API](https://docs.clarityq.ai/api-reference.md): ask a question, read the answer, pull usage, and more. A key can only call the public API. It can't sign in to the app or reach the rest of the product.

## Two Kinds of Keys

| | **Personal API key** | **Service account key** |
| - | - | - |
| Acts as | You | A service account that belongs to the organization |
| Role | Your role | The role an Admin gave the service account |
| Workspaces | Every workspace you can access | The workspaces an Admin chose for the service account |
| Who creates it | Anyone whose role can use Ask Anything | Admins |
| When someone leaves | Deleted with the user | Keeps working |
| Use it for | Your own scripts and analysis | Integrations your team depends on |

## Personal API Keys

A personal key acts as you. It can do what you can do in ClarityQ, in every workspace you can access. If your role or your workspaces change, the key follows on its next call.

Questions you ask with a personal key appear in your own chat history, marked with a key icon.

To create one:

**1. Open your API keys**

Open your profile menu, choose **Settings**, then **API keys**.

**2. Generate the key**

Click **Generate API Key** and give it a **Key name**. You can also set a **Daily prompt limit** for it.

**3. Copy it**

The key is shown once. Copy it and store it somewhere safe. You can't see it again.

Each key has a menu with **View usage**, **Edit limit**, and **Revoke**. **View usage** shows how many prompts the key used in the last 24 hours.

## Service Accounts

A service account belongs to the organization, not to a person. Its keys keep working when people leave or change roles, so use one for anything your team relies on.

Only **Admins** can create and manage service accounts. Go to **Organization Settings → API → Service accounts** and click **Generate Service Account**. Fill in:

* **Service account name** and an optional **Description**.
* **Role**: Admin, Analyst Contributor, Analyst, or Business User. The role decides what the service account's keys can do, the same way a role does for a person.
* **Workspaces**: **All workspaces** also covers workspaces you add later. **Selected workspaces** limits the service account to the ones you pick.
* **First API key**: every new service account gets one key. Give it a name and, if you want, a daily prompt limit.

The key is shown once. Copy it before you close the dialog.

A service account reaches only its own workspaces, whatever its role. An Admin service account limited to two workspaces reaches two.

> [!NOTE]
>
> Service accounts have no data warehouse login of their own. In a workspace where [each user signs in with their own warehouse account](https://docs.clarityq.ai/data-warehouse/signing-in-with-your-own-account.md), a service account uses the workspace's shared login and sees all rows.

### Managing a Service Account

Each service account has a menu:

* **Edit**: change its name, description, role, or workspaces. Changes apply to all of its keys from their next call.
* **View prompts**: opens the [Usage Dashboard](https://docs.clarityq.ai/admin/usage-dashboard.md) filtered to this service account.
* **Delete**: revokes all of its keys. Integrations that use them stop working right away. Its past prompts stay on the Usage page.

To add another key to a service account, open the **API keys** tab, click **Generate API Key**, and pick the service account.

## All Keys in the Organization

The **API keys** tab under **Organization Settings → API** lists every key in the organization: service account keys and everyone's personal keys. Admins can search and filter the list, export it to CSV, and use **Edit limit** or **Revoke** on any key.

## Finding a Workspace ID

Every API call needs a workspace ID in its URL. In the API reference this value is called `product_id`.

* For a personal key, click **View workspace IDs** on your **API keys** page.
* For a service account, click its **Workspaces** value in the service accounts list.

Both open a list of workspace names and IDs, with a button to copy each ID.

## Daily Prompt Limits

Any key can have a daily prompt limit. It counts the questions the key asked in a rolling 24 hours. When the key reaches its limit, [Ask a Question](https://docs.clarityq.ai/api-reference/api/ask-a-question.md) returns `429` until older questions fall out of the 24-hour window.

* **Organization default**: an Admin sets it with the **API settings** icon on the **API keys** tab. It applies to every key that has no limit of its own.
* **One key**: use **Edit limit** on the key. An Admin can do this for any key. You can do it for your own personal keys.

A key with no limit of its own uses the organization default. If there is no default either, the key has no daily limit.

Daily limits are separate from your organization's monthly usage limits. See [Usage Limits and Top-Ups](https://docs.clarityq.ai/admin/usage-limits-and-top-ups.md) for how API usage counts toward those.

## Expiry and Replacing Keys

Every key expires one year after it is created. ClarityQ sends an email reminder 30, 14, 7, and 1 day before. For a personal key the email goes to you. For a service account key it goes to every Admin.

To replace a key, generate a new one, switch your code to it, then **Revoke** the old one. Revoking takes effect right away.

## When Someone Leaves

Deleting a user deletes their personal API keys, so scripts that use them stop working. Service account keys that person created keep working, because they belong to the organization.

## Keys Created Before Service Accounts

API keys created before service accounts were introduced keep working with the same secret, expiry date, and daily limit. Each one now belongs to its own service account, named after the key, with the Admin role and the one workspace the key was created for. You can edit that service account like any other.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.