Skip to content

API Keys

The API keys resource manages authentication tokens for programmatic access.

Methods

Method Description
create(name, scopes, expires_at) Create a new API key
list(limit, offset) List all API keys
get(jti) Get API key details by JTI
revoke(jti) Revoke an API key

Creating an API key

    client.api_keys.create(
        name='My API Key',
        scopes=['viewer', 'editor'],
    )

Save the token!

The token is generated only once and you cannot recover it. Keep it safe.

Using an API key

API keys are regular JWT token. They are save to ineepy.toml (unless save_token=False) or you can pass them to the constructor.

    token = client.api_keys.create(
        name='My API Key',
        scopes=['viewer', 'editor'],
        save_token=False,
    )

with Ineepy(token=token) as api_key_client:

Listing API keys

You can list your API keys.

    api_keys = api_key_client.api_keys.list().items
    print(f'API Keys: {[k.name for k in api_keys]}')

Revoking an API key

    key = client.api_keys.list().items[0].jti
    client.api_keys.revoke(key)

Once revoked, the API key can no longer be used for authentication.

Warning

Create a unique API key for each application and revoke unused keys to minimize your attack surface. Set expires_at to automatically revoke the key on a specific date.