GuardRails API Usage Guide
Table of Contents
Pre-Requisites
To use the GuardRails API, you need to have a GuardRails account and obtained an API key. Note: For on-premise deployments, the GuardRails API is hosted on port 1444
, e.g. https://guardrails.your-company.com:1444/swagger
.
More information on how to get started can be found here.
Once you setup your GuardRails account you can generate your api key
in the user's setting page in the dashboard.
Exchange API Key for JWT
To access the GuardRails api, you must first get a valid GuardRails JWT. In the example below we are assuming that you are using bash and have curl and jq installed on your computer.
Start by adding your API key to a variable (this will be used in the subsequent command).
export API_KEY="" # The api key can be generated on the user account in the GuardRails dashboard.
Next, make a request (using curl
) to get a valid JWT from the api key.
JWT_TOKEN=$(curl \
--request POST \
--header "Content-Type: application/json" \
--data "{ \"apiKey\": \"$API_KEY\" }" \
https://api.guardrails.io/v2/auth | jq -r '.jwtToken')
echo $JWT_TOKEN
Note: The JWT will expire after 6 hours, after that you will have to make a new request to get a new JWT token.
How to use the API
Now that you have a valid JWT you can start calling the GuardRails API. Here's an example of fetching all accounts (user and organizations) associated with the api key.
curl \
--request GET \
--header "Authorization: bearer $JWT_TOKEN" \
"https://api.guardrails.io/v2/accounts"
Now you should see a list of all the accounts associated with the api key.
Click here to get a list of all available API endpoints.