Skip to Content

Creating an Access Key

This guide explains how to programmatically create or update users and retrieve their access keys using Liona’s API. This is ideal for automating user provisioning in your applications or backend systems.

Note

To use this API, you need an API key with administrative privileges. Learn how to generate an API key first.

Understanding Access Keys

Access keys allow your users to authenticate with AI providers through Liona. Unlike API keys, which have administrative privileges, access keys have limited access based on the policies you assign.

When creating users programmatically:

  1. You define user details like ID and policy
  2. The API returns an access key for the user
  3. You can distribute this access key to the user or store it in your system

API Endpoint

⚠️
Warning

This endpoint should only be called from your backend services. Never call this endpoint from client-side code or expose your API key in client applications.

FieldValue
URLhttps://liona.ai/v1/admin/make-access-key
MethodPOST
AuthenticationAPI Key (in Authorization header)

Request Parameters

ParameterTypeRequiredDescription
user_idstringYesA unique identifier for the user
policy_idstringYes (for new users)The ID of the policy to associate with this user
emailstringNoUser’s email address for identification (optional)
expire_secondsintegerNoAccess key expiration in seconds (defaults to 1 week if not specified or if a value greater than 1 week is provided)

Response Structure

The API returns a JSON object containing:

FieldTypeDescription
access_keystringThe access key for the user
expires_atstringISO 8601 timestamp when the access key expires

Examples

curl -X POST https://liona.ai/v1/admin/make-access-key \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_API_KEY" \ -d '{ "user_id": "user123", "email": "[email protected]", "policy_id": "pol_12345", "expire_seconds": 86400 }'

How It Works

This endpoint performs the following operations:

  1. If the user with the specified user_id doesn’t exist in the project:

    • Creates a new user with the provided details
    • Associates the user with your project
  2. If the user already exists:

    • Updates the user’s policy and/or email if provided in the request
  3. For the access key:

    • If the user has an existing valid API-generated access key, extends its expiration
    • Otherwise, generates a new access key
  4. Returns the access key and its expiration date

Error Handling

The API may return the following errors:

Status CodeDescription
400Bad Request - Missing required fields or validation error
401Unauthorized - Invalid or missing API key
500Internal Server Error - Various internal failures such as policy not found or access key generation failure

Limitations

  • Access key expiration is capped at 1 week (604,800 seconds) for security reasons
  • If you specify an expiration longer than 1 week, it will be automatically adjusted to 1 week
  • If you don’t specify an expiration, the access key will expire after 1 week by default

Next Steps

Now that you can programmatically create users and access keys, you might want to:

Last updated on