Programmatic API Tokens
The LISA Serve ALB can be used for programmatic access outside the example Chat application. An example use case would be for allowing LISA to serve LLM requests that originate from the Continue VSCode Plugin. To facilitate communication directly with the LISA Serve ALB, a user with sufficient DynamoDB PutItem permissions may add API keys to the APITokenTable, and once created, a user may make requests by including the Authorization: Bearer ${token}
header or the Api-Key: ${token}
header with that token. If using any OpenAI-compatible library, the api_key
fields will use the Authorization: Bearer ${token}
format automatically, so there is no need to include additional headers when using those libraries.
Adding a Token
An account owner may create a long-lived API Token using the following AWS CLI command.
AWS_REGION="us-east-1" # change to your deployment region
token_string="YOUR_STRING_HERE" # change to a unique string for a user
aws --region $AWS_REGION dynamodb put-item --table-name $DEPLOYMENT_NAME-LISAApiTokenTable \
--item '{"token": {"S": "'${token_string}'"}}'
If an account owner wants the API Token to be temporary and expire after a specific date, LISA will allow for this too. In addition to the token
field, the owner may specify the tokenExpiration
field, which accepts a UNIX timestamp, in seconds. The following command shows an example of how to do this.
AWS_REGION="us-east-1" # change to your deployment region
token_string="YOUR_STRING_HERE"
token_expiration=$(echo $(date +%s) + 3600 | bc) # token that expires in one hour, 3600 seconds
aws --region $AWS_REGION dynamodb put-item --table-name $DEPLOYMENT_NAME-LISAApiTokenTable \
--item '{
"token": {"S": "'${token_string}'"},
"tokenExpiration": {"N": "'${token_expiration}'"}
}'
Once the token is inserted into the DynamoDB Table, a user may use the token in the Authorization
request header like in the following snippet.
lisa_serve_rest_url="https://<rest-url-from-cdk-output>"
token_string="YOUR_STRING_HERE"
curl ${lisa_serve_rest_url}/v2/serve/models \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer ${token_string}"
Updating a Token
In the case that an owner wishes to change an existing expiration time or add one to a key that did not previously have an expiration, this can be accomplished by editing the existing item. The following commands can be used as an example for updating an existing token. Setting the expiration time to a time in the past will effectively remove access for that key.
AWS_REGION="us-east-1" # change to your deployment region
token_string="YOUR_STRING_HERE"
token_expiration=$(echo $(date +%s) + 600 | bc) # token that expires in 10 minutes from now
aws --region $AWS_REGION dynamodb update-item --table-name $DEPLOYMENT_NAME-LISAApiTokenTable \
--key '{"token": {"S": "'${token_string}'"}}' \
--update-expression 'SET tokenExpiration=:t' \
--expression-attribute-values '{":t": {"N": "'${token_expiration}'"}}'
Removing a Token
Tokens will not be automatically removed even if they are no longer valid. An owner may remove an key, expired or not, from the database to fully revoke the key, by deleting the item. As an example, the following commands can be used to remove a token.
AWS_REGION="us-east-1" # change to your deployment region
token_string="YOUR_STRING_HERE" # change to the token to remove
aws --region $AWS_REGION dynamodb delete-item --table-name $DEPLOYMENT_NAME-LISAApiTokenTable \
--key '{"token": {"S": "'${token_string}'"}}'