Skip to main content
Python
from openlayer import Openlayer

client = Openlayer()
api_key = client.workspaces.api_keys.create(
  workspace_id="182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  name="My API Key"
)
import Openlayer from 'openlayer';

const openlayer = new Openlayer();
apiKey = await openlayer.workspaces.apiKeys.create(
  {workspace_id: "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", name: "My API Key"}
)
package main

import (
  "context"

  "github.com/openlayer-ai/openlayer-go"
  "github.com/openlayer-ai/openlayer-go/option"
)

client := openlayer.NewClient()
apiKey, err := client.Workspaces.APIKeys.New(
  context.TODO(),
  "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
  openlayer.WorkspaceAPIKeyNewParams{
    Name: openlayer.F("My API Key"),
  },
)
import com.openlayer.api.client.OpenlayerClient;
import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;
import com.openlayer.api.models.WorkspaceAPIKeyNewParams;
import com.openlayer.api.models.WorkspaceAPIKeyNewResponse;

OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();

WorkspaceAPIKeyNewParams params = WorkspaceAPIKeyNewParams.builder().build();
WorkspaceAPIKeyNewResponse response = client.workspaces().apiKeys().new(params);
curl --request POST \
  --url https://api.openlayer.com/v1/workspaces/182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e/api-keys \
  --header 'Authorization: Bearer <token>' \
  --data '{
    "name": "My API Key"
  }'
{
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "dateCreated": "2023-11-07T05:31:56Z",
  "dateUpdated": "2023-11-07T05:31:56Z",
  "dateLastUsed": "2023-11-07T05:31:56Z",
  "secureKey": "sk-ol-*************************5PW0",
  "name": "Secret Key"
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your workspace API key. See Find your API key for more information.

Path Parameters

workspaceId
string<uuid>
required

The workspace id.

Body

application/json
name
any

Response

201 - application/json

Status Created.

id
string<uuid>
required
read-only

The API key id.

dateCreated
string<date-time>
required
read-only

The API key creation date.

dateUpdated
string<date-time>
required
read-only

The API key last update date.

dateLastUsed
string<date-time> | null
required
read-only

The API key last use date.

secureKey
string
required
read-only

The API key value.

Maximum string length: 120
Example:

"sk-ol-*************************5PW0"

name
string | null

The API key name.

Maximum string length: 120
Example:

"Secret Key"