---
title: "Service account SDK reference"
description: "Customer-hosted cloud features"
---

# Service account SDK reference

#### Customer-hosted cloud features

:::note
Some features are only available on customer-hosted clouds. Reach out to [support@anyscale.com](mailto:support@anyscale.com) for info.
:::

## Service account SDK

### `anyscale.service_account.create`

Create a service account and return the API key.

**Arguments**

-   **`name` (str)**: Name for the service account.

**Returns**: str

#### Examples

::::tabs

:::tab[Python]
```python
import anyscale

api_key = anyscale.service_account.create(
    name="my-service-account",
)
```
:::

::::

### `anyscale.service_account.create_api_key`

Create an API key for the service account and return the API key.

**Arguments**

-   **`email` (str | None) = None**: Email of the service account to create the new key for.
-   **`name` (str | None) = None**: Name of the service account to create the new key for.

**Returns**: str

#### Examples

::::tabs

:::tab[Python]
```python
import anyscale

api_key = anyscale.service_account.create_api_key(
    name="my-service-account",
)
```
:::

::::

### `anyscale.service_account.rotate_api_keys`

Rotate all api keys of a service account and return the new API key.

**Arguments**

-   **`email` (str | None) = None**: Rotate API keys for the service account with this email.
-   **`name` (str | None) = None**: Rotate API keys for the service account with this name.

**Returns**: str

#### Examples

::::tabs

:::tab[Python]
```python
import anyscale

anyscale.service_account.rotate_api_keys(
    name="my-service-account",
)
```
:::

::::

### `anyscale.service_account.list`

List service accounts.

**Arguments**

-   **`max_items` (int) = 20**: Maximum number of items to return.

**Returns**: List\[[ServiceAccount](#serviceaccount)\]

#### Examples

::::tabs

:::tab[Python]
```python
import anyscale

anyscale.service_account.list(
    max_items=20,
)
```
:::

::::

### `anyscale.service_account.delete`

Delete a service account.

**Arguments**

-   **`email` (str | None) = None**: Email of the service account to delete.
-   **`name` (str | None) = None**: Name of the service account to delete.

#### Examples

::::tabs

:::tab[Python]
```python
import anyscale

anyscale.service_account.delete(
    name="my-service-account",
)
```
:::

::::

## Service account models

### `ServiceAccount`

Service account

#### Fields

-   **`name` (str)**: Name of the service account.
-   **`created_at` (datetime)**: The timestamp when this service account was created.
-   **`permission_level` ([OrganizationPermissionLevel](#organizationpermissionlevel))**: The organization permission level of the service account.
-   **`email` (str)**: Email of the service account.

#### Python Methods

```python
def to_dict(self) -> Dict[str, Any]
    """Return a dictionary representation of the model."""
```

#### Examples

::::tabs

:::tab[Python]
```python
import anyscale
from anyscale.service_account.models import ServiceAccount

service_accounts: List[ServiceAccount] = anyscale.service_account.list()
```
:::

::::

### `OrganizationPermissionLevel`

Permission levels for service accounts in an organization.

#### Values

-   **`OWNER`**: Owner permission level for the organization
-   **`COLLABORATOR`**: Collaborator permission level for the organization

---

Previous: [Schedule](/reference/sdk/schedule.md) | Next: [Service](/reference/sdk/service.md)