ApiKeys

The endpoints managing ApiKeys resources are located under the /apikeys path.

ApiKey Object

The ApiKey object is describing an api key authentication token that you can use to access the restrcited API.

    Properties

    An ApiKey has a role which determine which are the actions that can be performed using the key. Also, it may have an expiration date, after which it will be automatically deleted.

  • Name
    id
    Type
    string
    Description

    The ApiKey ID.

  • Name
    name
    Type
    string
    Description

    The ApiKey name.

  • Name
    type
    Type
    ApiKeyTypes
    Description

    The ApiKey type. Can be one of 'sk' or 'pk'.

    • sk - Secret Key. Must never be used from a public client like a browser page.
    • pk - Public Key. Can be used to access the API from anywere (e.g. a browser page). This type of key can only read public data and execute interactions.

    It is recommended to use key rotations to keep the keys secure. Public keys can be requested using a secret key on the server making the key rotation easy to implement.

  • Name
    role
    Type
    ProjectRoles
    Description

    the role an API key may have. Can be one of:

    • reader - read only access to projects.
    • executor - read only access and can execute interactions. This is the role used by a Public Key.
    • application - like executor and in addition can request public keys too.
    • developer - full access to objects inside projects but cannot delete objects.
    • admin - can perform any action on the project.
  • Name
    maskedValue
    Type
    string
    Description

    The masked value of the key. The value is masked to avoid exposing the key in the logs.

  • Name
    account
    Type
    string
    Description

    The ID of the account (i.e. organization) containing the API key.

  • Name
    project
    Type
    string
    Description

    An optional project ID if the key is only valid for a specific project.

  • Name
    enabled
    Type
    boolean
    Description

    Whether or not the key is enabled.

  • Name
    expires_at
    Type
    string
    Description

    An option expiry date. The date is in ISO 8601 format.
    If specified the key will be automatically deleted after the date.

  • Name
    created_at
    Type
    string
    Description

    The creation date. The date is in ISO 8601 format.

  • Name
    updated_at
    Type
    string
    Description

    The creation date. The date is in ISO 8601 format.

ApiKey
{
  "account": "652d77895674c387e105948c",
  "name": "Key Created On 2023-10-24 16:31:28",
  "type": "sk",
  "role": "developer",
  "enabled": true,
  "created_at": "2023-10-24T07:31:33.363Z",
  "updated_at": "2023-10-24T07:31:33.363Z",
  "id": "653772d5d73c5ac92045df97",
  "maskedValue": "sk-ec54686****"
}

List API Keys
GET /apikeys

Get the list of the API keys defined in the current organization. \

Parameters

No parameters.

Returns

A list of APIKey objects.

Request

curl https://api.composableprompts.com/api/v1/apikeys \
  -H "Accept: application/json"
  -H "Authorization: Bearer {token}"

Response

[
  {
    account: "652d77895674c387e105948c",
    name: "Public API Key (generated)",
    type: "pk",
    role: "executor",
    expires_at: "2023-12-06T18:27:03.707Z",
    enabled: false,
    created_at: "2023-12-06T17:27:03.724Z",
    updated_at: "2023-12-07T08:56:32.986Z",
    id: "6570aee711df2c266121108a",
    maskedValue: "pk-6e65296****"
  },
  ...
]

Request Public Key
GET /pk

Request a public key. If a valid public key is found it will be returned optherwise a new one is created with a default time to live of 24h.
The API key used to request the public key must have the at least the application role.

Parameters

name?: string, projectId?: string, ttl?: number,

  • Name
    projectId
    Type
    string
    Modifier
    optional
    Description

    Project for which this key is enabled. If specified the returned API key will only work to access this project, if not default project will be set.

  • Name
    name
    Type
    string
    Modifier
    optional
    Description

    An optional API key name. If not provided a name will be generated.

  • Name
    ttl
    Type
    number
    Modifier
    optional
    Description

    A custom ttl in seconds. If not provided the default ttl is 24h.

Returns

Returns a JSON object with 2 properties: expire_at and value. The value is the token to be used when authenticating using the key.

Request

curl "https://api.composableprompts.com/api/v1/apikeys/pk?name=test-key&ttl=3600" \
  -H "Accept: application/json"
  -H "Authorization: Bearer {token}"

Response

{
  "expire_at": "2023-10-24T08:31:28.000Z",
  "value": "pk-ec54686****"
}

Was this page helpful?