> For the complete documentation index, see [llms.txt](https://docs.lenses.io/latest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lenses.io/latest/devx/6.1/user-guide/iam/service-accounts.md). Agents can also search and read this documentation through its [MCP server](https://docs.lenses.io/latest/~gitbook/mcp).

# Service Accounts

This page describes service accounts in Lenses.

Service accounts are intended for programmatic access to Lenses.

{% hint style="info" %}
Service accounts are assigned to groups. The groups inherit permissions from the roles assigned to the groups.
{% endhint %}

Each service account has a token used to authenticate and identify it.

You can also set:

1. Description
2. Resource name (must be unique across Lenses)
3. Token expiry
4. Regenerate the token

Token expiry can be 7, 30, 60, 90 days, 1 year, a custom expiry, or no expiry.

## Create a Service Account

To create a service account, go to **IAM → Service Accounts → New Service Account**. After creation, assign the service account to one or more groups.

<figure><img src="https://880527424-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNwC1VSrH2RhBa4WJMBdQ%2Fuploads%2Fgit-blob-68f88e47a868e5b216d9b96fd459dec267240485%2Fiam-service-account.PNG?alt=media" alt=""><figcaption><p>IAM Service Account</p></figcaption></figure>

You can also manage service accounts via the CLI and YAML, for CI/CD automation.

{% code title="terminal" %}

```shell
➜  hq service-accounts
Manage ServiceAccounts.

Usage:
  hq service-accounts [command]

Aliases:
  service-accounts, sa

Available Commands:
  create      Creates a new ServiceAccount.
  delete      Deletes a ServiceAccount.
  get         Returns a specific ServiceAccount.
  list        Returns all ServiceAccounts.
  metadata    Manages service-account metadata.
  renew-token Renews the service account's token. The current token is invalidated and a new one is generated. An optional expiration timestamp can be provided.
  set-groups  Assigns the given service account exactly to the provided groups, ensuring they are not part of any other groups.
  update      Updates a service account.
```

{% endcode %}

## API Calls

When calling the Lenses APIs, send the service account token in the `Authorization` header:

```http
Authorization: Bearer <service_account_token>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lenses.io/latest/devx/6.1/user-guide/iam/service-accounts.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
