# API Keys

## List Api Keys

`ApiKeyListPage apiKeys().list(ApiKeyListParamsparams = ApiKeyListParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**get** `/api/v1/beta/api-keys`

List API keys.

Name a `project_id` to list every key on that project, which its members
share; naming one you cannot read is a 404. Omit it to list your own. A
project-scoped key sees only its own project either way.

### Parameters

- `ApiKeyListParams params`

  - `Optional<List<String>> expand`

  - `Optional<KeyType> keyType`

    - `AGENT("agent")`

    - `USER("user")`

  - `Optional<String> name`

  - `Optional<Long> pageSize`

  - `Optional<String> pageToken`

  - `Optional<String> projectId`

### Returns

- `class ApiKey:`

  Schema for an API Key.

  - `String id`

    Unique identifier

  - `String redactedApiKey`

    The key with its middle masked, except on the create response, which returns the full secret once and never again.

  - `String userId`

  - `Optional<LocalDateTime> createdAt`

    Creation datetime

  - `Optional<LocalDateTime> expiresAt`

    When the API key expires. Null if the key never expires.

  - `Optional<KeyType> keyType`

    - `AGENT("agent")`

    - `USER("user")`

  - `Optional<Metadata> metadata`

  - `Optional<String> name`

  - `Optional<String> projectId`

  - `Optional<Role> role`

    Role capping what this key may do. Null if the key authorizes as its owner.

    - `ADMIN("admin")`

    - `AGENT_VIEWER("agent_viewer")`

    - `VIEWER("viewer")`

    - `VIEWER_V2("viewer_v2")`

  - `Optional<LocalDateTime> updatedAt`

    Update datetime

### Example

```java
package ai.llamaindex.llamacloudadmin.example;

import ai.llamaindex.llamacloudadmin.client.LlamaCloudAdminClient;
import ai.llamaindex.llamacloudadmin.client.okhttp.LlamaCloudAdminOkHttpClient;
import ai.llamaindex.llamacloudadmin.models.apikeys.ApiKeyListPage;
import ai.llamaindex.llamacloudadmin.models.apikeys.ApiKeyListParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudAdminClient client = LlamaCloudAdminOkHttpClient.fromEnv();

        ApiKeyListPage page = client.apiKeys().list();
    }
}
```

#### Response

```json
{
  "items": [
    {
      "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
      "redacted_api_key": "redacted_api_key",
      "user_id": "user_id",
      "created_at": "2019-12-27T18:11:19.117Z",
      "expires_at": "2019-12-27T18:11:19.117Z",
      "key_type": "agent",
      "metadata": {
        "foo": "bar"
      },
      "name": "name",
      "project_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
      "role": "admin",
      "updated_at": "2019-12-27T18:11:19.117Z"
    }
  ],
  "next_page_token": "next_page_token",
  "total_size": 0
}
```

## Create Api Key

`ApiKey apiKeys().create(ApiKeyCreateParamsparams = ApiKeyCreateParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**post** `/api/v1/beta/api-keys`

Create an API key.

Scope it to a project with `project_id`, which requires read access to that
project; omit it for a key that reaches every project you can read. A
project-scoped or agent key cannot create an API key. The response carries
the secret in `redacted_api_key`, and only this once.

### Parameters

- `ApiKeyCreateParams params`

  - `Optional<LocalDateTime> expiresAt`

    When the API key should expire. If not set, the key never expires.

  - `Optional<KeyType> keyType`

    - `AGENT("agent")`

    - `USER("user")`

  - `Optional<String> name`

  - `Optional<String> projectId`

    The project ID to associate with the API key.

  - `Optional<Role> role`

    Role capping what this key may do. A key can only ever be narrower than the user who created it, never broader. If not set, the key authorizes as its owner.

    - `ADMIN("admin")`

    - `AGENT_VIEWER("agent_viewer")`

    - `VIEWER("viewer")`

    - `VIEWER_V2("viewer_v2")`

### Returns

- `class ApiKey:`

  Schema for an API Key.

  - `String id`

    Unique identifier

  - `String redactedApiKey`

    The key with its middle masked, except on the create response, which returns the full secret once and never again.

  - `String userId`

  - `Optional<LocalDateTime> createdAt`

    Creation datetime

  - `Optional<LocalDateTime> expiresAt`

    When the API key expires. Null if the key never expires.

  - `Optional<KeyType> keyType`

    - `AGENT("agent")`

    - `USER("user")`

  - `Optional<Metadata> metadata`

  - `Optional<String> name`

  - `Optional<String> projectId`

  - `Optional<Role> role`

    Role capping what this key may do. Null if the key authorizes as its owner.

    - `ADMIN("admin")`

    - `AGENT_VIEWER("agent_viewer")`

    - `VIEWER("viewer")`

    - `VIEWER_V2("viewer_v2")`

  - `Optional<LocalDateTime> updatedAt`

    Update datetime

### Example

```java
package ai.llamaindex.llamacloudadmin.example;

import ai.llamaindex.llamacloudadmin.client.LlamaCloudAdminClient;
import ai.llamaindex.llamacloudadmin.client.okhttp.LlamaCloudAdminOkHttpClient;
import ai.llamaindex.llamacloudadmin.models.apikeys.ApiKey;
import ai.llamaindex.llamacloudadmin.models.apikeys.ApiKeyCreateParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudAdminClient client = LlamaCloudAdminOkHttpClient.fromEnv();

        ApiKey apiKey = client.apiKeys().create();
    }
}
```

#### Response

```json
{
  "id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  "redacted_api_key": "redacted_api_key",
  "user_id": "user_id",
  "created_at": "2019-12-27T18:11:19.117Z",
  "expires_at": "2019-12-27T18:11:19.117Z",
  "key_type": "agent",
  "metadata": {
    "foo": "bar"
  },
  "name": "name",
  "project_id": "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  "role": "admin",
  "updated_at": "2019-12-27T18:11:19.117Z"
}
```

## Delete Api Key

`ApiKeyDeleteResponse apiKeys().delete(ApiKeyDeleteParamsparams = ApiKeyDeleteParams.none(), RequestOptionsrequestOptions = RequestOptions.none())`

**delete** `/api/v1/beta/api-keys/{api_key_id}`

Revoke an API key.

Revoking a project key takes access away from everyone using it, so it needs
key-management permission on that project. Your own unscoped keys need only
that you own them. A project-scoped key revokes only within its own project,
unscoped keys included.

### Parameters

- `ApiKeyDeleteParams params`

  - `Optional<String> apiKeyId`

### Returns

- `class ApiKeyDeleteResponse:`

  Confirmation that a resource was deleted.

  - `long cacheTtlSeconds`

    Maximum seconds until cached information expires

  - `boolean success`

    Whether the resource was deleted

### Example

```java
package ai.llamaindex.llamacloudadmin.example;

import ai.llamaindex.llamacloudadmin.client.LlamaCloudAdminClient;
import ai.llamaindex.llamacloudadmin.client.okhttp.LlamaCloudAdminOkHttpClient;
import ai.llamaindex.llamacloudadmin.models.apikeys.ApiKeyDeleteParams;
import ai.llamaindex.llamacloudadmin.models.apikeys.ApiKeyDeleteResponse;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        LlamaCloudAdminClient client = LlamaCloudAdminOkHttpClient.fromEnv();

        ApiKeyDeleteResponse apiKey = client.apiKeys().delete("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e");
    }
}
```

#### Response

```json
{
  "cache_ttl_seconds": 0,
  "success": true
}
```

## Domain Types

### API Key

- `class ApiKey:`

  Schema for an API Key.

  - `String id`

    Unique identifier

  - `String redactedApiKey`

    The key with its middle masked, except on the create response, which returns the full secret once and never again.

  - `String userId`

  - `Optional<LocalDateTime> createdAt`

    Creation datetime

  - `Optional<LocalDateTime> expiresAt`

    When the API key expires. Null if the key never expires.

  - `Optional<KeyType> keyType`

    - `AGENT("agent")`

    - `USER("user")`

  - `Optional<Metadata> metadata`

  - `Optional<String> name`

  - `Optional<String> projectId`

  - `Optional<Role> role`

    Role capping what this key may do. Null if the key authorizes as its owner.

    - `ADMIN("admin")`

    - `AGENT_VIEWER("agent_viewer")`

    - `VIEWER("viewer")`

    - `VIEWER_V2("viewer_v2")`

  - `Optional<LocalDateTime> updatedAt`

    Update datetime
