Skip to main content
POST
/
api-keys
/
{type}
/
{sub-type}
from portkey_ai import Portkey

# Initialize the Portkey client
portkey = Portkey(
    api_key="PORTKEY_API_KEY",
)

# Create a new API key
api_key = portkey.api_keys.create(
    name="API_KEY_NAME_0909",
    type="organisation",
    sub_type="service",
    workspace_id="WORKSPACE_ID",
    scopes=[
        "logs.export",
        "logs.list",
        "logs.view",
        "configs.create",
        "configs.update",
        "configs.delete",
        "configs.read",
        "configs.list",
        "virtual_keys.create",
        "virtual_keys.update",
        "virtual_keys.delete",
        "virtual_keys.read",
        "virtual_keys.list",
        "virtual_keys.copy"
    ]
)

print(api_key)
{
  "id": "183f497a-2a7f-4f47-992e-26213fa863we",
  "key": "abssofjosfjs",
  "object": "api-key"
}

Documentation Index

Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt

Use this file to discover all available pages before exploring further.

Authorizations

x-portkey-api-key
string
header
required

Path Parameters

type
enum<string>
required
Available options:
organisation,
workspace
sub-type
enum<string>
required
Available options:
user,
service

Body

application/json
name
string
required
Example:

"Development API Key"

scopes
string[]
required
Example:
["completions.write"]
description
string
Example:

"API key for development environment"

organisation_id
string<uuid>

Organisation ID. Optional when calling via an org-level API key (picked from auth context).

Example:

"a1b2c3d4-e5f6-7890-abcd-ef1234567890"

workspace_id
string
Example:

"ws-myworkspace"

user_id
string<uuid>

Required when sub-type path parameter is 'user'. Not required when sub-type is 'service'.

Example:

"c3d4e5f6-a7b8-6c7d-0e1f-2a3b4c5d6e7f"

rate_limits
object[] | null
usage_limits
object
Example:
{
"credit_limit": 10,
"periodic_reset": "monthly",
"alert_threshold": 8
}
defaults
object
alert_emails
string<email>[]
expires_at
string<date-time> | null

ISO 8601 datetime at which this key expires. Must not exceed the org/workspace maximum TTL if configured.

Example:

"2026-12-31T23:59:59Z"

rotation_policy
object

Automatic key rotation configuration. Requires either rotation_period or next_rotation_at.

Response

200 - application/json

OK

id
string<uuid>
Example:

"183f497a-2a7f-4f47-992e-26213fa863we"

key
string
Example:

"abssofjosfjs"

object
enum<string>
Available options:
api-key
Example:

"api-key"

Last modified on January 28, 2026