Skip to content
Product Docs

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.

ParametersExpand Collapse
ApiKeyCreateParams params
Optional<LocalDateTime> expiresAt

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

formatdate-time
Optional<KeyType> keyType
AGENT("agent")
USER("user")
Optional<String> name
Optional<String> projectId

The project ID to associate with the API key.

formatuuid
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")
ReturnsExpand Collapse
class ApiKey:

Schema for an API Key.

String id

Unique identifier

formatuuid
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

formatdate-time
Optional<LocalDateTime> expiresAt

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

formatdate-time
Optional<KeyType> keyType
One of the following:
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.

One of the following:
ADMIN("admin")
AGENT_VIEWER("agent_viewer")
VIEWER("viewer")
VIEWER_V2("viewer_v2")
Optional<LocalDateTime> updatedAt

Update datetime

formatdate-time

Create Api Key

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();
    }
}
{
  "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"
}
Returns Examples
{
  "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"
}