Use this API to interact with service accounts.

The number of service accounts you can create depends on your subscription and offering:

  • On GitLab Premium and Ultimate, you can create an unlimited number of service accounts for all offerings.
  • On GitLab Free, limits vary by offering:
    • For GitLab.com, you can create up to 100 service accounts for each top-level group. This includes service accounts created in subgroups or projects.
    • For GitLab Self-Managed, you can create up to 100 service accounts for the entire instance. This includes service accounts created for the instance, a group, or a project.

You can also interact with service accounts through the users API. To manage SSH keys for service accounts, use the user SSH and GPG keys API.

List all group service accounts

GET /api/v4/groups/{id}/service_accounts

Lists all service accounts in a specified group. Use the page and per_page pagination parameters to filter the results. This feature was introduced in GitLab 17.1.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
order_by
Query
StringSort results by the specified field
Allowed values: id, username
Default: id
sort
Query
StringSort results in ascending or descending order
Allowed values: asc, desc
Default: desc

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Group not found—

Create a group service account

POST /api/v4/groups/{id}/service_accounts

Creates a service account in a specified group.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted when creating a new service account, generates an email address prefixed with service_account_group_. Custom email addresses require confirmation, unless the top-level group has a matching verified domain or email confirmation settings are turned off. Introduced in GitLab 17.9
nameStringName of the user. If omitted when creating a new service account, uses Service account user
usernameStringUsername of the user account. If omitted when creating a new service account, generates a username prefixed with service_account_group_

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Group not found—

Get a single group service account

GET /api/v4/groups/{id}/service_accounts/{user_id}

Gets a specified service account in a specified group. Returns 404 Not Found if the service account does not exist in the group, and 400 Bad Request if the user exists in the group but is not a service account.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Update a group service account

PATCH /api/v4/groups/{id}/service_accounts/{user_id}

Update a specified group service account. The username of a service account associated with a composite identity cannot be updated. This feature was introduced in GitLab 17.10.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted when creating a new service account, generates an email address prefixed with service_account_group_. Custom email addresses require confirmation, unless the top-level group has a matching verified domain or email confirmation settings are turned off. Introduced in GitLab 18.2
nameStringName of the user. If omitted when creating a new service account, uses Service account user
usernameStringUsername of the user account. If omitted when creating a new service account, generates a username prefixed with service_account_group_

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Delete a group service account

DELETE /api/v4/groups/{id}/service_accounts/{user_id}

Deletes a specified group service account. Available only for group Owners and administrators. This feature was introduced in GitLab 17.1.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account
hard_delete
Query
BooleanIf true, contributions that would usually be moved to a ghost user are deleted instead, along with groups owned solely by this service account

Responses

CodeDescriptionSchema
204Resource deleted—
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Group not found—

List all personal access tokens for a group service account

GET /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens

Lists all personal access tokens for a specified group service account. For tokens created with granular scopes, the response also includes a granular_scopes attribute. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.6. This feature was introduced in GitLab 17.11.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
revoked
Query
BooleanIf true, only returns revoked tokens. If false, only returns tokens that are not revoked
Example: false
state
Query
StringReturn tokens with the specified state
Allowed values: all, active, inactive
Example: active
created_before
Query
String (date-time)Return tokens created on or before the specified time
Example: 2022-01-01T00:00:00Z
created_after
Query
String (date-time)Return tokens created on or after the specified time
Example: 2021-01-01T00:00:00Z
last_used_before
Query
String (date-time)Return tokens last used on or before the specified time
Example: 2021-01-01T00:00:00Z
last_used_after
Query
String (date-time)Return tokens last used on or after the specified time
Example: 2022-01-01T00:00:00Z
expires_before
Query
String (date)Return tokens that expire before the specified date
Example: 2022-01-01
expires_after
Query
String (date)Return tokens that expire on or after the specified date
Example: 2021-01-01
search
Query
StringReturn tokens that include the specified value in their name
Example: token
sort
Query
StringSort results by the specified field and direction. Possible values are created_asc, created_desc, expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc, and name_desc
Example: created_desc
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
user_id
Path, required
IntegerID of the service account

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesPersonalAccessToken
400Bad Request—
401401 Unauthorized—
403Forbidden—
404404 Group Not Found—

Create a personal access token for a group service account

POST /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens

Creates a personal access token for a specified group service account. Available only for group Owners and administrators. The last_used_ips attribute was introduced in GitLab 19.4. This feature was introduced in GitLab 16.1.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the access token. Limited to 255 characters
Example: A token used for k8s
expires_atString (date)Expiration date of the access token in ISO format (YYYY-MM-DD). If undefined, the date is set to the maximum allowable lifetime limit
Example: 2021-01-31
name
Required
StringName of the access token
Example: My token
scopes
Required
Array of stringsArray of approved scopes. For a list of possible values, see access token scopes

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

Revoke a personal access token for a group service account

DELETE /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}

Revokes a specified personal access token for a group service account. This feature was introduced in GitLab 17.11.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
token_id
Path, required
IntegerID of the personal access token
user_id
Path, required
IntegerID of the service account

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
401Unauthorized—
403Forbidden—
404Not Found—

Rotate a personal access token for a group service account

POST /api/v4/groups/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}/rotate

Rotates a specified personal access token for a group service account. This revokes the existing token and creates a token with the same name, description, and scopes. Rotating a token with granular scopes returns those scopes in a granular_scopes attribute on the new token. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.5.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the group
token_id
Path, required
IntegerID of the personal access token
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
expires_atString (date)Date when the access token expires. Introduced in GitLab 17.9. If omitted, the new token expires one week after rotation when token expiry is enforced, and does not expire otherwise
Example: 2021-01-31

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

List all project service accounts

GET /api/v4/projects/{id}/service_accounts

Lists all service accounts in a specified project. Use the page and per_page pagination parameters to filter the results.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
order_by
Query
StringSort results by the specified field
Allowed values: id, username
Default: id
sort
Query
StringSort results in ascending or descending order
Allowed values: asc, desc
Default: desc

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Project not found—

Create a project service account

POST /api/v4/projects/{id}/service_accounts

Creates a service account in a specified project.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted, generates an email address prefixed with service_account_project_. Custom email addresses require confirmation, unless the top-level group has a matching verified domain or email confirmation settings are turned off
nameStringName of the user. If omitted, uses Service account user
usernameStringUsername of the user account. If omitted, generates a name prefixed with service_account_project_

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Project not found—

Get a single project service account

GET /api/v4/projects/{id}/service_accounts/{user_id}

Gets a specified service account in a specified project.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
user_id
Path, required
IntegerID of the service account

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Update a project service account

PATCH /api/v4/projects/{id}/service_accounts/{user_id}

Update a specified project service account.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted when creating a new service account, generates an email address prefixed with service_account_project_. Custom email addresses require confirmation, unless the top-level group has a matching verified domain or email confirmation settings are turned off
nameStringName of the user. If omitted when creating a new service account, uses Service account user
usernameStringUsername of the user account. If omitted when creating a new service account, generates a name prefixed with service_account_project_

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 User not found—

Delete a project service account

DELETE /api/v4/projects/{id}/service_accounts/{user_id}

Deletes a specified project service account. Available only for project Owners, Maintainers, and administrators.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
user_id
Path, required
IntegerID of the service account
hard_delete
Query
BooleanIf true, contributions that would usually be moved to a ghost user are deleted instead, along with groups owned solely by this service account

Responses

CodeDescriptionSchema
204No Content—
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Project not found—

List all personal access tokens for a project service account

GET /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens

Lists all personal access tokens for a specified project service account. For tokens created with granular scopes, the response also includes a granular_scopes attribute. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.6.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
revoked
Query
BooleanIf true, only returns revoked tokens. If false, only returns tokens that are not revoked
Example: false
state
Query
StringReturn tokens with the specified state
Allowed values: all, active, inactive
Example: active
created_before
Query
String (date-time)Return tokens created on or before the specified time
Example: 2022-01-01T00:00:00Z
created_after
Query
String (date-time)Return tokens created on or after the specified time
Example: 2021-01-01T00:00:00Z
last_used_before
Query
String (date-time)Return tokens last used on or before the specified time
Example: 2021-01-01T00:00:00Z
last_used_after
Query
String (date-time)Return tokens last used on or after the specified time
Example: 2022-01-01T00:00:00Z
expires_before
Query
String (date)Return tokens that expire before the specified date
Example: 2022-01-01
expires_after
Query
String (date)Return tokens that expire on or after the specified date
Example: 2021-01-01
search
Query
StringReturn tokens that include the specified value in their name
Example: token
sort
Query
StringSort results by the specified field and direction. Possible values are created_asc, created_desc, expires_asc, expires_desc, last_used_asc, last_used_desc, name_asc, and name_desc
Example: created_desc
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
user_id
Path, required
IntegerID of the service account

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesPersonalAccessToken
400Bad Request—
401401 Unauthorized—
403Forbidden—
404404 Project Not Found—

Create a personal access token for a project service account

POST /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens

Creates a personal access token for a specified project service account. Available only for project Owners, Maintainers, and administrators. The last_used_ips attribute was introduced in GitLab 19.4.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
descriptionStringDescription of the access token. Limited to 255 characters
Example: A token used for k8s
expires_atString (date)Expiration date of the access token in ISO format (YYYY-MM-DD). If undefined, the date is set to the maximum allowable lifetime limit
Example: 2021-01-31
name
Required
StringName of the access token
Example: My token
scopes
Required
Array of stringsArray of approved scopes. For a list of possible values, see access token scopes

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

Revoke a personal access token for a project service account

DELETE /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}

Revokes a specified personal access token for a project service account.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
token_id
Path, required
IntegerID of the personal access token
user_id
Path, required
IntegerID of the service account

Responses

CodeDescriptionSchema
204No Content—
400Bad Request—
401Unauthorized—
403Forbidden—
404Not Found—

Rotate a personal access token for a project service account

POST /api/v4/projects/{id}/service_accounts/{user_id}/personal_access_tokens/{token_id}/rotate

Rotates a specified personal access token for a project service account. This revokes the existing token and creates a token with the same name, description, and scopes. Rotating a token with granular scopes returns those scopes in a granular_scopes attribute on the new token. The last_used_ips attribute was introduced in GitLab 19.4. The granular_scopes attribute was introduced in GitLab 19.5.

Parameters

NameTypeDescription
id
Path, required
String or integerID or URL-encoded path of the project
token_id
Path, required
IntegerID of the personal access token
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
expires_atString (date)Date when the access token expires. Introduced in GitLab 17.9. If omitted, the new token expires one week after rotation when token expiry is enforced, and does not expire otherwise
Example: 2021-01-31

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesPersonalAccessTokenWithToken
400Bad Request—
404Not Found—

List all instance service accounts

GET /api/v4/service_accounts

Lists all instance service accounts. Use the page and per_page pagination parameters to filter the results. This feature was introduced in GitLab 17.1.

Parameters

NameTypeDescription
page
Query
IntegerPage number of results to retrieve
Default: 1
Example: 1
per_page
Query
IntegerNumber of items to list per page
Default: 20
Example: 20
order_by
Query
StringSort results by the specified field
Allowed values: id, username
Default: id
sort
Query
StringSort results in ascending or descending order
Allowed values: asc, desc
Default: desc

Responses

CodeDescriptionSchema
200OKArray of APIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—

Create an instance service account

POST /api/v4/service_accounts

Creates an instance service account. If the email address is already in use by another user, 400 Bad request is returned.

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted, generates a no-reply email address prefixed with service_account_. Custom email addresses require confirmation, unless the email confirmation settings are turned off. Introduced in GitLab 17.9
externalBooleanFlag indicating the user is an external user. Default is true. Introduced in GitLab 19.5
nameStringName of the user. If omitted, uses Service account user
usernameStringUsername of the user account. If omitted, generates a name prefixed with service_account_

Responses

CodeDescriptionSchema
201CreatedAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—

Update an instance service account

PATCH /api/v4/service_accounts/{user_id}

Updates a specified instance service account. This feature was introduced in GitLab 18.2.

Parameters

NameTypeDescription
user_id
Path, required
IntegerID of the service account

Request body (application/json)

PropertyTypeDescription
emailStringEmail address of the user account. If omitted when creating a new service account, generates a no-reply email address. Custom email addresses require confirmation, unless the email confirmation settings are turned off
externalBooleanFlag indicating the user is an external user. Introduced in GitLab 19.5
nameStringName of the user. If omitted when creating a new service account, uses Service account user
usernameStringUsername of the user account. If omitted when creating a new service account, generates a name prefixed with service_account_

Responses

CodeDescriptionSchema
200OKAPIEntitiesServiceAccount
400400 Bad request—
401401 Unauthorized—
403403 Forbidden—
404404 Not found—

Schemas

Objects returned by the operations above and objects nested in their request bodies.

APIEntitiesGranularScope

PropertyTypeDescription
accessStringExample: personal_projects
group_idInteger (int64)Example: 5
permissionsArrayExample: ["read_job"]
project_idInteger (int64)Example: 3

APIEntitiesPersonalAccessToken

PropertyTypeDescription
activeBoolean—
created_atString (date-time)—
descriptionStringExample: Token to manage api
expires_atString (date-time)Example: 2020-08-31T15:53:00.073Z
granularBoolean—
granular_scopesArray of APIEntitiesGranularScope—
idInteger (int64)Example: 2
last_used_atString (date-time)Example: 2020-08-31T15:53:00.073Z
last_used_ipsArray of stringsThe five most recent unique IP addresses that have authenticated with this token. When the limit is reached, the oldest IP address is removed. The list updates once per minute per token
Example: ["127.0.0.1","127.0.0.2","127.0.0.3"]
nameStringExample: John Doe
revokedBoolean—
scopesArrayExample: ["api"]
user_idInteger (int64)Example: 3

APIEntitiesPersonalAccessTokenWithToken

PropertyTypeDescription
activeBoolean—
created_atString (date-time)—
descriptionStringExample: Token to manage api
expires_atString (date-time)Example: 2020-08-31T15:53:00.073Z
granularBoolean—
granular_scopesArray of APIEntitiesGranularScope—
idInteger (int64)Example: 2
last_used_atString (date-time)Example: 2020-08-31T15:53:00.073Z
last_used_ipsArray of stringsThe five most recent unique IP addresses that have authenticated with this token. When the limit is reached, the oldest IP address is removed. The list updates once per minute per token
Example: ["127.0.0.1","127.0.0.2","127.0.0.3"]
nameStringExample: John Doe
revokedBoolean—
scopesArrayExample: ["api"]
tokenStringExample: glpat-<example-token>
user_idInteger (int64)Example: 3

APIEntitiesServiceAccount

PropertyTypeDescription
emailStringEmail address of the service account
Example: service_account@example.com
externalBooleanExample: true
idInteger (int64)ID of the user
Example: 1
nameStringName of the user. For a bot user, **** if the current user cannot read the bot’s project or group
Example: Administrator
public_emailStringPublic email address of the user
Example: john@example.com
unconfirmed_emailStringEmail address awaiting confirmation. Returned only when a confirmation is pending
Example: updated_service_account@example.com
usernameStringUsername of the user
Example: admin