Resources

API Keys

API keys let your own code reach the LevelFour API. Every key has a name, and it can carry a scope and an expiration date. Key scopes has what each scope reaches, and Key formats has the production and test prefixes.

Managing keys needs a signed-in dashboard session, not an API key. Authentication has the rule.

Create a key

Creates a new API key.

from datetime import datetime

key = client.api_keys.create(
    name="CI Pipeline",
    scope="read",
    expires_at=datetime(2025, 12, 31, 23, 59, 59),
)
Store the returned key value immediately. It will not be shown again.

Parameters

ParameterTypeDescription
namestringDisplay name for the key
scopestring?read or read-write
expires_atdatetime?Optional expiration timestamp

List keys

Returns all API keys for your organization.

keys = client.api_keys.list()

Rotate a key

Generates a new secret for an existing key ID.

The old secret is invalidated immediately, so anything still sending it stops working.
rotated = client.api_keys.rotate("key_123")

Revoke a key

Permanently invalidates a key. This cannot be undone.

client.api_keys.revoke("key_123")

Rotate every key

This lists every key, rotates each one, and prints what comes back.

from levelfour import LevelFour

client = LevelFour()

keys = client.api_keys.list()
for key in keys.data:
    rotated = client.api_keys.rotate(key.id)
    print(f"Rotated {key.name}: {rotated}")

Next

  • Authentication has the key formats, what each scope reaches, and where the SDKs look for a key
  • API reference is generated from the schema: every parameter, response field and status code
  • CLI authentication is how l4 resolves a credential and where it stores one